Hi, I am working on integration with Milight.
I have to send UPD commands to manage the system.
Could you give me some details or example about the way to send UDP commands?
Thanks.
Thank you Admin,
just a quick information. As you can see in the link (http://www.limitlessled.com/dev/) I have to send a datagram made of like below
UDP.SEND hex bytes: 20 00 00 00 16 02 62 3A D5 ED A3 01 AE 08 2D 46 61 41 A7 F6 DC AF (D3 E6) 00 00 1E <-- Send this to the ip address of the wifi bridge v6
In your opinion the following command can work? Because unfortunately it does not work:
local socket = require('socket')
local udp = socket.udp()
udpettimeout(200)
udpendto('31x00x00x08x04x02x00x00x00','192.168.1.32','5987')
data = udp:receive()
function cmd (mioff)
-- edit ip address and port
ip = '192.168.1.32'
port = 5987
local sock = require('socket').udp()
if sock then
sockendto(cmd, ip, port)
sockettimeout(200)
data = sock:receive()
sock:close()
end
return data
end
log(data)
functioncmd (mioff)
ip = '192.168.1.255'port = 48899localsock = require('socket').udp()
ifsockthensock:sendto(mioff, ip, port)
sock:settimeout(200)
data = sock:receive()
sock:close()
endreturndataend
Hi there, I am going on to embadded Milight on HL unfortunately without success. User library above is not changed but HL error log tells me that on line 3:loop or previous error loading 'user.milight'.
Furthermore I tried to snif using wireshark and it seems that there is not any telegram sent by UDP to ny device. Event based script is the one shown below:
Can you try to put the function 'cmd' direct in your script (on top) without the require of a user lib?
Make sure there is no function called 'cmd' in your common functions to avoid a duplicate function.
BR,
Erwin
mioff = string.char(0x80,0x00,0x00,0x00,0x11,0x00,0x31,0x00,0x00,0x08,0x04,0x02,0x00,0x00,0x00)
ip = '192.168.1.255'port = 48899localsock = require('socket').udp()
ifsockthensock:sendto(mioff,ip,port)
sock:settimeout(200)
data = sock:receive()
sock:close()
endreturndata
Hi Erwin,
directly on event based I wrote this code but with Wireshark I cannot see any telegram leaving from HL to address 192.168.1.255.
What is wrong in your opinion?
Thanks.
I am sending the 0x4c,0x69,0x6e,0x6b,0x5f,0x57,0x69,0x2d,0x46,0x69. It is part of the same char which I read with Wireshark when I command light using android app of Milight.
I do not understand the reason why when I send commands by Milight Android app telegram lenght is 52 instead sending telegram (just string above) lenght is 60.
The problem is thay I should send further data but telegram will be longer. What is your thoughs?
Hi, I found on web this script to integrate Milight led. There are udp commends. Could you let me know if it is suitable for HL or some instruction should be modified?
Thanks.
local IP = 192.168.1.2
local Port = 5987
local ZoneID = string.char(0x01)
--List of Commands
local Init = string.char (0x20,0x00,0x00,0x00,0x16,0x02,0x62,0x3A,0xD5,0xED,0xA3,0x01,0xAE,0x08,0x2D,0x46,0x61,0x41,0xA7,0xF6,0xDC,0xAF,0xFE,0xF7,0x00,0x00,0x1E)
local Preample = string.char (0x80,0x00,0x00,0x00,0x11)
local Filler = string.char (0x00)
local On = string.char (0x31,0x00,0x00,0x08,0x04,0x01,0x00,0x00,0x00)
local Off = string.char(0x31,0x00,0x00,0x08,0x04,0x02,0x00,0x00,0x00)
--Generate random Sequential Byte just helps with keeping commands in the correct order, and it helps to ignore duplicate packets already received.
math.randomseed(os.time())
math.random(); math.random(); math.random()
local RandomNumber = math.random(255)
local SequentialByte = string.char(RandomNumber)
--Action
local Command = On
--Send Init and wait for response
local Response={}
socket = Net.FUdpSocket()
socket:setBroadcast(true)
bytes, ErrorCode = socket:write (Init, IP, Port)
if ErrorCode == 0 then
local ResponseLength = 1
while (ErrorCode==0 and ResponseLength>0 and ResponseLength~=22) do
Response, ErrorCode = socket:read()
ResponseLength = string.len(Response)
end
end
--Extract data from UDP response
local MAC = Response:sub(0x09,0x0E)
local WifiBridgeSessionID1 = Response:sub(0x14,0x14)
local WifiBridgeSessionID2 = Response:sub(0x15,0x15)
local Payload = Preample..WifiBridgeSessionID1..WifiBridgeSessionID2..Filler..SequentialByte..Filler..Command..ZoneID..Filler
local ChksumString = Payload:sub(0x0B)
--Calculate Checksum
local i = 1
local Chksum = 0
while i <= ChksumString:len() do
Number = ChksumString:sub(i,i)
Chksum = Chksum + tonumber(Number:tohex(),16)
i = i + 1
end
--Calculate remainder Chksum%256 same as &0xFF
Chksum = (Chksum - math.floor(Chksum/256)*256)
local Chksumchar = string.char(Chksum)
Payload = Payload..Chksumchar
Response={}
bytes, ErrorCode = socket:write (Payload, IP, Port)
if ErrorCode == 0 then
local ResponseLength = 1
while (ErrorCode==0 and ResponseLength>0 and ResponseLength~=8) do
Response, ErrorCode = socket:read()
ResponseLength = string.len(Response)
end
end
socket = nil
--Extract data from UDP response
local Result = ""
local ResultByte = Response:sub(0x08,0x08)
local ResponseSequentialByte = Response:sub(0x07,0x07)
if (ResponseSequentialByte==SequentialByte and ResultByte==Filler) then
Result = "Successfull"
else
Result = "Failed"
end
require('socket') -- added socket liblocalIP = '192.168.1.2'-- added set ip into ''localPort = 5987localZoneID = string.char(0x01)
--List of CommandslocalInit = string.char (0x20,0x00,0x00,0x00,0x16,0x02,0x62,0x3A,0xD5,0xED,0xA3,0x01,0xAE,0x08,0x2D,0x46,0x61,0x41,0xA7,0xF6,0xDC,0xAF,0xFE,0xF7,0x00,0x00,0x1E)
localPreample = string.char (0x80,0x00,0x00,0x00,0x11)
localFiller = string.char (0x00)
localOn = string.char (0x31,0x00,0x00,0x08,0x04,0x01,0x00,0x00,0x00)
localOff = string.char(0x31,0x00,0x00,0x08,0x04,0x02,0x00,0x00,0x00)
--Generate random Sequential Byte just helps with keeping commands in the correct order, and it helps to ignore duplicate packets already received.math.randomseed(os.time())
math.random(); math.random(); math.random()
localRandomNumber = math.random(255)
localSequentialByte = string.char(RandomNumber)
--ActionlocalCommand = On--Send Init and wait for responselocalResponse={}
localclient = socket.udp() -- added socket clientclientConfusedetBroadcast(true) -- missing function don't know what it should dobytes, ErrorCode = client:write (Init, IP, Port) -- changed socket requestifErrorCode == 0thenlocalResponseLength = 1while (ErrorCode==0andResponseLength>0andResponseLength~=22) doResponse, ErrorCode = client:read() -- changed socket requestResponseLength = string.len(Response)
endend--Extract data from UDP responselocalMAC = ResponseConfusedub(0x09,0x0E) -- missing function don't know what it should dolocalWifiBridgeSessionID1 = ResponseConfusedub(0x14,0x14) -- missing function don't know what it should dolocalWifiBridgeSessionID2 = ResponseConfusedub(0x15,0x15) -- missing function don't know what it should dolocalPayload = Preample..WifiBridgeSessionID1..WifiBridgeSessionID2..Filler..SequentialByte..Filler..Command..ZoneID..Filler--missing ID1 & ID2 result due to missing functionslocalChksumString = PayloadConfusedub(0x0B) -- missing function don't know what it should do--Calculate Checksumlocali = 1localChksum = 0whilei <= ChksumString:len() doNumber = ChksumStringConfusedub(i,i)
Chksum = Chksum + tonumber(Number:tohex(),16) -- i think this must be lmcore.intohex()i = i + 1end--Calculate remainder Chksum%256 same as &0xFFChksum = (Chksum - math.floor(Chksum/256)*256)
localChksumchar = string.char(Chksum)
Payload = Payload..ChksumcharResponse={}
bytes, ErrorCode = client:write (Payload, IP, Port) -- changed socket requestifErrorCode == 0thenlocalResponseLength = 1while (ErrorCode==0andResponseLength>0andResponseLength~=8) doResponse, ErrorCode = client:read() -- changed socket requestResponseLength = string.len(Response)
endendclient = nil--Extract data from UDP responselocalResult = ""localResultByte = ResponseConfusedub(0x08,0x08) -- missing function don't know what it should dolocalResponseSequentialByte = ResponseConfusedub(0x07,0x07) -- missing function don't know what it should doif (ResponseSequentialByte==SequentialByteandResultByte==Filler) then-- missing Byte due to missing functionResult = "Successfull"elseResult = "Failed"end
You probably will get a reply as 'Response' but the extraction of the reply data would need to be rebuild without the additional functions ..