As the title says... Chat on...

User avatar
By JuanG
#37830 Hello forum,

I´m sorry but my LUA knowledge is very limited. I want to send a sequence of bytes from an ESP8266-12 board, to a PLC (Programmable Logic Controller), using UDP protocol.

The simple code I have writte is the following, but I cannot receive the UDP bytes on my PLC (however, if I send them using a UDP tool on my PC, I can receive them correctly). Perhaps I have a syntax mistake ??
Is the "send" line correctly written to send an array of bytes ??

function SendDatosUDP()
cudp=net.createConnection(net.UDP, 0)
cudp:connect(4950,"192.168.1.81")
cudp:send(0x00,0x00,0x00,0x00,0x02,0xFA,0x03,0x00,0x06,0x02,0x11,0x12)
end

Thank you for any help !
JJ
User avatar
By TerryE
#37842 You can't issue the send until you have connected. You would use a
Code: Select allcups:on('connected', function(sock) . . . end)
to do this. Also why don't you use crypto:toBase64 to convert your binary to ASCII as this will be easier to debug.
User avatar
By JuanG
#38000 Thank you. I have found the solution: I needed to use string.char, like in:
cudp:send(string.char(byte, byte, byte))
With this, it is now working.

However thanks to your suggestion, I will also add a "connection" check.

JJ

TerryE wrote:You can't issue the send until you have connected. You would use a
Code: Select allcups:on('connected', function(sock) . . . end)
to do this. Also why don't you use crypto:toBase64 to convert your binary to ASCII as this will be easier to debug.