MQTT: publish several values for same field at once | ThingSpeak API | 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
MQTT: publish several values for same field at once
No permission to create posts
May 16, 2018
11:08 am
Avatar
borjah
New Member
Members
Forum Posts: 1
Member Since:
May 16, 2018
sp_UserOfflineSmall Offline

Dear all,

I want to publish through MQTT several values to the same channel's field using different timestamps
I'm using different single messages to do that, but it's not working. Is there any restriction in the ThingSpeak MQTT broker of time between 2 consecutives messages?

Please find below a example Python's snippet trying to upload the same value to several fields several times with a delay of 1 second in the timestamps

Thanks a lot in advanced
======================================================
import paho.mqtt.client as mqtt
import time

MQTT_BROKER ="mqtt.thingspeak.com"
MQTT_PORT =1883

messages = []
data="-1000"

messages.append({'topic':"channels//publish/fields/field1/", 'payload': "&field1="+data+"&created_at=2018-5-16T16:48:21&status=MQTTPUBLISH"})
messages.append({'topic':"channels//publish/fields/field1/", 'payload': "&field1="+data+"&created_at=2018-5-16T16:49:21&status=MQTTPUBLISH"})
messages.append({'topic':"channels//publish/fields/field2/", 'payload': "&field2="+data+"&created_at=2018-5-16T16:48:21&status=MQTTPUBLISH"})
messages.append({'topic':"channels//publish/fields/field2/", 'payload': "&field2="+data+"&created_at=2018-5-16T16:49:21&status=MQTTPUBLISH"})
messages.append({'topic':"channels//publish/fields/field3/", 'payload': "&field3="+data+"&created_at=2018-5-16T16:48:21&status=MQTTPUBLISH"})
messages.append({'topic':"channels//publish/fields/field3/", 'payload': "&field3="+data+"&created_at=2018-5-16T16:49:21&status=MQTTPUBLISH"})
messages.append({'topic':"channels//publish/fields/field4/", 'payload': "&field4="+data+"&created_at=2018-5-16T16:48:21&status=MQTTPUBLISH"})
messages.append({'topic':"channels//publish/fields/field4/", 'payload': "&field4="+data+"&created_at=2018-5-16T16:49:21&status=MQTTPUBLISH"})
messages.append({'topic':"channels//publish/fields/field1/", 'payload': "&field1="+data+"&created_at=2018-5-16T16:48:21&status=MQTTPUBLISH"})
messages.append({'topic':"channels//publish/fields/field1/", 'payload': "&field1="+data+"&created_at=2018-5-16T16:49:21&status=MQTTPUBLISH"})
messages.append({'topic':"channels//publish/fields/field2/", 'payload': "&field2="+data+"&created_at=2018-5-16T16:48:21&status=MQTTPUBLISH"})
messages.append({'topic':"channels//publish/fields/field2/", 'payload': "&field2="+data+"&created_at=2018-5-16T16:49:21&status=MQTTPUBLISH"})

client = mqtt.Client()
client.connect(MQTT_BROKER, MQTT_PORT)
client.loop_start()

for i in range(0,len(messages)):
out=client.publish(topic=messages[i]['topic'], payload=messages[i]['payload'])
while(out.is_published()is False):
time.sleep(0.05)

client.loop_stop()
client.disconnect()

May 17, 2018
8:37 am
Avatar
rw950431

Top
Members
Forum Posts: 271
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

I'm guessing that the 15 second update limit applies to MQTT as well as HTML updates. The mods may be able to confirm.

The syntax you are using to publish an individual field doesnt appear correct according to https://au.mathworks.com/help/thingspeak/publishtoachannelfieldfeed.html

You would be better off grouping your updates and writing them as multiple fields to a channel rather than individual fields. See some python code at https://community.thingspeak.com/tutorials/update-a-thingspeak-channel-using-mqtt-on-a-raspberry-pi/ and the docs at https://au.mathworks.com/help/thingspeak/publishtoachannelfeed.html

May 17, 2018
11:12 am
Avatar
Vinod

MathWorks
Members
Forum Posts: 223
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

Irrespective of the API used (REST or MQTT) to ingest the data to ThingSpeak, the maximum accepted rate of data is one data point per second per channel for users with a paid standard, academic, home or student license. Users with a free license can can send data at up to one data point every 15 seconds per channel.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
34 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:

Georgesic, BalladolbineAboth, Wayneamure, MattonAboth, ginatm2, Spreeuw

Administrators: Hans: 387, lee: 457