As with events you need to use Basic Auth, specifying ‘use-token-auth’ as the userid and the device’s token as the password. ¬†If there’s a command waiting then you’ll get it back as the body of the response message, if there isn’t then you’ll get a return code of 204.

HTTP isn’t as good at¬†being sent data from the server side as a bi-directional protocol like MQTT. ¬†Most HTTP communication is driven from the client side, rather than the server. ¬†From the above example, you’d have to keep polling the server to see if there was a message waiting. ¬†That’s slow and computationally expensive. ¬†For some use cases that’s fine – where you’re trying to conserve power, and just wake up periodically to check whether there’s a message waiting for you. ¬†For other use cases you want the command to arrive as soon as¬†it is sent. For that you can issue what’s often called a long poll.

Set the body of the message to:

{"waitTimeSecs": 10}

The number represents a number of seconds. ¬†It tells the server to hold on to the request and only respond back if there’s a message or the number of seconds elapses. ¬†That way you can effectively set your code to ‘wait’ for a command to arrive.