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.
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:
I am able to subscribe and receive data from Ubidots for single topic. However if I subscribe two topics to a single client, only last subscription is valid. No data is received from first subscription. Here is the code:
You need to clean the topicSubscribe variables before the second variable to subscribe, or have a separate variable for the second topic. Either way, here are the 2 examples:
Cleaning the topicSubscribe variable before the second subscription:
Having a second variable for the second topic to subscribe: note that in the second subscription I didn’t recycle the topicSubscribe but instead used topicSubscribe2. Remember to declare topicSubscribe2
hellon @Casey, I have the same problem, I already tried the second example but the data is still shown in the same variable, could you show me your code. I hope you can help me.
David’s response had a subtle mistake, and the second subscribe client was assigning its value to the same variable as the first, which explains what was happening to you.
He has corrected the mistake and now the second subscribe outputs its value to the second declared value. Makes sense?