Skip to content

Instantly share code, notes, and snippets.

@jpawlowski
Last active September 25, 2022 20:17
Show Gist options
  • Save jpawlowski/5359556 to your computer and use it in GitHub Desktop.
Save jpawlowski/5359556 to your computer and use it in GitHub Desktop.
LED Wifi control script for MiLight, EasyBulb, iBulb, LinkUP, Kepsun
#!/usr/bin/perl -w
#
# LED Wifi control script for MiLight, EasyBulb, iBulb, LinkUP, Kepsun
# ====================================================================
#
#
# Copyright (C) 2013, Julian Pawlowski <julian.pawlowski@gmail.com>
# All rights reserved.
#
# License: Simplified BSD / FreeBSD License
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are those
# of the authors and should not be interpreted as representing official policies,
# either expressed or implied, of the FreeBSD Project.
#
#
#
# --------------
# [1st Screen in iOS app Wifi Controller v1]
# RGB Strip Controller codes:
#
# 10 xx 55 - color selection (xx = value between 0 and 255, converted to hex)
# 11 00 55 - turn down (brightness/speed)
# 12 00 55 - light changing mode
# 13 00 55 - turn up (brightness/speed)
# 14 00 55 - turn on/off
# 15 00 55 - color light/white light switching mode
#
# --------------
# [2nd Screen in iOS app Wifi Controller v1]
# Wireless Dimmer Controller codes:
# 10 xx 55 - brightness selection (xx = value between 0 and 255, converted to hex)
# 11 00 55 - lowest brightness
# 12 00 55 - turn on
# 13 00 55 - highest brightness
# 14 00 55 - medium brightness
# 15 00 55 - turn off
#
# --------------
# [3rd Screen in iOS app Wifi Controller v1]
# Color Temperature Adjustable Dimmer Controller codes:
#
# 10 xx 55 - 1 part brightness, 1 part temperature selection (xx = value between 0 and 255, converted to hex)
# 11 00 55 - lowest brightness
# 12 00 55 - turn on
# 13 00 55 - highest brightness
# 14 00 55 - medium brightness
# 15 00 55 - turn off
#
# --------------
# [4th Screen in iOS app Wifi Controller v1]
# RGB+W Strip/bulb Controller codes:
#
# 20 xx 55 - color selection (xx = value between 0 and 255, converted to hex)
# 21 00 55 - turn off
# 22 00 55 - turn on
# 23 00 55 - brightness up
# 24 00 55 - brightness down
# 25 00 55 - speed up
# 26 00 55 - speed down
# 27 00 55 - mode up
# 28 00 55 - mode down
#
# --------------
# [5th Screen in iOS app Wifi Controller v1]
# MiLight Bulb Controller codes:
#
# 39 00 55 - turn off
# 35 00 55 - turn on
# 3c 00 55 - turn brightness up
# 34 00 55 - turn brightness down
# 3e 00 55 - light warmer
# 3f 00 55 - light whiter
# 38 00 55 - turn Zone 1 on
# 3b 00 55 - turn Zone 1 off
# 3d 00 55 - turn Zone 2 on
# 33 00 55 - turn Zone 2 off
# 37 00 55 - turn Zone 3 on
# 3a 00 55 - turn Zone 3 off
# 32 00 55 - turn Zone 4 on
# 36 00 55 - turn Zone 4 off
#
# --------------
# 4 Zone LED Controller (thnx to Detlef Fossan to provide these data)
#
# 40 xx - color selection (xx = value between 00 and FF, 00 = blue, FF = purple)
# 41 00 - turn master off
# 42 00 - turn master on
# 43 00 - speed down
# 44 00 - speed up
# 45 00 - turn Zone 1 on
# 46 00 - turn Zone 1 off
# 47 00 - turn Zone 2 on
# 48 00 - turn Zone 2 off
# 49 00 - turn Zone 3 on
# 4a 00 - turn Zone 3 off
# 4b 00 - turn Zone 4 on
# 4c 00 - turn Zone 4 off
# 4d 00 - light changing mode
# 4e xx - brightness selection (xx = value between 00 and 1F)
if (@ARGV < 2) {
print STDERR "Usage: $0 IP-ADDRESS COMMAND-CODE\n";
exit 1;
}
use strict;
use IO::Socket::INET;
my $sock = new IO::Socket::INET(PeerAddr => $ARGV[0],
PeerPort => 50000,
Proto => 'udp', Timeout => 1) or die('Error opening socket.');
my $code = $ARGV[1];
my $packed = join "",map {chr(hex $_)} split(' ',$code);
print $sock $packed;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment