hubAction call sending nothing from device type

(Mike Maxwell) #1

Obviously I’m missing something with hubAction…
Wireshark shows no packets from the hub to the target host…
Attempting to send some raw packets to my squeezebox server.

I’ve run it from the app as well as the IDE, zip nada…
Is the below not the correct syntax for this call???

Calling the heavy hitters…
Any thoughts on this guys?
@pstuart @scottinpollock @geko @wackware

metadata {
    definition (name: "squeezeSwitch", namespace: "mmaxwell", author: "Mike Maxwell") {
        capability "Switch"

    simulator {
        // TODO: define status and reply messages here

    tiles {
        standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
        state "on", label: '${name}', action: "", icon: "st.switches.switch.on", backgroundColor: "#79b821"
        state "off", label: '${name}', action: "switch.on", icon: "", backgroundColor: "#ffffff"
    main "switch"

// parse events into attributes
def parse(String description) {
    log.debug "Parsing '${description}'"
    // TODO: handle 'switch' attribute

private String makeNetworkId(ipaddr, port) { 
     String hexIp = ipaddr.tokenize('.').collect { 
     String.format('%02X', it.toInteger()) 
     String hexPort = String.format('%04X', port) 
     //log.debug "${hexIp}:${hexPort}"
     return "${hexIp}:${hexPort}" 

// handle commands
def on() {
    log.debug "Executing 'on'"
    def nid = makeNetworkId("",9090)
    return new physicalgraph.device.HubAction("00:04:20:17:b2:04 power 1\r\r\n",physicalgraph.device.Protocol.LAN, "${nid}") 

def off() {
    log.debug "Executing 'off'"
    def nid = makeNetworkId("",9090)
    return new physicalgraph.device.HubAction("00:04:20:17:b2:04 power 0\r\r\n",physicalgraph.device.Protocol.LAN,"${nid}") 

DSC/Vista Alarm Smartapp and devices based on AlarmServer
(Todd Wackford) #2

Is this a post or put? And shouldn’t it be \r\n\r\n?

(Mike Maxwell) #3

The end point understands telnet, so I’m not sure exactly how to send the command shown.
In a nut shell I’m emulate this:
telnet 9090
"00:04:20:17:b2:04 power 1"

(Geko) #4

It’s not enough to pass device network id to HubAction. You also need to set the actual device.deviceNetworkId property.

(Mike Maxwell) #5

added the following after makeNetworkID

device.deviceNetworkId = nid
still squat…

(Geko) #6

I’d suggest debugging your code in a smart app rather than a device handler. Device handlers are too finicky.

(Todd Wackford) #7

Oh jeece, I didn’t pick up on that. I don’t even think you can do hub actions from a device. I think only the app can.

(Convinced ST will never be unbroken…) #8

I do it from my thermostat device using:

private getapi() {
  log.debug("Executing get api to " + getHostAddress())
  def uri = "/query/info"
  def hubAction = new physicalgraph.device.HubAction(
    method: "GET",
    path: uri,
    headers: [HOST:getHostAddress()]
private postapi(command) {
	log.debug("Executing ${command}")
	def uri = "/control"
	def hubAction = [new physicalgraph.device.HubAction(
		method: "POST",
		path: uri,
		body: command,
		headers: [Host:getHostAddress(), "Content-Type":"application/x-www-form-urlencoded" ]
		), delayAction(1000), refresh()]

(Patrick Stuart [@pstuart]) #9

You can do hubactions from a device, see my generic camera devicetype for examples.

The key is device.deviceNetworkId, properly formatted.

If you don’t care about getting a response (and with raw commands, you won’t) then it should work…

I’ve had issues with a virtual device sending commands, but once you install it as a working device in the IDE then attach the IDE to that device it works.

(Todd Wackford) #10

Ah I see now. Yeah I have only done devices where I need responses.

(James) #11

I had similar issues with a Raspberry Pi device.

To get it to work at all, I had to:

  • Ask support to update my firmware. I had an ancient version which didn’t do POST/GET. The iOS app insisted that the firmware was up to date, when it was not.
  • Set the deviceNetworkId manually in the devices pane of the IDE, I’m not sure why it didn’t work from the device itself.

Then I saw packets from the hub with wireshark + a sniffer.

Still having problems with unsubscribing from a previously-used IP/port combination, however. When I deleted the device in desperation, requests sent by the new device instance would be routed to the old instance. I guess the code is missing an unsubscribe somewhere. To avoid that, I’ve been bumping the IP or port number – but that’s not really a sustainable solution.

(Mike Maxwell) #12

Well freaking SOB!, that was the issue @JamesH .
Jacking the hex networkID into the actual device in the IDE worked.
Thanks for that, I was ready to give up.
It’s really too bad that all this tribal knowledge isn’t documented somewhere…

I figured it was something boneheaded simple…

(James) #13

Maybe the device.deviceNetworkId is read-only from a device, and can only be written by a SmartApp?

(Geko) #14

It used to be writeable, no doubts about it, but a lot of small but annoying changes were pushed into the framework last month, so I would’t be surprised if that is one of them.