subscribe to past data

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.
Locked
User avatar
TheRobertTalley
 
Posts: 9
Joined: Fri Nov 13, 2020 1:26 pm

subscribe to past data

Post by TheRobertTalley »

Is there any way to subscribe to https://io.adafruit.com/api/v2/{usernam ... /data/last to retrieve the last known value of a feed? it's in the documentation but returns:
{"error":"not found - API documentation can be found at https://io.adafruit.com/api/docs"}.

I am attempting to read a slider value after the time it was changed. or at least compare values after an esp has been asleep. Changing the value of a slider and reading it with :


mqtt.subscribe(MQTT_USER "/feeds/slider");

if (!mqtt.connected()) {
mqtt.connect( "", MQTT_USER, MQTT_PASSWORD);
}
mqtt.loop();
}

Only returns a change if the connection is live. is there a way to tell rip van winkle what has happened ?

User avatar
TheRobertTalley
 
Posts: 9
Joined: Fri Nov 13, 2020 1:26 pm

Re: subscribe to past data

Post by TheRobertTalley »

so according to abachman:
Assuming I'm understanding you correctly, we have that feature for feeds already via the get() method on Feed objects in the Adafruit_IO_Arduino library. It behaves pretty much exactly like you describe. If you subscribe to an MQTT feed topic, "username/feeds/something", publishing anything to "username/feeds/something/get" will force the most recent value for the feed to be sent to just that MQTT client. If you've set up an onMessage callback, it'll trigger your code in the same way as if your feed had a new value published.

At least, that seems to be what you're describing.

We're currently figuring out how to better document the MQTT API features since we also have some more in the pipeline. For now, feature announcements come via the blog, these forums, and discord.gg/adafruit.

The feature hasn't been deployed yet for groups, but should be in the next week or two.

lastValue uses the HTTP API, which is okay if you're comfortable polling for the last value, but doesn't play nicely with active MQTT connections.


- adam b.
this should work if the esp is waking up:


mqtt.publish(MQTT_USER "/feeds/slider/get", "anything"); //to get a responce for
mqtt.subscribe(MQTT_USER "/feeds/slider"); // should be read with a proper callback.

but that doesnt work either.
Attachments
adafruit forum.png
adafruit forum.png (108.92 KiB) Viewed 109 times

User avatar
TheRobertTalley
 
Posts: 9
Joined: Fri Nov 13, 2020 1:26 pm

Re: subscribe to past data

Post by TheRobertTalley »

pubsubclient with this rough guide seems to work:

Code: Select all

#define sliderpub MQTT_USER "/feeds/slider"
#define sliderget MQTT_USER "/feeds/slider/get"

mqtt.subscribe(sliderpub);
mqtt.publish(sliderget, "\0");

readsub();delay(1000);readsub();

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”