Ubidots Community

ESP32 Subscribing via MQTT

Hi,

I am trying to subscribe to a variable on my ubidots device which is controlled by a slider that ranges from 0 to 100. I am currently using the ESP32 development board and the following libraries: WiFi.h and PubSubClient.h .

So far I have only been able to publish four variables to my ubidots device but I have not had any luck subscribing. I have had a good look at the examples in the ubidots API and other examples as well but nobody really explains in detail how it all works. The closest thing I found was an example that allowed the user to control a relay but this has not helped me understand the subscribe procedure either.

Does anyone have any SIMPLE bare bones example that subscribes to a variable on ubidots and prints its value to the serial monitor?? If I have that, I would be able to take it from there.

Thank you for you help

Hi @Masso_RainCloud,

Please refer to section 4 of the below article. It addresses subscription to Ubidots from an ESP32, and it is proven to work.

Furthermore, if you want to simply subscribe to a variable on Ubidots and print its value to the serial monitor, use the following callback function instead of that in the article:

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

–David