Last known value from Adafruit IO on Arduino

1.1k views Asked by At

I'm working on a basic sketch for an Adafruit Huzzah which uses the Adafruit IO MQTT library. This is put together by copy/pasting from various sources and examples, and mostly works - but there's one thing I can't figure out.

Right now, I'm using a line of code which fires off a handler every time a new message is received via the feed I'm subscribed to:

group->onMessage("daniel", handleMessage);

This is fine, and does what I need it to do for values which are updated.

What I want to do, however, is grab the last known value on the feed during the setup() routine, rather than having to wait for a new value to come though.

In MQTT parlance, I believe this is known as retained messages, which I think Adafruit IO has on by default, but I don't know how to grab these values during the startup() process.

Can anyone help me out?

(If you're interested, here's my code so far: https://github.com/LimeBlast/family-box/blob/master/family-box.ino)

3

There are 3 answers

0
Daniel Hollands On BEST ANSWER

Seeing as I've just found the answer to the question I was asking, I figured it only right I post it here.

The command I was looking for, after having setup the feed, was ->get(), as shown in this example.

2
hardillb On

Short answer is you don't... do anything.

Retained messages are delivered just the same as normal messages (via the onMessage callback), they are just delivered as soon as you subscribe to the topic.

0
Gilles On

I also had this problem. Here is the full explination

The get() function wil ask the Adafruit servers to resend the last value of the feed to this client only. When the value is received, the handler will be executed.

exampleFeed->get();