TCP Commands not transmitting with HubAction?

Hey all, I’ve been trying to send a simple TCP packet via my hub, but haven’t had any luck. I’ve tried writing both a SmartApp and a Device Type to transmit this, without any luck. Other network traffic seems to be working just fine to the receiving end of my TCP server.

Can anyone help point me in the correct direction? Here’s what my code looks like:

// Convert IP and Port to Hex for HubAction
def String ipaddr = "192.168.X.X"
def port = 1234

def String hexIp = ipaddr.tokenize('.').collect {
    String.format('%02X', it.toInteger())
}.join()

def String hexPort = String.format('%04X', port)
def String myNetworkID = "${hexIp}:${hexPort}"

// Display results of conversion
log.debug "network ID is " + myNetworkID


	def transmittedData = new physicalgraph.device.HubAction("This is a test string", physicalgraph.device.Protocol.LAN, myNetworkID)

// Is this part necessary? I've tried including it, and not including it
transmittedData.options = [type:"LAN_PROTOCOL_TCP"]

// Send data
sendHubCommand(transmittedData)	
}

Any help sure would be appreciated. I’ve scoured the forums and the documentation—I thought I had this working a couple years ago with TCP/UDP, but I’m not having any luck now :wink:

Thanks in advance!

Have you set the destination ip or port?

1 Like

Thanks for your response. The destination IP and Port are converted to their hex values in the first section, and then assigned as the variable myNetworkID, which is then passed as the third parameter for transmittedData.

Is that how destinations are supposed to be assigned? If I’m missing something super basic like that, I’d sure be a happy camper to learn that it’s correctable!

Check your options and are you looking for a response in the parse method? I don’t see any callback method registered:

type:“LAN_TYPE_CLIENT”, protocol:“LAN_PROTOCOL_TCP”

1 Like

Oh my goodness, adding those options did it! No parse response needed for my code (from my understanding we still can’t parse TCP responses, or has that changed?)

Thank you so much!

1 Like

With the help of this post I got smartthings to send tcp commands from device handler. Can someone confirm that there is no way to read tcp response? My parse method gets triggered but payload seems empty.

I’m having same trouble.

See this response to my query, seems smartthings is broke:

Yep, an empty response is the broken platform. Pending with ST’s engineers for a patch for months now, I can only hope they carve out some time to deploy the patch (apparently it’s coded but just been pending testing/deployment).

1 Like