0

Read toggle state on-demand or at start up?
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Read toggle state on-demand or at start up?

by JMJunek on Sun Nov 29, 2020 4:01 pm

I've noticed that upon start up, my device (Huzzah esp8266) doesn't know the initial state of a toggle on AIO. I've been using digital->onMessage(handleMessage); and handleMessage(AdafruitIO_Data *data) but that method obviously only runs when an event on AIO (like a toggle state change) happens. So I have to hit all the toggles after startup to get everything synched, and then it's all working fine from then on. It's there a way to read the state of a toggle on-demand, that I could run at start up?

JMJunek
 
Posts: 16
Joined: Sat May 11, 2019 5:37 pm

Re: Read toggle state on-demand or at start up?

by brubell on Mon Nov 30, 2020 11:27 am

It's there a way to read the state of a toggle on-demand, that I could run at start up?

Yep! You could use the */get topic (https://io.adafruit.com/api/docs/mqtt.h ... -get-topic).

It seems like you're using the Adafruit IO Arduino library - check out an example of using this topic here: https://github.com/adafruit/Adafruit_IO ... d_read.ino

brubell
 
Posts: 1383
Joined: Fri Jul 17, 2015 10:33 pm

Re: Read toggle state on-demand or at start up?

by JMJunek on Sun Dec 06, 2020 2:38 pm

Nice! that worked perfectly! Thanks Brent!!

JMJunek
 
Posts: 16
Joined: Sat May 11, 2019 5:37 pm

Please be positive and constructive with your questions and comments.