[SOLVED] Possible number of variables and sources to publish using MQTT


#1

Hi,

I wanted to be sure about many sources and variables that can be published to ubidots using an MQTT connection from one microcontroller such as a NodeMCU or Wemos D1?

The reason why I’m asking is that my captured data values won’t be published to ubidots if I add more than the 3 sources. Moreover, no more than 3 variables in each source can be published.

Can anyone recognise this situation? is it something to do with my present subscribtion to ubidots?

Regards

PS: the following code was my starting point and modified it (of course) according to my particular experiment:


include “UbidotsESPMQTT.h”

define TOKEN “…” // Your Ubidots TOKEN
define WIFINAME “…” //Your SSID
define WIFIPASS “…” // Your Wifi Pass
define MQTTCLIENTNAME “…” // Your MQTT Client Name, it must be unique so we recommend to choose a random ASCCI name

Ubidots client(TOKEN, MQTTCLIENTNAME);

void callback(char* topic, byte* payload, unsigned int length) {
Serial.print(“Message arrived [”);
Serial.print(topic);
Serial.print("] ");
for (int i=0;i<length;i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
client.setDebug(true); // Pass a true or false bool value to activate debug messages
client.wifiConnection(WIFINAME, WIFIPASS);
client.begin(callback);
}

void loop() {
// put your main code here, to run repeatedly:
if(!client.connected()){
client.reconnect();
}

// Publish values to 2 different data sources

client.add(“stuff”, 10.2); //Insert your variable Labels and the value to be sent
client.ubidotsPublish(“source1”);
client.add(“stuff”, 10.2);
client.add(“more-stuff”, 120.2);
client.ubidotsPublish(“source2”);
client.loop();
}


#2

Hello @su1993,

I’ve reproduced the issue when trying to publish more than four variables and the problems comes from the max packet size defined by default in the PubSubclient library, to publish many variables simply define at PubSubClient.h the MQTT_MAX_PACKET_SIZE to 512 and you will fix the issue. I will release a new update to treat with this, thanks for the report.

Regards


#3

Hola tengo el mismo problema pero con la biblioteca Paho para Android no puedo realizar más de 2 publicaciones.