Ubidots Community

Code failure when sending MQTT Ubidots Package

Hello friends, how are you? I need help with the following item: When sending temperature data to Ubidots, a crash occurs in the code, using either arduino ide classic or arduino 2.0. The same code works normally using the arduino WEB.
Comments:
1- I have already replaced all the libraries and all are with their original versions.
2- Why the arduino web works and the arduino IDE classic and 2.0 don’t if the code and libraries are the same?
3- When I use only the temperature reading part in the code, the code and device work normally, but when I insert the publication for the ubidots, the code presents the failure described below.

��…WiFi connected

IP address:

192.168.1.172

entra
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (0):

epc1=0x40201639 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

stack>>>

THE CODE:

/****************************************

  Include Libraries

****************************************/

#include "UbidotsESPMQTT.h"

#include <OneWire.h>

#include <DallasTemperature.h>

/****************************************

  Define Constants and Instances

****************************************/

#define TOKEN "XXX" // Your Ubidots TOKEN

#define WIFINAME "XXX" // Your SSID

#define WIFIPASS "XXX" // Your Wifi Pass

#define MQTTCLIENTNAME "XXX" // Your MQTT Client Name, it must be unique so we recommend to choose a random ASCCI name

#define Pin D3

int temp;

OneWire ourWire(Pin);

DallasTemperature sensors(&ourWire);

Ubidots client(TOKEN, MQTTCLIENTNAME);

/****************************************

  Auxiliar Functions

****************************************/

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();

}

/****************************************

  Main Functions

****************************************/

void setup() {

  // put your setup code here, to run once:

  Serial.begin(9600);

  client.wifiConnection(WIFINAME, WIFIPASS);

  sensors.begin();

  client.begin(callback);

}

void loop() {

  // put your main code here, to run repeatedly:

  if (!client.connected()) {

    client.reconnect();

  }

  sensors.requestTemperatures();

  //Prepare the sensor for reading

  temp = sensors.getTempCByIndex(0);

  Serial.print(sensors.getTempCByIndex(0));

  //Read and print the temperature in Celsius

  client.add("temperature", temp);

  //Insert your variable Labels and the value to be sent

  delay(1000);

  Serial.println("_Celcius");

  client.ubidotsPublish("XXX");

  delay(3000);

  client.loop();

}

Hello @CAEGRUBR ,

Thank you for your message.

I recently tested the MQTT library that you’re using in an ESP8266 with the classic Arduino IDE and everything was working as expected. Are you presenting the same problem with another MQTT library for the ESP8266? Because as I can see, the problem could be related to that library due to you were able to connect to your WiFi network.

I’ll be attentive to your comments.

Best Regards,

– Leonardo