UDP Not Possible They Said? Wait, what's this?

Hi @pstuart,

It seems you managed to solve the TCP packet issue and I’ve been struggling with this for a while now (through device types). Can you show us an example of TCP packet sent through ST?

Thanks,
Elfège

look at practically any hubaction local device service manager (sonos, hue, etc.). Depends on what you are trying to do, but the recommended process is to write a smartapp service manager, do all the lan activity there and then route status to/from a virtual child device(s).

1 Like

Hi, and thank you for your answer.

What I’m trying to do is send a simple 8 bit tcp packet to a wifi connected TCP server (SainSmart iMatic V2). This device is installed inside an old Neato Robot vacuum and so far I’ve been using a virtual device which httpGet() to an arduino. The arduino then sends the proper tcp packet. What I would like to do is send the TCP packet directly from a virtual device (or an app if it has to be from an app, which sounds weird to me though - not sure I got what you mean by “a smartapp service manager”).

Here is the code I’ve been messing around with so far within a virtual device:

def on() {

    sendEvent(name: "switch", value: "cleaning")
    log.debug "Neato is -------------------------- cleaning"
    state.switch  = "on"

   // def deviceNetworkId = "4796940DE:50"  //  "19216810206:80"
    // def ip = "192.168.10.206:80"

    //sendHubCommand(new physicalgraph.device.HubAction("""GET /?status=10 HTTP/1.1\r\nHOST: $ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))

    // byte on[] = {0xfd, 0x02, 0x20, 0x01, 0x01, 0x5D}; // code in my arduino sketch
    //byte off[] = {0xfd, 0x02, 0x20, 0x01, 0x00, 0x5D};
	
     byte[] bytes = [0xfd, 0x02, 0x20, 0x01, 0x01, 0x5D] // These are the bytes to send to the device
    String str = new String(bytes)    // Convert the bytes into an ASCII string ? Should I do that? 
    log.debug "${str}" 
    // debug shows weird result such as  "� ] " while it should be "ý ]" but anyway I 
// don't see how this right because the device is expecting binary data, not strings... 
// binary? tcp isn't always in hex? 
   
   def ip = "192.168.10.22:8008"
   def deviceNetworkId = "728A867E:1F48"  //  "1921681022:8008"
   def x = new physicalgraph.device.HubAction("FD022001015D\r\nHOST: $ip\r\n\r\n", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}")
    //x.options = [type:"LAN_TYPE_UDPCLIENT"]
    sendHubCommand(x)
    
/*
	def deviceNetworkId = "728A867E:1F48"  //  "1921681022:8008"
    def ip = "192.168.10.22:8008"
   
        
    def ByteToSend = "FD022001015D"
   
    
    
    log.debug command.toString()
    // Debug the output
    def command = new physicalgraph.device.HubAction("${str}" , physicalgraph.device.Protocol.LAN, "728A867E:1F48")
    // The above line's parameters are as follows: The data to send, the protocol for transmitting the data, and the IP ...
    // ... send the data to (in hex). In this case, the IP and port 
    
    sendHubCommand(command)
    */
}

yeah, so bad news, extended chars (>256) in converting to hex get stripped out by ST. Nothing I have found to get around it.

Thank you @pstuart for you answer. However I wonder in what way this code sends extended chars above 256, since what I’m sending, once converted into chars, remains pretty short. The equivalent of my hex packet in chars is only “ý]” and that is 2 chars, right? Beginner’s question I suppose, I see that I’m missing something, I just don’t know what… :frowning:

That’s great news! Thanks a lot!

Hi there,

Just wondering if anyone else has gotten this to work or has smartThings blocked this?

Here’s my part of my code but it doesn’t seem to send anything.

def hubCmd = new physicalgraph.device.HubAction(“1149ACCF23557A54b38d85d9f427638ef1e1af6dfcf37818\r\nHOST: 192.168.3.113:38899\r\n\r\n”, physicalgraph.device.Protocol.LAN, “C0A80371:97F3”)
hubCmd.options = [type:“LAN_TYPE_UDPCLIENT”]
sendHubCommand(hubCmd)

RBOY,

Does the hubAction then process a response return strings in any way?

Dave

not that I recall.

Sorry for bringing up such an old thread.
I’m also trying to send extended ASCII chars to a device I have through TCP, however the extended chars are being sent corrupted.
I also tried you way (sending “0xFE” as “\u00FE”, for example), but with no success (it’s sent as “0xc3 0xbe”).
Any idea what can I do?

The only way you’ll get raw UDP/TCP support is by using Hubitat. You could use that with Hub Link to accomplish what you’re looking for.

If you go with that route, send me a message and I can give you some primer code :slight_smile:

@adamkempenich, I am trying to send a text string to my AV controller with webcore on Hubitat. It is TCP/IP.
Example string : EVENT C[1].Z[5]!ZoneOn

All string commands are made up of ASCII characters except for the terminating characters. All commands must be terminated with a carriage return (0x0D hex). I just cannot get this to work. Suggestions?

I suggest taking this conversation to the Hubitat forum (or PM). It’s way off topic here, and it’s only going to confuse people, particularly since the rest of the thread is also outdated and refers to the previous platform. :wink:

1 Like