Tengo un ESP32 conectado a Ubidots a través de protocolo Mqtt. La información que envío desde mi esp32, se muestra perefectamente en el dashboard (widget) de Ubidots, pero cuando intento recibir el estado de un -swich em mi módulo esp32, este valor nunca llega, la función callback, nunca se ejecuta. Gracias por su atención
/****************************************
* Include Libraries
****************************************/
#include "UbidotsEsp32Mqtt.h"
/****************************************
* Define Constants
****************************************/
const char* UBIDOTS_TOKEN = "**********"; // Put here your Ubidots TOKEN
const char* WIFI_SSID = "OSPINA"; // Put here your Wi-Fi SSID
const char* WIFI_PASS = "*****"; // Put here your Wi-Fi password
const char *PUBLISH_DEVICE_LABEL = "esp32"; // Put here your Device label to which data will be published
const char *PUBLISH_VARIABLE_LABEL = "Temperatura"; // Put here your Variable label to which data will be published
const char *SUBSCRIBE_DEVICE_LABEL = "esp32"; // Replace with the device label to subscribe to
const char *SUBSCRIBE_VARIABLE_LABEL = "Led"; // Replace with the variable label to subscribe to
const int PUBLISH_FREQUENCY = 5000; // Update rate in millisecondsx
unsigned long timer;
uint8_t analogPin = 34; // Pin used to read data from GPIO34 ADC_CH6.
Ubidots ubidots(UBIDOTS_TOKEN);
/****************************************
* 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(115200);
// ubidots.setDebug(true); // uncomment this to make debug messages available
ubidots.connectToWifi(WIFI_SSID, WIFI_PASS);
ubidots.setCallback(callback);
ubidots.setup();
ubidots.reconnect();
ubidots.subscribeLastValue(SUBSCRIBE_DEVICE_LABEL, SUBSCRIBE_VARIABLE_LABEL); // Insert the device and variable's Labels, respectively
timer = millis();
}
void loop()
{
// put your main code here, to run repeatedly:
if (!ubidots.connected())
{
Serial.print("No conexion");
ubidots.reconnect();
ubidots.subscribeLastValue(SUBSCRIBE_DEVICE_LABEL, SUBSCRIBE_VARIABLE_LABEL); // Insert the device and variable's Labels, respectively
}
if (millis() - timer > PUBLISH_FREQUENCY) // triggers the routine every 5 seconds
{
float value = analogRead(analogPin);
ubidots.add(PUBLISH_VARIABLE_LABEL, value); // Insert your variable Labels and the value to be sent
ubidots.publish(PUBLISH_DEVICE_LABEL);
Serial.print("Analog= ");
Serial.println(value);
timer = millis();
}
ubidots.loop();
}