I’m attempting to write a discovery for my edge driver.
The device requires a message (‘DISCOVER\r\n’) to be braodcast over UDP on port 3310. The device will then reply by broadcasting a message containing its IP address.
My code below successfully send the discovery message. I can see it in Wireshark. Likewise, the device broadcasts a message response which contains its IP address. I can see that in wireshark too. But for some reason the hub never receives the response from the device.
Here’s the code.
local function find_device()
-- UDP socket initialization
local udp = socket.udp()
udp:setsockname('*', 0)
udp:setoption('broadcast', true)
udp:settimeout(2)
-- broadcasting request
log.info('===== SCANNING NETWORK...')
udp:sendto('DISCOVER\r\n', '255.255.255.255', 3310)
-- Socket will wait 2 seconds to receive a response back.
local res = udp:receive()
-- close udp socket
udp:close()
if res ~= nil then
return res
end
return nil
end
local disco = {}
function disco.start(driver, opts, cons)
while true do
local device_res = find_device()
if device_res ~= nil then
log.info('===== DEVICE FOUND IN NETWORK...')
end
log.error('===== DEVICE NOT FOUND IN NETWORK')
end
end
return disco
Any help would be appreciated.
AlejandroPadilla
(Please contact @nayelyz or @Luis_Humberto_Medina )
2
Maybe the problem is in local res = udp:receive() if you try local res = udp:receivefrom() what happens? , I was checking the tutorial and the function is different
Thanks for getting back to me with your suggestion. Unfortunetly, I got the same result.
I also tried both local socket = require 'cosock.socket' and local socket = require 'socket' with no success.
Any other ideas?
AlejandroPadilla
(Please contact @nayelyz or @Luis_Humberto_Medina )
4
Mmm, let me do some tests, Could you share the response?
This is the response from the device as captured in wireshark:
Source IP/Port: 192.168.0.16 (3310)
Destination IP/Port: 255.255.255.255 (3310)
Data: DISCOVER:PA-RC2-WMP-1,CC3F1D04D392,192.168.0.16,ASCII,v1.3.3,-38,WMP_04D392,N,3
And, the protocol specification for the device im trying to integrate is here.
Really appreciate you helping me out!
1 Like
AlejandroPadilla
(Please contact @nayelyz or @Luis_Humberto_Medina )
6
Mmm I think the hub has not received the response because the device is sending the response to the broadcast address, so what happens If you change the destination?