publish multiple values to thingspeak using MQTT | Raspberry Pi | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
publish multiple values to thingspeak using MQTT
No permission to create posts
March 8, 2018
2:37 pm
Avatar
digimation
New Member
Members
Forum Posts: 2
Member Since:
March 8, 2018
sp_UserOfflineSmall Offline

I am trying to publish a multiple random data using mqtt to send data from raspberry pi to thingspeaks.
i want to publish the 10 values of temp to thingspeaks field but it limits me to one value every 15 seconds.
so is there anyway to send a list of values every 15 second to graph it with time in thingspeaks channels??

 

<span class="pln">temp </span><span class="pun">=</span> <span class="pun">[]</span><span class="pln"> current </span><span class="pun">=</span> <span class="pun">[]</span> <span class="kwd">while</span><span class="pun">(</span><span class="lit">1</span><span class="pun">):</span> <span class="com"># get the system performance data over 20 seconds.</span> <span class="kwd">for</span><span class="pln"> i </span><span class="kwd">in</span><span class="pln"> range</span><span class="pun">(</span><span class="lit">10</span><span class="pun">):</span><span class="pln"> temp</span><span class="pun">.</span><span class="pln">append</span><span class="pun">(</span><span class="pln">random</span><span class="pun">.</span><span class="pln">randint</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span> <span class="lit">100</span><span class="pun">))</span><span class="pln"> current</span><span class="pun">.</span><span class="pln">append</span><span class="pun">(</span><span class="pln">random</span><span class="pun">.</span><span class="pln">randint</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span> <span class="lit">100</span><span class="pun">))</span> <span class="com"># build the payload string.</span><span class="pln"> payload </span><span class="pun">=</span> <span class="str">"field1="</span> <span class="pun">+</span><span class="pln"> str</span><span class="pun">(</span><span class="pln">temp</span><span class="pun">)</span> <span class="pun">+</span> <span class="str">"&amp;field2="</span> <span class="pun">+</span><span class="pln"> str</span><span class="pun">(</span><span class="pln">current</span><span class="pun">)</span> <span class="com"># attempt to publish this data to the topic.</span> <span class="kwd">try</span><span class="pun">:</span><span class="pln"> publish</span><span class="pun">.</span><span class="pln">single</span><span class="pun">(</span><span class="pln">topic</span><span class="pun">,</span><span class="pln"> payload</span><span class="pun">,</span><span class="pln"> hostname</span><span class="pun">=</span><span class="pln">mqttHost</span><span class="pun">,</span><span class="pln"> transport</span><span class="pun">=</span><span class="pln">tTransport</span><span class="pun">,</span><span class="pln"> port</span><span class="pun">=</span><span class="pln">tPort</span><span class="pun">,</span><span class="pln">auth</span><span class="pun">={</span><span class="str">'username'</span><span class="pun">:</span><span class="pln">mqttUsername</span><span class="pun">,</span><span class="str">'password'</span><span class="pun">:</span><span class="pln">mqttAPIKey</span><span class="pun">})</span> <span class="kwd">print</span> <span class="pun">(</span><span class="str">" Published temp ="</span><span class="pun">,</span><span class="pln">temp</span><span class="pun">,</span><span class="str">" current ="</span><span class="pun">,</span><span class="pln"> current</span><span class="pun">,</span><span class="str">" to host: "</span> <span class="pun">,</span><span class="pln"> mqttHost </span><span class="pun">,</span> <span class="str">" clientID= "</span> <span class="pun">,</span><span class="pln"> clientID</span><span class="pun">)</span> <span class="kwd">except</span> <span class="pun">(</span><span class="typ">KeyboardInterrupt</span><span class="pun">):</span> <span class="kwd">break</span> <span class="kwd">except</span><span class="pun">:</span> <span class="kwd">print</span> <span class="pun">(</span><span class="str">"There was an error while publishing the data."</span><span class="pun">)</span><span class="pln"> time</span><span class="pun">.</span><span class="pln">sleep</span><span class="pun">(</span><span class="lit">15</span><span class="pun">)</span>
Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
38 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

KeslarAboth, EnigmBioge, debbiepe18, MatthewmUb, cathrynww1, Slark

Administrators: Hans: 387, lee: 457