Search code examples
python-2.7ibm-cloudiot

IBMIOTF/BlueMix Publish Command Syntax


I am attempting to assemble a small proof of concept system on IBM's Bluemix/Internet of Things. Currently this comprises of a Raspberry Pi feeding events up to the cloudbased app, which currently stores those events away, and periodically attempts to send down a command, using the following code block:

def sendCmd(command, payload, device="raspberrypi" ):
    deviceId = #Fixed value
    global cmdCount
    client.publishCommand("raspberrypi", deviceId, str(command), "json", payload)
    print "Sending '%s' cmd, payload '%s' to device %s" % (command, payload, deviceId)
    cmdCount = cmdCount + 1

As far as the documentation is concerned this appears to be the correct syntax, as described by the documentation :

   client.connect()
   commandData={'rebootDelay' : 50}
   client.publishCommand(myDeviceType, myDeviceId, "reboot", "json", myData)

No exceptions are thrown in this block of code, however the device is not receiving any commands; and the cloud foundry log is not throwing any errors. Is there a subtle point about the syntax I am missing?


Solution

  • This issue boiled down to having instantiated the wrong class on the Raspberry Pi. I had an instance of ibmiotf.application which registered a function to the variable self.client.commandCallback. However nothing appeared to be triggering the callback.

    Once I instantiated the device with the ibmiotf.device import rather than ibmiotf.application, the command callback started to be called. This required a couple of the minor changes, to support slightly different function calls, but they were fairly self explanatory when trying to run the code.

    The Device Class controls Events being published from the unit, and determines how to handle commands from upstream. Whereas the Application Class handles the receipt of Events and emission of Commands.