[SOLVED] Only update first data then freeze

Hello,

I am trying to send data using Mqtt to Ubidots server (30 day trial).
I folowed the steps suggested in the portal for a simple publish example.

But the dashboard only updates once … and after a few samples MQTT connection fails.

Heres is the serial monitor output:

Eventually reconects, but dashboard never updates again.

I also tried a simple example with HTTP with the same result.

Here is the code …

#include "UbidotsESPMQTT.h"

#define TOKEN "here is my token" // Your Ubidots TOKEN
#define WIFINAME "CLAROMEP2" //Your SSID
#define WIFIPASS "55134488" // Your Wifi Pass

Ubidots client(TOKEN);

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();
      }
  
  float temp = random(0, 9) * 10;
  float hum = random(0, 9) * 10;
  
  client.add("temperatura", temp); //Insert your variable Labels and the value to be sent
  client.ubidotsPublish("Secadero_1");
  client.add("humedad", hum);
  client.ubidotsPublish("Secadero_1");
  client.loop();
  }

Please let me know how to troubleshoot/analyze this issue.

Best Regards,
Patricio Lllovera

Hi there, from the official PubSubclient library docs, which is the core of the Ubidots library, a return code equals to -2 means a network error once the device attempts to connect to the cloud. If you are getting also issues through HTTP, my suspicion is that the issue is at your LAN side or your hardware rather than at the Ubidots side.

To clear doubts, I have run a test at my side and everything works properly:

Please try with another board or another network and make sure to download the latest library version.

All the best