0

Getting initial values from adafruit.io via MQTT
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Getting initial values from adafruit.io via MQTT

by 0707070 on Sat Jan 23, 2016 12:45 pm

I have set up a color picker on adafruit.io widget which I use to set the color on NeoPixels connected to a ESP8266, which is communicating to adafruit.io using the Adafruit MQTT library. This is running fine, however after rebooting I need to change the value on the color wheel so that a new message gets sent to the ESP8266. Since adafruit.io seems to "remember" the last set color, I wonder whether there is a way using MQTT to get the "initial value" of each feed immediately after booting the ESP8266.

In other words, the ESP8266 should not have to wait until a feed is updated; instead it should ask adafruit.io "give me the last value of feed x".

Can this be done, and if so, how?

0707070
 
Posts: 3
Joined: Sat Jan 16, 2016 6:10 pm

Re: Getting initial values from adafruit.io via MQTT

by jwcooper on Sat Jan 23, 2016 12:49 pm

I believe this should be the default scenario. You should get an initial value as you subscribe to a feed. We store the last values sent (once you have sent an initial value, of course) so that you should immediately receive that value.

jwcooper
 
Posts: 666
Joined: Tue May 01, 2012 9:08 pm

Re: Getting initial values from adafruit.io via MQTT

by 0707070 on Sat Jan 23, 2016 1:35 pm

This is the relevant code I am using, it seems not to be doing that:

Code: Select all | TOGGLE FULL SIZE
  Adafruit_MQTT_Subscribe *subscription;
  while ((subscription = mqtt.readSubscription(5000))) {
    if (subscription == &color) {
      setColor((char *)color.lastread);
    }
  }

Full sketch here: https://github.com/probonopd/sketches/b ... ls-ota.ino

0707070
 
Posts: 3
Joined: Sat Jan 16, 2016 6:10 pm

Re: Getting initial values from adafruit.io via MQTT

by Mr_Paul on Sun Jan 24, 2016 3:03 pm

The retain bit in MQTT is exactly for this, and it should be honoured. Some information is only valid when it is sent (for example, motion sensing). Other information is ok if it is stale; the usage of the retain bit allows the publishing sensor to determine the nature of the data, and if it is ok send to new publishers.

Mr_Paul
 
Posts: 24
Joined: Mon Dec 10, 2012 11:58 am

Re: Getting initial values from adafruit.io via MQTT

by 0707070 on Tue Jan 26, 2016 3:38 am

If I understand it correctly, the retain bit is set by the sender of a message. E.g., if I am using a color picker on Adafrit.io to set the color of some LEDs it would be nice if I could set that color picker widget to send the retain bit with every message it emits, whereas when some event (e.g., "bus is coming") sets the color to a different value temporarily it should not be retained. Fpr that, sending messages e.g., with the Adafruit.io Arduino library should allow to selectively set the retain bit.

0707070
 
Posts: 3
Joined: Sat Jan 16, 2016 6:10 pm

Re: Getting initial values from adafruit.io via MQTT

by Rooneybuk on Sat Apr 02, 2016 11:39 am

Hi,

I have the same problem, i have followed a guide below which turns a lamp on and off using the Adafruit IO MQTT Dash, but the issue is if the lamp is rebooted it doesent not read the retained subscription status so the Dash Swicth says ON but the Lamp is OFF.

did you find a solution?

Guide
https://learn.adafruit.com/home-automat ... o?view=all

Sketch
https://github.com/openhomeautomation/a ... module.ino

Rooneybuk
 
Posts: 2
Joined: Sat Apr 02, 2016 11:27 am

Re: Getting initial values from adafruit.io via MQTT

by todd1988 on Sun Apr 10, 2016 11:59 pm

I am having the same problem. I am not getting an initial value.

Did anyone find a solution.

Thanks,
Todd

todd1988
 
Posts: 3
Joined: Thu Aug 08, 2013 8:37 am

Re: Getting initial values from adafruit.io via MQTT

by Rooneybuk on Mon Apr 11, 2016 2:39 am

Hi

I've not managed to workout a solution to this either.

Regards

Rooneybuk
 
Posts: 2
Joined: Sat Apr 02, 2016 11:27 am

Re: Getting initial values from adafruit.io via MQTT

by chillypenguin on Mon Apr 11, 2016 3:16 pm

OK, this forum is spooky. Every time I think of posting a questions, someone else asks the same question!

I wanted to set the measurement interval on a temp/humility monitor on a HUZZAH. But could not find any way of updating on reboot automatically.

Reading this thread with interest.

chillypenguin
 
Posts: 8
Joined: Fri Apr 01, 2016 7:02 am

Re: Getting initial values from adafruit.io via MQTT

by dutchfarmer on Mon Apr 11, 2016 3:52 pm

hi chillypenguin,

while slightly off topic from this thread, the second part of your question seems to be more about minimizing power consumption by putting the esp into sleep mode. take a look at the video at https://youtu.be/6SdyImetbp8. i used this method for a device in my greenhouse with a dht-22 and a soil moisture sensor. it wakes up every 30 min and publishes values then falls back to sleep. works great...

D-

dutchfarmer
 
Posts: 8
Joined: Mon Apr 11, 2016 3:25 pm

Re: Getting initial values from adafruit.io via MQTT

by viscons on Fri May 06, 2016 11:07 pm

Has anyone found a way to request the current state of a feed? If I understand correctly, the retain flag is set by default, but I haven't seen any code that queries the current value upon subscription. If anyone has done this please post the code.
Like Rooneybuk I need to know if the Dash Switch is ON or OFF upon subscription. Thank you.

viscons
 
Posts: 2
Joined: Mon Jan 25, 2016 4:19 pm

Re: Getting initial values from adafruit.io via MQTT

by fabfsi on Thu Jul 21, 2016 1:52 pm

Any update on this?

fabfsi
 
Posts: 1
Joined: Fri Jul 08, 2016 9:38 am

Re: Getting initial values from adafruit.io via MQTT

by geekguy on Thu Jul 21, 2016 11:48 pm

jwcooper wrote:I believe this should be the default scenario. You should get an initial value as you subscribe to a feed

OK, so as soon as I do:
Code: Select all | TOGGLE FULL SIZE
  // Subscribe to feeds
  mqtt.subscribe(&bedroomsw);
  mqtt.subscribe(&updateinterval);
I should be able to pick up the current value of each feed. Is that correct?

8-Dale

geekguy
 
Posts: 170
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Re: Getting initial values from adafruit.io via MQTT

by adafruit2 on Mon Jul 25, 2016 4:18 pm

yes - ish
its not officially guaranteed, two feeds might conflict so you may only get one. no eta on a fix.

adafruit2
Site Admin
 
Posts: 18047
Joined: Fri Mar 11, 2005 7:36 pm

Re: Getting initial values from adafruit.io via MQTT

by lst on Wed Sep 07, 2016 6:48 pm

Any progress on this? I am also desiring to read the state of a subscribe feed after a reboot even if the value has not changed. Using the mqtt_winc1500 example reacts nicely to changing the state of the onoff feed on io.adafruit.com; however, if the device is rebooted, it is unable to retrieve the last known state until the feed state is changed.

lst
 
Posts: 1
Joined: Tue Sep 06, 2016 3:28 pm

Please be positive and constructive with your questions and comments.