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.
User avatar
macxPrime
 
Posts: 8
Joined: Sun Feb 14, 2021 2:39 pm

lastread function not working as expected

Post by macxPrime »

When I start up my Arduino running the MQTT library, subscriptions to feed work great whenever there is a feed update.

However, when I start up my Arduino and there is no feed update activity, nothing is returned when calling feedobject.lastread.

I am guessing that there is a destructive read in play at the Adafruit MQTT servers as reported years ago. Has there been an update to the client library or the server to retain last feed update data? I prefer to use and support Adafruit's MQTT service. If there is an alternative solution suggestion, I'd be interested in that as well. The objective is to accomodate a loss of power, crash etc. with the last known feed data.

Thanks!

Mike

User avatar
jwcooper
 
Posts: 1004
Joined: Tue May 01, 2012 9:08 pm

Re: lastread function not working as expected

Post by jwcooper »

IO doesn't support the MQTT retain functionality as noted here:
https://io.adafruit.com/api/docs/mqtt.h ... ned-values

In that link, we suggest an alternative if you need to get the last value on startup (the */get topic).

User avatar
macxPrime
 
Posts: 8
Joined: Sun Feb 14, 2021 2:39 pm

Re: lastread function not working as expected

Post by macxPrime »

Thanks! Excellent response and I am sorry I missed the retain specification in the documentation. I completely understand.

The MQTT service is great for my non-stateful part of my project and I will have to review the /get solution.

cheers and thanks again

Mike

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

Re: lastread function not working as expected

Post by gwiot »

Thank you for the information on using the */get topic as an alternative to the Retain functionality. I have tried to implement this method to obtain the last published value but it is not working for me. I am not using the Arduino library but here is what my software is doing:

1. connect to MQTT
2. subscribe to uname/feeds/example

At this point I can publish to the feed and see the value on the dashboard, and I receive a response to the subscription with the new value. I also receive a response to the subscription when I publish (change the value) from the dashboard.

3. Then I publish to "uname/feeds/example/get", but I do not get any response to the subscription. I have tried publishing a null (\0) and other values as the data to the /get topic, but nothing is returned.

Am I missing something or is there something else I can try? I would like to know if "macxPrime" (forum, 3/4/21) got this to work.

Thank you,
Geoff

User avatar
jwcooper
 
Posts: 1004
Joined: Tue May 01, 2012 9:08 pm

Re: lastread function not working as expected

Post by jwcooper »

Here is the client libraries implementation:
https://github.com/adafruit/Adafruit_IO ... d.cpp#L280

The library is just publishing a null character to the topic.

Here is the example that utilizes the implementation:
https://github.com/adafruit/Adafruit_IO ... be.ino#L55

One thing you can try is the above example, to ensure it's working for you.

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

Re: lastread function not working as expected

Post by gwiot »

Thank you for your response and the references. The client library appears to operate similar to my software, but I will investigate further. If I can test with the library directly, I will compare with my results.

I am very pleased with the platform and it is working well for me!

Thank you,
Geoff

User avatar
Ashaman483
 
Posts: 5
Joined: Sun Mar 28, 2021 6:53 pm

Re: lastread function not working as expected

Post by Ashaman483 »

Is there any update to this? I am having the same problem.

I have a MQTT dart application which can successfully subscript and publish to my feed however the /get feature does not work.

With publishing to my topic + /get I receive the publish ack but never get the published data from my feed. Maybe its something I do not understand w/ the dart mqtt_client since the feature does work ok from my ESPP8266 code. Any ideas?

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: lastread function not working as expected

Post by brubell »

Ashaman483 wrote:Is there any update to this? I am having the same problem.

I have a MQTT dart application which can successfully subscript and publish to my feed however the /get feature does not work.

With publishing to my topic + /get I receive the publish ack but never get the published data from my feed. Maybe its something I do not understand w/ the dart mqtt_client since the feature does work ok from my ESPP8266 code. Any ideas?
I haven't used the MQTT dart application before, but you want to "pump"/"loop" the MQTT client's message loop to receive data back from the feed after publishing.

User avatar
Ashaman483
 
Posts: 5
Joined: Sun Mar 28, 2021 6:53 pm

Re: lastread function not working as expected

Post by Ashaman483 »

Can you explain what you mean by pump the message loop? I register a callback with the library to do the actual receiving so I do not easily have direct access to the receive loop.

Thanks!

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: lastread function not working as expected

Post by brubell »

Ashaman483 wrote:Can you explain what you mean by pump the message loop? I register a callback with the library to do the actual receiving so I do not easily have direct access to the receive loop.

Thanks!
Could you provide a link to this software, I'll take a look to see if I find something equivalent

User avatar
Ashaman483
 
Posts: 5
Joined: Sun Mar 28, 2021 6:53 pm

Re: lastread function not working as expected

Post by Ashaman483 »


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

Re: lastread function not working as expected

Post by gwiot »

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.

User avatar
Ashaman483
 
Posts: 5
Joined: Sun Mar 28, 2021 6:53 pm

Re: lastread function not working as expected

Post by Ashaman483 »

I agree, anymore details you have about what you are talking about would be helpful.

User avatar
Ashaman483
 
Posts: 5
Joined: Sun Mar 28, 2021 6:53 pm

Re: lastread function not working as expected

Post by Ashaman483 »

Should I see messaged published to a topic + /get in the monitor?

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: lastread function not working as expected

Post by brubell »

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/

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”