Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
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.

lastread function not working as expected

by macxPrime on Thu Mar 04, 2021 12:57 pm

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

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

Re: lastread function not working as expected

by jwcooper on Thu Mar 04, 2021 1:35 pm

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).

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

Re: lastread function not working as expected

by macxPrime on Thu Mar 04, 2021 4:56 pm

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

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

Re: lastread function not working as expected

by gwiot on Mon Mar 08, 2021 3:34 pm

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

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

Re: lastread function not working as expected

by jwcooper on Mon Mar 08, 2021 5:02 pm

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.

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

Re: lastread function not working as expected

by gwiot on Tue Mar 09, 2021 12:12 pm

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

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

Re: lastread function not working as expected

by Ashaman483 on Mon Apr 19, 2021 12:40 am

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?

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

Re: lastread function not working as expected

by brubell on Mon Apr 19, 2021 9:40 am

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.

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

Re: lastread function not working as expected

by Ashaman483 on Mon Apr 19, 2021 10:06 am

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!

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

Re: lastread function not working as expected

by brubell on Mon Apr 19, 2021 10:08 am

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

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

Re: lastread function not working as expected

by Ashaman483 on Mon Apr 19, 2021 10:13 am


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

Re: lastread function not working as expected

by gwiot on Mon Apr 19, 2021 4:10 pm

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.

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

Re: lastread function not working as expected

by Ashaman483 on Tue Apr 20, 2021 3:14 am

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

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

Re: lastread function not working as expected

by Ashaman483 on Wed Apr 21, 2021 1:32 am

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

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

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: 1347
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.