Sending Commands with MQTT - is there a pattern?
<p>I'm new to MQTT: but I have got some basic Python programs working where sensor readings can be published to a particular topic: and other clients can then subscribe to get the temperature on a event-driven basis.</p>
<p>But when it comes to sending commands; I'm a little stuck on the best to do this.</p>
<p>So for example: take a 'countdown timer' connected to mqtt.</p>
<p>This timer has two states: 'stopped' and 'started'.
It will initialize itself into the 'stopped' state and wait for a 'start' command; and then will count down; publishing the current countdown to a topic.
When the countdown reaches zero; it will switch its state to 'stopped' again, and wait for another 'start' command.</p>
<p>If it receives a 'stop' command (over mqtt); it should also go into the 'stopped' state.</p>
<p>So perhaps I could create topics something like:</p>
<pre><code>countdown_timer/command
countdown_timer/state
countdown_timer/value
</code></pre>
<p>And the countdown device could subscribe to 'command' and react by publishing to 'state'. ('stopped' or 'started'?)</p>
<p>But should the client somehow 'consume' the 'command' topic value once it has processed it ?</p>
<p>Or would it better to have something like:</p>
<pre><code>countdown_timer/send_command
countdown_timer/command_result
</code></pre>
<p>Where the controller would send a command, the subscribed-device would carry-out the command and put 'ok' or 'error' on the 'command_result' topic ?</p>