<?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>nRF Cloud - sending custom data to custom topic</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/116427/nrf-cloud---sending-custom-data-to-custom-topic</link><description>Hi 
 I&amp;#39;m currently trying to modify the nRF Cloud multi-service sample (SDK2.6) to send custom data to custom topics. But I can&amp;#39;t find a way to do this. 
 I want to send a JSON package like this to the custom topic &amp;quot;tdg&amp;quot;: 
 
 Other similar messages should</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 15 Nov 2024 14:51:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/116427/nrf-cloud---sending-custom-data-to-custom-topic" /><item><title>RE: nRF Cloud - sending custom data to custom topic</title><link>https://devzone.nordicsemi.com/thread/510741?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2024 14:51:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b43fee30-3654-4666-8f66-976292a24013</guid><dc:creator>Mariano Goluboff</dc:creator><description>&lt;p&gt;Ah - I misunderstood the original ask. I&amp;#39;m not aware of the nRF Cloud firmware library supporting sending to additional topics. You can do it with MQTT directly to additional topics:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.nordicsemi.com/bundle/nrf-cloud/page/APIs/MQTT/Topics.html#additional-topics-supported-by-nrf-cloud"&gt;https://docs.nordicsemi.com/bundle/nrf-cloud/page/APIs/MQTT/Topics.html#additional-topics-supported-by-nrf-cloud&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Another possible solution would be to change the cloud service. Instead of using MQTT to subscribe to topics, you could use the Message Routing Service to send the data to a REST cloud service:&lt;/p&gt;
&lt;p&gt;&lt;a id="" href="https://docs.nordicsemi.com/bundle/nrf-cloud/page/Devices/MessagesAndAlerts/MessageRoutingService/MessageRouting.html"&gt;https://docs.nordicsemi.com/bundle/nrf-cloud/page/Devices/MessagesAndAlerts/MessageRoutingService/MessageRouting.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Cloud - sending custom data to custom topic</title><link>https://devzone.nordicsemi.com/thread/510719?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2024 14:10:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7d6480b-9e50-410f-9ca9-a5e2f0427cca</guid><dc:creator>Bard</dc:creator><description>&lt;p&gt;Thanks a lot, Mariano.&lt;/p&gt;
&lt;p&gt;This will certainly work, but maybe I wasn&amp;#39;t clear about my objective. I want to send the object to a custom topic. We have a cloud service that subscribe to topics like:&amp;nbsp;&lt;span&gt;{mqtt_config.topic_prefix}m/d/{mqtt_config.client_id}/d2c/&lt;strong&gt;tdg,&amp;nbsp;&lt;/strong&gt;and hence, I want to send the JSON data to the same topic. The solution you suggest will send the data to&amp;nbsp;{mqtt_config.topic_prefix}m/d/{mqtt_config.client_id}/d2c since this is the default for nrf cloud library (?). Using &amp;quot;tdg&amp;quot; in&amp;nbsp;&lt;code&gt;create_timestampled_device_message&lt;/code&gt;&amp;nbsp;call will result in&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;div class="sqdtc"&gt;
&lt;div class="q5Q_9"&gt;&lt;strong&gt;appId&lt;/strong&gt;:&amp;quot;TDG&amp;quot;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="sqdtc"&gt;
&lt;div class="q5Q_9"&gt;messageType:&amp;quot;DATA&amp;quot;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="sqdtc"&gt;
&lt;div class="q5Q_9"&gt;ts:1731675207965&lt;/div&gt;
&lt;div class="q5Q_9"&gt;in nrf cloud, but it will not change the topic sent to(?).&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Cloud - sending custom data to custom topic</title><link>https://devzone.nordicsemi.com/thread/510702?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2024 13:25:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a16614e-9021-4963-a3fa-d8c070db76ce</guid><dc:creator>Mariano Goluboff</dc:creator><description>&lt;p&gt;I would start from &lt;code&gt;send_sensor_sample&lt;/code&gt;&amp;nbsp;in nRF Cloud multi-service sample. That sends a single numeric value to a sensor appId (&amp;quot;TEMP&amp;quot; and &amp;quot;COUNT&amp;quot; in this sample).&lt;/p&gt;
&lt;p&gt;If I understand correctly, you want to send to appId &amp;quot;tdg&amp;quot;, and send an object rather than a single value.&amp;nbsp;Change `sensor` to &lt;code&gt;&amp;quot;tdg&amp;quot;&lt;/code&gt; in &lt;code&gt;create_timestampled_device_message&lt;/code&gt;&amp;nbsp;call.&lt;/p&gt;
&lt;p&gt;Where `send_sensor_sample` calls &lt;code&gt;nrf_cloud_obj_num_add&lt;/code&gt;, you&amp;#39;ll want to use &lt;code&gt;nrf_cloud_obj_object_add&lt;/code&gt;, but before calling that you&amp;#39;ll need to create the object that you&amp;#39;ll pass to it.&lt;/p&gt;
&lt;p&gt;There&amp;#39;s a convenience macro to do that: &lt;code&gt;NRF_CLOUD_OBJ_JSON_DEFINE&lt;/code&gt;, then call &lt;code&gt;nrf_cloud_obj_init&lt;/code&gt;, and add the fields above. i.e. &lt;code&gt;nrf_cloud_obj_str_add(obj, &amp;quot;gp&amp;quot;, &amp;quot;2222&amp;quot;, false)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Remember to call &lt;code&gt;nrf_cloud_obj_free&lt;/code&gt; if there are errors, to avoid memory leaks.&lt;/p&gt;
&lt;p&gt;Mariano&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>