Hello everyone,
I'm trying to send hex values to a socket. I am working on an app that will control wireless RGB lightbulbs. They come with a wifi bridge that takes commands on a UDP socket.
There are more details of the API on the LimitlessLED Dev website, but I'm not allowed to post links.
All commands are three bytes. For example I need to send a TCP/IP UDP packet of: 0x42 0x00 0x55 to turn all the lights on.
I know i need to open a socket connection or do a write to socket, but how do I get Livecode to send a hex value like 0x42? Does it involve numtobyte? If someone can point me in the right direction for getting live code to send those commands, I would appreciate it.
Sending hex values to socket.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Sending hex values to socket.
Hi Jeffrey,
Are you sure that you should send hex values? Probably, you have to send binary data and the documentation gives the hex values for the binary data. Probably, you can use numToByte (or numToChar).
Kind regards,
Mark
Are you sure that you should send hex values? Probably, you have to send binary data and the documentation gives the hex values for the binary data. Probably, you can use numToByte (or numToChar).
Code: Select all
put numToChar(0x42) & NULL & numToChar(0x55) into myData
write myData to socket mySocket
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Sending hex values to socket.
Hi, Jeffrey. If the docs are showing the data in hex, you can...
Good for reference when you look back over your code as it matches the docs.
To send the 'lights on' string, you could use a little re-usable function ...
Code: Select all
write numToByte(0x42) to socket tSocket
To send the 'lights on' string, you could use a little re-usable function ...
Code: Select all
function binData
local tIndex, tData
repeat with tIndex = 1 to paramCount()
put numToByte(param(tIndex)) after tData
end repeat
return tData
end binData
# turn the lights on
write binData(0x42, 0x00, 0x55) to socket tSocket
LiveCode Development & Training : http://splash21.com
Re: Sending hex values to socket.
Thank you so much for the help Mark and Splash21! I regret I can't test it yet it because the hardware is still on the way, but it won't stop me from tinkering around with creating a program in the mean time.
I couldn't quite figure out whether it was num2byte, byte2num or binary convert, and exactly how it was implemented no matter how I studied the doc entries. I believe this will put me on the right path.
I couldn't quite figure out whether it was num2byte, byte2num or binary convert, and exactly how it was implemented no matter how I studied the doc entries. I believe this will put me on the right path.