<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sending commands to Thingy91 by subscribing to mqtt server</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/72066/sending-commands-to-thingy91-by-subscribing-to-mqtt-server</link><description>Hi Dev team, 
 I am working on a Thingy91 device, and I am sending data out through MQTT. 
 I need a functionality to send some commands to do assigned tasks from the MQTT server back to the LTE device. 
 Are there any nRF or Zephyr API that supports</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 04 Mar 2021 10:15:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/72066/sending-commands-to-thingy91-by-subscribing-to-mqtt-server" /><item><title>RE: Sending commands to Thingy91 by subscribing to mqtt server</title><link>https://devzone.nordicsemi.com/thread/297729?ContentTypeID=1</link><pubDate>Thu, 04 Mar 2021 10:15:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f80dfbe1-67cc-467d-b09b-c48949de6b4e</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;The mqtt_evt_handler function is the same as in the mqtt_simple sample.&lt;/p&gt;
&lt;p&gt;If it receives the MQTT_EVT_PUBLISH event (which means that it has received a message on some topic), it checks if the topic is the command topic, and if it is, it calls a function that handles the command (handle_command_message()).&lt;/p&gt;
&lt;p&gt;The handle_command_message() function parses the command (from some unspecified format to something that is easier to work with in the code, e.g. an enum). When the command is parsed, the function checks what command it is, and calls a new function that handles that particular command.&lt;/p&gt;
&lt;p&gt;mqtt_evt_handler is already a part of the mqtt_simple sample. is_command_topic(), handle_command_message(), parse_command() and handle_set_light() (or handle_lighton() or handle_&amp;lt;this particular command&amp;gt;()) you must implement yourself.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending commands to Thingy91 by subscribing to mqtt server</title><link>https://devzone.nordicsemi.com/thread/296763?ContentTypeID=1</link><pubDate>Mon, 01 Mar 2021 08:55:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69a73223-9094-4ed3-bfe8-5ada9f1037d2</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Didrik,&lt;/p&gt;
&lt;p&gt;Thanks for the pseudocode. I was trying to understand it but was a bit confused.&lt;/p&gt;
&lt;p&gt;Would it be possible if you could incorporate it in the mqtt_simple sample project so I could understand it a bit better. That would be a great help for me &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Basically I am currently trying to turn on the LED0 of the Thingy91, when I subscribe to a topic and receive a command &amp;quot;LIGHTON&amp;quot; from my server.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adeel.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending commands to Thingy91 by subscribing to mqtt server</title><link>https://devzone.nordicsemi.com/thread/296604?ContentTypeID=1</link><pubDate>Fri, 26 Feb 2021 15:16:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e62d8bd3-4ba7-4523-a48f-2aa55c283477</guid><dc:creator>Didrik Rokhaug</dc:creator><description>[quote user="Adeel"]Could you let me know any examples of such libraries available ?[/quote]
&lt;p&gt;&amp;nbsp;The most common libraries: CoAP, LwM2M, MQTT, HTTP, cloud_client.&lt;/p&gt;
&lt;p&gt;Note that only LwM2M actually says anything about what data is sent. The other libraries just send arbitrary data, and it is up to you to define what the data means. and how it is encoded.&lt;/p&gt;
&lt;p&gt;But, again, MQTT is probably the most suitable protocol here, and you are already using it.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Adeel"]But I was looking for any specific nRF or Zephyr libraries that help in this functionality.[/quote]
&lt;p&gt;&amp;nbsp;I don&amp;#39;t quite understand what you need help to, or want the library to do.&lt;/p&gt;
&lt;p&gt;Here is some pseudocode showing roughly how I would have done it (which is also roughly how it is done in the asset_tracker):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;func handle_command_message(message):
    command = parse_command(message)
    switch command:
        SET_LIGHT:
            handle_set_light(command)

func mqtt_evt_handler(evt):
    switch evt.type:
        MQTT_PUBLISH:
            if is_command_topic(evt.data.message.topic):
                handle_command_message(evt.data.message.data)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending commands to Thingy91 by subscribing to mqtt server</title><link>https://devzone.nordicsemi.com/thread/296571?ContentTypeID=1</link><pubDate>Fri, 26 Feb 2021 13:49:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e406c994-75cc-4b52-9f6f-5751449c41b5</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Didrik,&lt;/p&gt;
&lt;p&gt;Thanks for the reply.&amp;nbsp;&lt;/p&gt;
[quote userid="81181" url="~/f/nordic-q-a/72066/sending-commands-to-thingy91-by-subscribing-to-mqtt-server/296543#296543"]&amp;nbsp;There are many libraries for sending data between a server and the nRF9160.[/quote]
&lt;p&gt;Could you let me know any examples of such libraries available ? I just want to build an interface wherein I assign a certain task based on a specific command. I just wanted to understand how the library helps me to communicate between a server and the LTE Device.&lt;/p&gt;
[quote userid="81181" url="~/f/nordic-q-a/72066/sending-commands-to-thingy91-by-subscribing-to-mqtt-server/296543#296543"]&amp;nbsp;If you already have an MQTT connection, that sounds like the easiest way.[/quote]
&lt;p&gt;Yes, right now I have an enabled MQTT connection and I am subscribing to a topic and receiving the commands I try to send from a server on that topic.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But I was looking for any specific nRF or Zephyr libraries that help in this functionality.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adeel.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending commands to Thingy91 by subscribing to mqtt server</title><link>https://devzone.nordicsemi.com/thread/296543?ContentTypeID=1</link><pubDate>Fri, 26 Feb 2021 12:49:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d18a5445-bb63-4156-86f3-d0e81ecf682d</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]Are&amp;nbsp;there any nRF or Zephyr API that supports this functionality to send commands from any server to the LTE Device?&amp;nbsp;[/quote]
&lt;p&gt;&amp;nbsp;There are many libraries for sending data between a server and the nRF9160. What you do with that data is up to you.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]What would be a feasible approach to implement the command functionality ?[/quote]
&lt;p&gt;&amp;nbsp;If you already have an MQTT connection, that sounds like the easiest way.&lt;/p&gt;
&lt;p&gt;MQTT let you send arbitrary data. What you do with that data is up to you. You could either have a way in the message to indicate that it is a command, or you could send the commands on a specific topic.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Didrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending commands to Thingy91 by subscribing to mqtt server</title><link>https://devzone.nordicsemi.com/thread/296541?ContentTypeID=1</link><pubDate>Fri, 26 Feb 2021 12:49:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c293116-eebc-40d7-a484-c758163672cb</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]Are&amp;nbsp;there any nRF or Zephyr API that supports this functionality to send commands from any server to the LTE Device?&amp;nbsp;[/quote]
&lt;p&gt;&amp;nbsp;There are many libraries for sending data between a server and the nRF9160. What you do with that data is up to you.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]What would be a feasible approach to implement the command functionality ?[/quote]
&lt;p&gt;&amp;nbsp;If you already have an MQTT connection, that sounds like the easiest way.&lt;/p&gt;
&lt;p&gt;MQTT let you send arbitrary data. What you do with that data is up to you. You could either have a way in the message to indicate that it is a command, or you could send the commands on a specific topic.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Didrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>