[SOLVED] Ubidots MQTT with multiple variables

Dear all,

I am trying to use the particle ubidotsMQTT library as described in here:
https://ubidots.com/docs/devices/particleMQTT.html#subscribe-to-a-variable
but I need to subscribe to several variables from the same ubidots device.
The example in the link shows the subscription to one variable only.
Could you please help me out here?

Thanks a lot!

Matt

Hello @Mabruna ,

As you can see in the subscribe example code there is a callback; the callback is the function that processes the incoming data when there is any change on your variables. At this video you can see how the callback is modified to parse if the value received is ‘1’ or ‘0’ in the routine to make an action based on that value.

If you wan to monitor more than one variable, just call the subscribe() function again, here is an example to multiple calls to the subscribe() function: http://blog.ubidots.com/digital-piano-with-ubidots-and-nodemcu16, in the example are declared multiple clients but you can subscribe to different topics with only one client too. You should parse the message string in the callback too for knowing what variable changed.

Regards,
Maria C.

the last link you mentioned above doesn’t exist any more please I need it .It will help me

Greetings, you can reference the tutorial for the piano here: https://help.ubidots.com/iot-projects-tutorials/create-a-digital-piano-with-ubidots-and-a-nodemcu

All the best