Sending mulicast messages with Vera


for discovering devices with specific portnumber I need to send “multicast” message to my

local network. The adress “” is functioning well with several (not-lua) devices

on my network. When I try this with my Vera3, in lua , I get no respond, doesn’t matter what I

do or try, nothing works. I tried several other “multicast” adresses like “” with no result.

The function I use works because I can sent messages to an device with a response message that I can

read. (LUACodeTest)

Is this possible with lua, and what do I have to change to get it working ?
This is my code:

socket = require(“socket”)
local s = socket.udp
bytes, ErrorCode = s:sendto(discoverDevice, “”, 5500)

function read_some(s)
local msg, err, part = s:receive(15)

if (not msg) and (err ~= ‘timeout’) then
return nil, err
msg = msg or part

if not msg then return nil, ‘timeout’ end
return msg


Thanks in advance,

Where/how does this fail?

I use UDP all the time in several applications, although not for multicast, so I use the setpeername() function.


thanks for your answer.
I tried to use setpeername() but got an error:

“string “ALTUI - LuaRunHandler”]:16: calling ‘send’ on bad self (udp{connected} expected, got userdata)”

Doesn’t the command setpeername() set a connection with a single device ?
It definately doesn’t work for adress “”, multicast.


[quote=“GreatGazoo, post:3, topic:205570”]Doesn’t the command setpeername() set a connection with a single device ?
It definately doesn’t work for adress “”, multicast.[/quote]

Yes, that seems to be the case.

The IP address is NOT a multicast address… It is the zero network BROADCAST address… and it is limited… Packets sent to this address are NOT forwarded by routers to other networks. (This means, if you have a device connected to a range extender, the packet sent to the zero network broadcast address from that device will never reach devices connected to your main router. Conversely, zero network broadcast packets sent from a device connected to your main router would never reach devices connected to the range extender). As all Vera units are essentially enhanced routers, packets sent to the zero network broadcast address are never forwarded outside of the Vera (except to devices that conected to and are using the Vera as a gateway). This is why you are receiving no response…

Multicast addresses are in the range to For discovery, the assigned multicast address is, which encompasses SSDP (Simple Service Discovery Protocol).

Discovering devices on the network is NOT as simple as sending a multicast packet… Many device manufactures use custom discovery addresses, custom discovery ports or special protocols (requiring a specially formatted UDP data).

If you want to send broadcast packets to your “private network”, you need to use the network broadcast address… IE: If your network is, the broadcast address would be

I use a version of the code below which works for me. I do note @dgb’s comment above about the ‘’ address. and agree with

Discovering devices on the network is NOT as simple as sending a multicast packet

I tried using multicast but failed in getting it to work. I therefore confess I’m not an expert in networking but my device of interest does communicate through a router. In my case the code below will get multiple replies and they all need to be handled and the device of interest checked for. Code has been extracted and may need a little massaging to suit. Interested in any feedback.

    local function debug(debugMessage)
        -- blah blah

    local function addToPhysicalDevicesList(var1, var2)

local function broadcastDiscoverDevicesMsg()
    local BROADCAST_IP = ''
    local UDP_IP_PORT = 5500
    local txMsg = 'Here is a message'

    local ok = false
    local udp = socket.udp()

    local BROADCAST_IP = ''
    -- HACK local MULTICAST_IP = ''

    -- asterisk represents all the local interfaces on Vera eg Lan, WiFi, etc
    local setOK, failMsg = udp:setsockname('*', UDP_IP_PORT)
    if (setOK == nil) then
        debug('Set socket name failed: '..failMsg,50)
        return ok

   udp:setoption('broadcast', true)
    debug('Broadcasting discovery message')
    local resultTX, errorMsg = udp:sendto(txMsg, BROADCAST_IP, UDP_IP_PORT)
    -- HACK local resultTX, errorMsg = udp:sendto(txMsg, MULTICAST_IP, UDP_IP_PORT)
    if (resultTX == nil) then debug('Broadcast TX failed: '..errorMsg) udp:close() return ok end

    local rxMsg = nil
    local ipOrErrorMsg = ''
    -- repeat until the queue of all the device responses has been processed
        -- allow for a msg length of 512. The receivefrom() function will block until timeout
        rxMsg, ipOrErrorMsg, _ = udp:receivefrom(512)
        if (rxMsg) then

            -- as the responses to the broadcast are rx'ed, add the devices to the list
            addToPhysicalDevicesList(rxMsg, ipOrErrorMsg)
    until (not rxMsg)



thanks for your reply.
I tried your code, but with no luck.
I tried to sent a message to my windows PC, where “packet sender” is installed,
but the message is not arriving, even if I try to sent the message directly (not thru
then I receive an " Result: false".