9

MQTT is widely used in IoT when it comes to exchanging application data between the end device and the host service. The publish-subscribe model makes it easy to use: no handshaking, negotiating etc (at least above the MQTT protocol layer). It's primarily geared towards data-producers being able to distribute their data easily to consumers.

However, when it comes to a central server wanting to configure settings on an end device, I'm not sure that the model is very suitable. The server will want to send a command to the device and wait for a response back (e.g. read a specific setting, wait for response), which doesn't really suit MQTT's publish-subscribe model.

I was wondering whether there are any existing protocols that are geared towards send and receiving commands and configuring remote devices?

  • 1
    Are you sure MQTT doesn't permit the client to subscribe to a control channel? I think this is the place to start looking for answers, but I'm not well enough up-to-speed to sumarise in an answer en.wikipedia.org/wiki/Representational_state_transfer – Sean Houlihane Apr 28 '17 at 12:30
  • 1
    Don't forget, the endpoint needs to be the one initiating the channel, so it's in control of power consumption. – Sean Houlihane Apr 28 '17 at 12:31
  • 1
    @SeanHoulihane It is certainly possible to use MQTT to send and receive commands/settings as you describe, but the way I see it, ideally you need to have a protocol that is "session-based", i.e. you create session, send a command and receive a response in that same session, thus easily linking the response to the original command. MQTT is message based, so there is nothing at all to link messages with each other - it's up to you to handle that part. I was wondering whether there was a readily available protocol that I could use for that purpose. – Amr Bekhit Apr 28 '17 at 13:19
  • 1
    en.wikipedia.org/wiki/OMA_LWM2M I'm not sure exactly how, but the cloud seems to be able to make PUT or POST calls to trigger a callback in the client. – Sean Houlihane Apr 28 '17 at 13:29
6

Sounds like a job for CoAP:

Like HTTP, CoAP is based on the wildly successful REST model: Servers make resources available under a URL, and clients access these resources using methods such as GET, PUT, POST, and DELETE.

From a developer point of view, CoAP feels very much like HTTP. Obtaining a value from a sensor is not much different from obtaining a value from a Web API.

It can apparently be implemented with very low overhead:

CoAP has been designed to work on microcontrollers with as low as 10 KiB of RAM and 100 KiB of code space

CoAP is specified in RFC 7252, and there are various implementations (e.g. in C).

It's very heavily inspired by REST as used with HTTP for web APIs, so if you're familiar with those, you'll quickly pick up CoAP. If not, you might find this presentation useful for context. The idea is that each HTTP method has a semantic meaning, e.g. GET requests information from the device without changing anything and POST, PUT and DELETE mutate the data.

As you say, publish/subscribe models wouldn't work for a situation where your device acts as a 'server' to the central system coordinating (which acts as a client to each device). Instead, a model similar to HTTP is ideal, except HTTP has far too much overhead, which is where CoAP comes in.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.