[SOLVED] mqtt - how to get the last value of a variable when first connect?


#1

How can I get the last value of a variable when my device connects to Ubidots at the first time? I want to synchronize my device to the status on Ubidots.

For example:

  1. I turn off my bulb.
  2. Disconnect from Ubidots.
  3. Turn on the button (which can control the variable represent for the bulb) on Ubidots.
  4. Connect the bulb to Ubidots. Now I want my bulb turn on automatically.

Can you help me?
Thank you in advance!
Regard.


#2

Hello @nghick001,

Regrettably under the Educational License the last retained feature is not available, so you are just going to be able to receive the status of the button once the status change and the device is already connected.

If you desire you can take a Free Trial of Ubidots for Business to start tinkering with your IoT project and know all the features it can offers you :wink:

All the best,
Maria C.


#3

Hi there @nghick001 , you may make a GET request inside your setup() function using HTTP instead of MQTT to know the initial value of your variable, and then just subscribe to the variable inside your main loop() using MQTT.

Unfortunately, retained values is available only for business licensed users.

Regards


#4

Thank you! I will try it later.


#5

Yeah thank you! Good idea!