0

lastread function not working as expected
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.

Re: lastread function not working as expected

by brubell on Wed Apr 21, 2021 11:40 am

gwiot wrote:Aside from looking for an equivalent function in the library, could you give more details about the "pump"/"loop" after publishing a /get? Is this a special feed_key and data pair? Does it need to be published? Is it a different type of MQTT action, or a lower-level feed issue? As I wrote on March 8, 2021, I have tried several variations to try to make this work, and I am not using the published libraries.


This isn't a special feed/data pair, but you do need to be using an MQTT client which can process messages from the broker.

After you publish a message to a feed's /get subtopic, the broker publishes the most recent value to that feed. To receive this message back across the feed, the same client which published needs to process messages FROM the broker.


For example, the paho mqtt client exposes a `loop` function: http://www.steves-internet-guide.com/lo ... tt-client/

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

Re: lastread function not working as expected

by LagomBra on Fri Apr 23, 2021 3:28 pm

There's a great tutorial on how to add retained message functionality to the library with very little code https://www.bakke.online/index.php/2017 ... t-library/

LagomBra
 
Posts: 8
Joined: Mon May 11, 2020 4:37 pm

Re: lastread function not working as expected

by gwiot on Sun Apr 25, 2021 10:08 am

For brubell: Thank you for providing more details on the "Loop" action. In my case, using my own client software, I can see all bytes received on the TCP connection. Therefore I do not have a problem with receiving messages from the buffer. My publish and subscribe work, but I get no data on the connection in response to publishing the /get (except for PUBACK if QoS = 1).

The /get seems to be ignored. If I simply press Enter in the data field on the web platform, my client receives a Publish message with the current value. However, the /get message does not trigger a similar response by the broker.

For Ashaman483: Could you please confirm that the /get feature works with your ESP8266 code? I am also using my own ESP8266 software. Did you have any trouble publishing the /get and receiving a response in your software?

For LagomBra: As jwcooper indicated earlier in this thread, the Retain functionality is not supported by Adafruit IO (see https://io.adafruit.com/api/docs/mqtt.h ... ned-values). Perhaps it is supported by the broker used in the tutorial you referenced. I would like to enter a value on the Adafruit IO web platform, and be able to read the latest value from a device that connects later. I do not know, or can't control, the state of the Retain flag when a message is posted from the IO platform.

I continue to experiment and investigate any suggestions.

Thank you.

gwiot
 
Posts: 4
Joined: Sun Mar 07, 2021 1:18 pm

Re: lastread function not working as expected

by Avrphreak on Mon Apr 26, 2021 6:29 am

Hello, I am looking for the same functionality for my weather station project.
I want to use the lightweight MQTT library by Adafruit for this because the AdafruitIO library gives me conflicts with other libraries i use.
I am able to publish and subscribe to values but I would like to use some form of retain so I can put my Esp32 to sleep and only check for updates every 15 minutes or so.

Can anyone show an arduino example on how to do this please?
Do I need to give the feeds a specific name?

I did read the page with the retain (get) description but I don't understand how to use it with the MQTT library.

Any help is much appreciated!

Avrphreak
 
Posts: 3
Joined: Thu Apr 15, 2021 3:15 pm

Re: lastread function not working as expected

by brubell on Mon May 03, 2021 10:10 am

Avrphreak wrote:Hello, I am looking for the same functionality for my weather station project.
I want to use the lightweight MQTT library by Adafruit for this because the AdafruitIO library gives me conflicts with other libraries i use.
I am able to publish and subscribe to values but I would like to use some form of retain so I can put my Esp32 to sleep and only check for updates every 15 minutes or so.

Can anyone show an arduino example on how to do this please?
Do I need to give the feeds a specific name?

I did read the page with the retain (get) description but I don't understand how to use it with the MQTT library.

Any help is much appreciated!


Please post this in a new thread.

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

Please be positive and constructive with your questions and comments.