Thingspeak MQTT | 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
Thingspeak MQTT
No permission to create posts
May 7, 2018
4:01 am
Avatar
Vignesh maker

Silver
Members
Forum Posts: 11
Member Since:
January 25, 2018
sp_UserOfflineSmall Offline

Thingspeak mqtt was working fine. But since this morniing I am losing my mqtt connection if I attempt to subscribe to a topic. I used both arduino and mqttfx for checking. I used codes which were working last evening. I cross checked all the credentials
Anyone please help

May 7, 2018
6:40 am
Avatar
Vinod

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

I suspect you have more than 3 concurrent connections to the MQTT server. As a free user you are only allowed 3 concurrent connections. You may need to purchase a license to get access to more concurrent MQTT subscriptions.

June 6, 2018
9:10 am
Avatar
karelt

Silver
Members
Forum Posts: 5
Member Since:
June 6, 2018
sp_UserOfflineSmall Offline

Hi, please I have question because there is not clear info. If I would like to publish MQTT message with update for all 8 fields in one Chanell there I need purchase license? I thing there is only one connection with one publish. Is possible to see mqtt broker log somewhere?
Example I have 4 DHT11 ssenzors on WemosD1 ESP8266 and this kind of publish. Please what now? Publish separately one or two fields at once and between use more than 15 second (two fields at once working well but three only sometimes more fields not) or I have some mistake and update all fields in one chanell is possible?

void mqttpublish() {

float t1 = dht11_1.readTemperature(); // Read temperature from DHT sensor.
float h1 = dht11_1.readHumidity(); // Read humidity from DHT sensor.
float t2 = dht11_2.readTemperature();
float h2 = dht11_2.readHumidity();
float t3 = dht11_3.readTemperature();
float h3 = dht11_3.readHumidity();
float t4 = dht11_4.readTemperature();
float h4 = dht11_4.readHumidity();

// Create data string to send to ThingSpeak
String data = String("field1=" + String(t1, DEC)+ "&field2=" + String(h1, DEC)+ "&field2=" + String(t2, DEC)+ "&field3=" + String(h2, DEC)+ "&field5=" + String(t3, DEC)+ "&field6=" + String(h3, DEC)+ "&field7=" + String(t4, DEC)+ "&field8=" + String(h4, DEC));
int length = data.length();
char msgBuffer[length];
data.toCharArray(msgBuffer,length+1);
Serial.println(msgBuffer);

// Create a topic string and publish data to ThingSpeak channel feed.
String topicString ="channels/" + String( channelID ) + "/publish/"+String(writeAPIKey);
length=topicString.length();
char topicBuffer[length];
topicString.toCharArray(topicBuffer,length+1);
// Tady odesila
mqttClient.publish( topicBuffer, msgBuffer );
lastConnectionTime = millis();

June 6, 2018
1:52 pm
Avatar
JasonW

MathWorks
Members
Forum Posts: 31
Member Since:
October 21, 2016
sp_UserOfflineSmall Offline

A license is not needed to publish to a channel using MQTT. However without a license there are limits on how many updates (< 8200 per day) and how often updates (once every 15 seconds) are sent. This page has some more information about the license: https://thingspeak.com/prices/thingspeak_standard

You should be able to publish all eight fields at once through MQTT. I think there is a problem in your code.
Regarding the msgBuffer[] and topicBuffer[] variables, I think you need to set the size of the char array at compile time, not at runtime.

Try setting the size to a high, worst case number to see if that makes a difference. For example:
char msgBuffer[200];

Currently, there is no way to see broker logs. But that is something we want to add eventually.

June 8, 2018
5:05 am
Avatar
karelt

Silver
Members
Forum Posts: 5
Member Since:
June 6, 2018
sp_UserOfflineSmall Offline

Hi JasonW,
thanks for your information broker log would be grate.
I tryed your advice but still does not work. When I try to send only two fields it is working but more not. There is not information about chanell stat last update. Seems like that message stop somewhere on the way. Can you please help me with some example of working code? Thx Karel

June 8, 2018
11:21 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 365
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

There are often very small limits on the buffer size for MQTT strings. Consider looking in the MQTT library for a size limit.

June 11, 2018
5:03 am
Avatar
karelt

Silver
Members
Forum Posts: 5
Member Since:
June 6, 2018
sp_UserOfflineSmall Offline

Hi, thanks for reply. I am not sure but I thing my message is something around 320B and I found that default MQTT_MAX_PACKET_SIZE is 128KB. So that is so faar bigger than my message. Where should be problem?

June 11, 2018
7:36 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 365
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Are you sure about the kb? That would be a very large MQTT packet. Perhaps try setting it to 400, just in case?

June 12, 2018
2:01 am
Avatar
karelt

Silver
Members
Forum Posts: 5
Member Since:
June 6, 2018
sp_UserOfflineSmall Offline

I amnot sure that is the reason why I am asking 🙁

June 12, 2018
8:13 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 365
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

The total RAM on on a Wemos D1 is 96 kb Data, 64 kb instruction. There is more in flash storage, but I don't think they would use flash for a data buffer. So I am pretty sure that number is bytes. Set it higher and see what happens. I recommend 512 or 1024.

June 14, 2018
4:54 am
Avatar
karelt

Silver
Members
Forum Posts: 5
Member Since:
June 6, 2018
sp_UserOfflineSmall Offline

So now seems that 1024 working (512does not) so thank you 😉 One more thing for ask is possible to send as payload JSON? Or in this case we do not have way hot to parse JSON to each channel or fields on thinspeak side?
By the way I change that example code for mqttpublish because I do not like that process to char array....
void mqttpublish() {

float t1 = dht11_1.readTemperature(); // Read temperature from DHT sensor.
float h1 = dht11_1.readHumidity(); // Read humidity from DHT sensor.
float t2 = dht11_2.readTemperature();
float h2 = dht11_2.readHumidity();
float t3 = dht11_3.readTemperature();
float h3 = dht11_3.readHumidity();
float t4 = dht11_4.readTemperature();
float h4 = dht11_4.readHumidity();

// Create data string to send to ThingSpeak
String data = ("field1=" + String(t1,0)+
"&field2=" + String(h1,0)+
"&field3=" + String(t2,0)+
"&field4=" + String(h2,0)+
"&field5=" + String(t3,0)+
"&field6=" + String(h3,0)+
"&field7=" + String(t4,0)+
"&field8=" + String(h4,0));
Serial.println(data);
String topicString ="channels/" + String( channelID ) + "/publish/"+String(writeAPIKey);
Serial.println(topicString);
mqttClient.publish(topicString.c_str(), data.c_str());
lastConnectionTime = millis();

June 18, 2018
6:24 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 365
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Thanks for the code suggestion! I will keep it in mind for the next revision.

The MQTT broker does not presently parse JSON, although you can send JSON formatted information through the REST API, using the Write Data endpoint.
https://www.mathworks.com/help/thingspeak/writedata.html

For example:

POST https://api.thingspeak.com/update.json HTTP/1.1
Content-Type: application/x-www-form-urlencoded
{
"write_api_key": "xxx"
{
"created_at": "2018-04-23 21:36:20 +0200",
"field1": "John Johnson",
"field3": 56,
"field4": 555,
"field5": 444,
"latitude": "",
"longitude": "",
"status": "Please check in!"
}
}

Forum Timezone: America/New_York

Most Users Ever Online: 114

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

JudestAboth, concettazx4, lyndarf60, caseybo16, iodiree, emiliacz4

Administrators: Hans: 387, lee: 457