UDP broadcast support

Perfectly fine to talk about it, we just don't want to share the code publicly yet as it is probably not final and make sure those testing it understand that.


@patrick Any updates on the availability of UDP? I'd like to take a stab at making local lifx control but doing that requires listening to and broadcasting UDP.

1 Like

Yeah, I was wondering about this as well. To implement anything to control a DMX device we need UDP.

Here are some examples of sending UDP messages

For sending regular strings:

String message = "Hello"
def myHubAction = new hubitat.device.HubAction(message, 
								[type: hubitat.device.HubAction.Type.LAN_TYPE_UDPCLIENT, 
		                            destinationAddress: ""])

for sending binary messages (message back to parse will also be hex string encoded):

byte[] rawBytes = [0x71, 0x23,  0x0F, 0xA3]
String stringBytes = hubitat.helper.HexUtils.byteArrayToHexString(rawBytes)
def myHubAction = new hubitat.device.HubAction(stringBytes, 
                           [type: hubitat.device.HubAction.Type.LAN_TYPE_UDPCLIENT, 
                            destinationAddress: "",
                            encoding: hubitat.device.HubAction.Encoding.HEX_STRING])

HexUtils is documented here:


so is there a way to listen as well?

if you are asking about the hub receiving udp broadcasts from a device. No, we do not support that. You can only send out UDP messages and receive a reply to that message.

1 Like

ok, thanks. would be nice to have in the future

I would like UDP receive too. One of the protocols I use extensively (xAP) uses it to a broadcast address.

I think that means: An App on the hub must initiate the UDP exchange. The "reply" will be seen in the parse method of that App. That might mean Lifx can be implemented locally.

1 Like

Is there support for UDP unicast as well? The reason for asking is that the LIFX LAN protocol seems to recommend that unicast is used for addressing an individual bulb - although it looks as though broadcast might work as well but causing more wifi traffic than desirable.

1 Like

The only difference between broadcast and unicast is the address you send to. The examples I posted above are unicast messages.

1 Like

Great, thanks.

Would be nice to have listen capability too, i.e. parse to be called for every received packet on a specific port

1 Like

Two items:
a. When is the UDP support going live so I can test direct command of the TP-Link devices? It would greatly simplify installation and operations.

b. Another item I may need is straight TCP support (i.e., "net.connect" in node.js) to a device. Does or will Hubitat support this?


going live??

Back in September as far as I know.

Chuck pasted some code showing the basics 9 days ago.


Does anyone have answer to the second question. Again, currently I use Node.js (on a pc). Each command sends a net.connect, the actual data on the socket, and a socket.close. I need to try to port this to Hubitat to eliminate the pc Hub and also the alternative Kasa Cloud connection.


It would be great to see a slightly more fully worked example of an App that uses UDP, including processing the response.

I'm not sure if I'm missing something, but I think I'm sending a correct GetService packet to LIFX on, but I'm not seeing any responses in the parse method, it doesn't look like that method is being called at all. I'm not ruling out mistakes on my part though, obviously.

Any thoughts on how to debug this? Here's the initialize and parse methods - not really ready to share the rest of the code in public yet

def initialize() {
  state.sequence = 1
  def buffer = []
  def getServiceSequence = makePacket(buffer, 0, messageTypes().DEVICE.GET_SERVICE, false, false, [])
  def rawBytes = asByteArray(buffer)
  log.debug "raw bytes: ${rawBytes}"
  String stringBytes = hubitat.helper.HexUtils.byteArrayToHexString(rawBytes)
  log.debug "sending bytes: ${stringBytes}"
  def myHubAction = new hubitat.device.HubAction(
                type              : hubitat.device.HubAction.Type.LAN_TYPE_UDPCLIENT,
                destinationAddress: "",
                encoding          : hubitat.device.HubAction.Encoding.HEX_STRING
  def response = sendHubCommand(myHubAction)
  log.debug "response from sendHubCommand ${response}"
def parse(String description) {
  log.debug "parse description: ${description}"

For what it's worth, I'm not seeing any errors in the logs. I'm trying to monitor UDP activity on port 56700 with Wireshark but not seeing anything showing up, but then I could have misconfigured it due to a lack of familiarity.

A bit more progress...
Now that I've got a slightly better understanding of Wireshark I can see that I'm broadcasting (I think) a UDP packet, but I'm just not getting any response. If I send the packet using PacketSender then I'm getting responses from my LIFX devices! The only apparent differences (apart from the IP/MAC address of the sender) is that HE is setting the don't fragment flag in the datagram, and also setting a header checksum, the TTL is different (64 from packet sender and 128 from HE). The payload for LIFX looks to be the same apart from the sequence number

This is very puzzling.

1 Like

My current conjecture is that the socket on the hub has been closed before the LIFX devices have responded, not sure whether Wireshark would see any messages in that case. Is there another parameter that needs specifying to ensure that the socket stays open?

Download the Hubitat app