0

Read current value of feed
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Read current value of feed

by rickseiden on Fri Jan 12, 2018 7:19 pm

This seems to be a common question, but I can't find the answer to it.

I have a feed that I send data to on two different ESP8266 boards. The data sent should depend on the current value of the feed. For example, the value of the feed could be "NONE", "ONE", "TWO", "BOTH". If the first board has a button pushed, it needs to read the value of the feed. If the feed has a value of "NONE", it should send "ONE". If the feed has a value of "ONE", it should send "NONE". If the feed has a value of "TWO", it should send "BOTH". And if the feed has a value of "BOTH" it should send "TWO".

The second board functions almost exactly the same way, but switching "ONE" and "TWO".

The problem is that I can't find a way to read the current value. Note that I don't want to get the value when it changes. I want to get the current value as it exists right this second. The reason for this is that I don't get the initial value of the feed when I subscribe to it, so I have no way of knowing the state of the feed until it's changed. How can I read the current state of a feed?

I'm trying to do this using either the AdafruitIO library or the AdafruitMQTT library.

I have searched the forums for "read" and "initial" but haven't come up with an answer.

As a followup question, is there a place where these libraries are documented outside of the examples?

Thanks

rickseiden
 
Posts: 25
Joined: Thu Oct 06, 2016 2:48 pm

Re: Read current value of feed

by dv19023 on Mon Jan 15, 2018 7:56 am

Same problem here.

I already implemented tried extending the adafruit libaries to allow publishing retained messages (as described in: https://www.bakke.online/index.php/2017 ... t-library/).

Nevertheless, I cannot seem to get it to work (tried with MQTT dash app, MQTT dashboard app and MQTT spy). The last value is not shown untill a new value is published.

dv19023
 
Posts: 1
Joined: Thu Jan 04, 2018 5:22 pm

Re: Read current value of feed

by jwcooper on Mon Jan 15, 2018 11:34 am

We have a pull request with the last/current value that hasn't been merged to master yet in our io client library. You can find it here: https://github.com/adafruit/Adafruit_IO_Arduino/pull/18

lastValue method is here: https://github.com/adafruit/Adafruit_IO ... ee20ecR146

Retained message support is not currently enabled in our mqtt broker at this time.

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

Please be positive and constructive with your questions and comments.