<?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>Parsing sensor data to a JSON file through MQTT Broker</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/68689/parsing-sensor-data-to-a-json-file-through-mqtt-broker</link><description>Hi Dev team, 
 I am working on a nrf9160DK and transmitting my sensor data to a MQTT Client. I tested this through an application : MQTT.fx (Using mqtt.eclipse.org as open source broker) and I was able to get my data published. 
 Now, I need to parse</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 26 Nov 2020 15:28:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/68689/parsing-sensor-data-to-a-json-file-through-mqtt-broker" /><item><title>RE: Parsing sensor data to a JSON file through MQTT Broker</title><link>https://devzone.nordicsemi.com/thread/282135?ContentTypeID=1</link><pubDate>Thu, 26 Nov 2020 15:28:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65a25b36-ea86-48eb-b2c5-e8765543f64d</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Jonathon,&lt;/p&gt;
&lt;p&gt;Just to let you know that I got it working, thanks for the guidance on this &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;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: Parsing sensor data to a JSON file through MQTT Broker</title><link>https://devzone.nordicsemi.com/thread/282013?ContentTypeID=1</link><pubDate>Thu, 26 Nov 2020 10:43:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f84cf81-1473-4b28-9ba6-a86e999435cc</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Jonathon,&lt;/p&gt;
&lt;p&gt;Thanks for the information. now, I am clear with this. The broker and topics are already configured in the prj.conf, so my task is to just parse the data accordingly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I will try this and let you know, but real thanks for clearing up my queries regarding this &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;. Really appreciate it.&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: Parsing sensor data to a JSON file through MQTT Broker</title><link>https://devzone.nordicsemi.com/thread/281950?ContentTypeID=1</link><pubDate>Thu, 26 Nov 2020 08:22:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73cf9668-3ca8-4ffa-93a3-841d7738385f</guid><dc:creator>JONATHAN LL</dc:creator><description>&lt;p&gt;Hi Addel,&lt;br /&gt;&lt;br /&gt;There si no need send the broker info in JSON format. The MQTT example is setting up a MQTT client on the nrf9160 much like the MQTT.fx does on your computer. First the client tries to connect to the server(broker), and when it achieves a connection it will subscribe to a topic (my/publish/topic). Then there is no need to send the broker port and topic together with the&amp;nbsp;message(sensor data). You can do it but since it the broker and topic info is all ready known it should be no use to send it as well.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;You can also test the&amp;nbsp;mqtt_simple example with &lt;a href="http://www.hivemq.com/demos/websocket-client/"&gt;HIVE mqtt websocket&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Here is a &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/68664/cjson-error"&gt;link to a extra cJSON Devzone case&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
[quote user="Adeel"]I also needed to segregate different data in a JSON format like how it is in the attached JSON file and send out. So, I think cJSON library is a good starting point for this[/quote]
&lt;p&gt;Yes, cJSON will work for this.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Jonathan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Parsing sensor data to a JSON file through MQTT Broker</title><link>https://devzone.nordicsemi.com/thread/281884?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2020 15:32:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a6863cd-d497-4a58-872a-c9f0477be903</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Jonathon,&lt;/p&gt;
[quote userid="91187" url="~/f/nordic-q-a/68689/parsing-sensor-data-to-a-json-file-through-mqtt-broker/281874#281874"]Could you link to what example you are getting the config.json file from?&amp;nbsp;[/quote]
&lt;p&gt;I had a python code through which I was able to generate the file. It used the paho library to connect to the broker.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/mqttgen.py"&gt;devzone.nordicsemi.com/.../mqttgen.py&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Yes, my prj.conf file has the same configuration. Actually, I had tested my data transfer through MQTT.fx with : mqtt.eclipse.org and that worked.&lt;/p&gt;
&lt;p&gt;I wanted to transfer the same data from my nrf9160DK now directly to this JSON file and not go through MQTT.fx at all.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I also needed to segregate different data in a JSON format like how it is in the attached JSON file and send out. So, I think cJSON library is a good starting point for this.&amp;nbsp;&lt;/p&gt;
[quote userid="91187" url="~/f/nordic-q-a/68689/parsing-sensor-data-to-a-json-file-through-mqtt-broker/281874#281874"]This refers to MQTT.fx working&amp;nbsp; and not nrf9160 mqtt_simple working ?&lt;br /&gt;[/quote]
&lt;p&gt;Yes, sending data to MQTT.fx is working with nrd9160 mqtt_simple.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adeel.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Parsing sensor data to a JSON file through MQTT Broker</title><link>https://devzone.nordicsemi.com/thread/281874?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2020 15:08:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:655b4a0e-1fd0-428e-8e2f-1e9c11dc90a1</guid><dc:creator>JONATHAN LL</dc:creator><description>&lt;p&gt;Hi Adeel,&lt;br /&gt;&lt;br /&gt;Could you link to what example you are getting the config.json file from?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Lets say you wat to use MQTT on the nrf9160, we can start by suing the mqtt_simple example provided in NCS as you said you are using. If we go tot he &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/4c0d3be2ed4ade4dc3e614e95e6f8e4330d663b4/samples/nrf9160/mqtt_simple/prj.conf#L30"&gt;prj.conf&lt;/a&gt; file we can see a section called #application. All you have to do is fill out the information about the broker there( it is by default commented out). Then there is no need for a dedicated config.json file, everything can be done in the prj.conf file.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Appliaction
CONFIG_MQTT_PUB_TOPIC=&amp;quot;/my/publish/topic&amp;quot;
CONFIG_MQTT_SUB_TOPIC=&amp;quot;/my/subscribe/topic&amp;quot;
CONFIG_MQTT_CLIENT_ID=&amp;quot;my-client-id&amp;quot;
CONFIG_MQTT_BROKER_HOSTNAME=&amp;quot;mqtt.eclipse.org&amp;quot;
CONFIG_MQTT_BROKER_PORT=1883&lt;/pre&gt;&lt;/p&gt;
[quote user=""] MQTT.fx (Using mqtt.eclipse.org as open source broker) and I was able to get my data published.[/quote]
&lt;p&gt;&amp;nbsp;This refers to MQTT.fx working&amp;nbsp; and not nrf9160 mqtt_simple working ?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There are no stupid questions, feel free to ask anything&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Jonathan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Parsing sensor data to a JSON file through MQTT Broker</title><link>https://devzone.nordicsemi.com/thread/281865?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2020 14:45:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5d68dd8-b622-4750-9631-3a4332eec7f1</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Jonathon,&lt;/p&gt;
&lt;p&gt;Okay, now I get your point. Yes, I think I don&amp;#39;t need a file system.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I will study the cJSON library and try to send my data out through it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1 question regarding my existing JSON file that I linked above:&lt;/p&gt;
&lt;p&gt;It has an mqtt field :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;quot;mqtt&amp;quot;: {&lt;br /&gt;&amp;quot;host&amp;quot;: &amp;quot;mqtt.eclipse.org&amp;quot;,&lt;br /&gt;&amp;quot;port&amp;quot;: 1883,&lt;br /&gt;&amp;quot;topic&amp;quot;: &amp;quot;my/publish/topic&amp;quot;&lt;/p&gt;
&lt;p&gt;Is this field enough for the board to recognise this broker and send the data to this file.&lt;/p&gt;
&lt;p&gt;I know its a naive question, but I have never worked with file systems as such :). Just worked with inbuilt software&amp;#39;s so was not sure if the writing happens in this way.&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: Parsing sensor data to a JSON file through MQTT Broker</title><link>https://devzone.nordicsemi.com/thread/281792?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2020 12:25:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15133dd2-f7a8-4c20-9a46-8b4dd2603f28</guid><dc:creator>JONATHAN LL</dc:creator><description>&lt;p&gt;Hi Adeel,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;It is not a file like in a file system file, it is a object witch you can store data in. You can follow the examples in aws_iot(&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/bcdf4be4c56e04483d3aebf2fe6ef7debbb140ac/samples/nrf9160/aws_iot/src/main.c#L42"&gt;link to use here&lt;/a&gt;) and asset_tracker (&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/bcdf4be4c56e04483d3aebf2fe6ef7debbb140ac/applications/asset_tracker/src/cloud_codec/cloud_codec.c#L279"&gt;link to use in assetracker&lt;/a&gt;) to see how it is used to for with JSON in C. If you want your own file that contains JSON data and want to read and write to that file then you need to use a file system.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Here is the &lt;a href="https://github.com/DaveGamble/cJSON"&gt;link to the documentation&lt;/a&gt; for cJSON. I recommend reading this, the implementation used in the aws_iot and asset_tracker examples are a bit much to get into at first.&lt;br /&gt;&lt;br /&gt;Here is a similar case on Devzone:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/65278/mqtt-simple-nrf9160-send-json-as-utf-8"&gt;Mqtt simple nrf9160, send JSON as utf-8 - Nordic Q&amp;amp;A - Nordic DevZone - Nordic DevZone (nordicsemi.com)&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;If you want a file system then maybe look in to&amp;nbsp;&lt;span&gt;Zephyr RTOS Virtual Filesystem Switch (VFS)&amp;nbsp;, but i dont hink that it is needed if i understand your use case&amp;nbsp;correctly.&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Jonathan&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Parsing sensor data to a JSON file through MQTT Broker</title><link>https://devzone.nordicsemi.com/thread/281777?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2020 11:50:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34242b09-f657-45ff-a44c-3a85d812756f</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Jonathon,&lt;/p&gt;
&lt;p&gt;I was progressing with this and I found a cjson library in the nrf folder :&amp;nbsp;C:\Users\adeel\ncs\v1.3.0\nrf\ext\cjson&lt;/p&gt;
&lt;p&gt;It contains the cJSON.c and cJSON.h file.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can this library file be used to generate a JSON file of its own ? Then I can create a file and add my fields in the same file.&amp;nbsp;&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: Parsing sensor data to a JSON file through MQTT Broker</title><link>https://devzone.nordicsemi.com/thread/281681?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2020 23:26:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd781954-fbac-41a2-8ee7-d893d00d6ad8</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Jonathon,&lt;/p&gt;
&lt;p&gt;Thanks for the detailed reply &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;. Gave me a lot of insight.&lt;/p&gt;
&lt;p&gt;I was actually looking to write my sensor data to this JSON file through the nrf9160dk example.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/config.rar"&gt;devzone.nordicsemi.com/.../config.rar&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The JSON has a mqtt field :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;quot;mqtt&amp;quot;: {&lt;br /&gt; &amp;quot;host&amp;quot;: &amp;quot;mqtt.eclipse.org&amp;quot;,&lt;br /&gt; &amp;quot;port&amp;quot;: 1883,&lt;br /&gt; &amp;quot;topic&amp;quot;: &amp;quot;my/publish/topic&amp;quot;&lt;/p&gt;
&lt;p&gt;through which I want to identify the broker to which I am sending the data.&lt;/p&gt;
&lt;p&gt;After that, I just want to add my data by creating a value tag for a sensor.&lt;/p&gt;
&lt;p&gt;So, as a first step, I wanted to know as to how to create this type of JSON file through C that I could through SES.&lt;/p&gt;
&lt;p&gt;Also, how to write values into this kind of a file.&lt;/p&gt;
&lt;p&gt;&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: Parsing sensor data to a JSON file through MQTT Broker</title><link>https://devzone.nordicsemi.com/thread/281674?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2020 20:54:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73ebd894-4448-4923-812f-aed4620f79d4</guid><dc:creator>JONATHAN LL</dc:creator><description>&lt;p&gt;&lt;br /&gt;Hi,&amp;nbsp;&lt;/p&gt;
[quote user=""]my/publish/topic.[/quote]
&lt;p&gt;&amp;nbsp;I would advise to not use the default topics and topic structure in the final project as it may end up getting random test data from anyone. Add some extra label or&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/4c0d3be2ed4ade4dc3e614e95e6f8e4330d663b4/samples/nrf9160/mqtt_simple/prj.conf#L30"&gt;rename something&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have not used MQTT.FX so i cant really give propper feedback on that. Here is a &lt;a href="http://www.steves-internet-guide.com/send-json-data-mqtt-python/"&gt;link to a different solution&lt;/a&gt; that might be equally helpful using python.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user=""]I would like to know the steps that would be required to parse data from my code to a JSON file.[/quote]
&lt;p&gt;&amp;nbsp;Do you mean on the nrf9160 or on the MQTT.FX side? Do you intend to store JSON files on the nrf9160 or are you takling about putting sensor data in to a JSON format?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A proposed solution based on initial understanding of the question:&lt;br /&gt;&lt;span&gt;- Take measurement &lt;br /&gt;- Send as MQTT message to broker Use another client (such as MQTT.fx) to receive the message &lt;br /&gt;- Take the necessary information from the MQTT payload&lt;br /&gt;- Pass this information to a function that generates your JSON file&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The last two steps i assume can be done in MQTT.fx&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Take a look &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.3.0/applications/asset_tracker/src/cloud_codec/cloud_codec.c"&gt;this example&lt;/a&gt;, it includes a more complex solution that uses JSON. There has been som changes in the newer version v1.4.0 that improves the example so might be smart to look at latest&amp;nbsp;release tag.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;What is the end goal? Do you intend to use a desktop/phone application to view sensors?&lt;br /&gt;&lt;br /&gt;Here is a &lt;a href="https://devzone.nordicsemi.com/nordic/cellular-iot-guides/b/software-and-protocols/posts/connecting-to-aws-cloud-services-using-the-nrf9160"&gt;link to a guide using AWS Cloud&lt;/a&gt; solution, it might be of interest.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Jonathan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>