Search code examples
arduinomqttadafruit

Last known value from Adafruit IO on Arduino


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)


Solution

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