0

Got lost on mqtt.readSubscription
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Got lost on mqtt.readSubscription

by MSPAdafruitIO on Fri Jun 29, 2018 10:24 am

Hi folks,

i got lost on mqtt.readSubscription. I'm able to read data from my feed. As soon as I change the value on the dashboard it shows up on the Nodemcu.

What I understood so far is that the MQTT_Subscribe is waitint for a message.

My idea is to read data on startup of the Nodemcu and than continue with waiting for new data.
Any idea how I can read the last data value with the mqtt lib?

THX for help

Gerhard

MSPAdafruitIO
 
Posts: 2
Joined: Fri Jun 29, 2018 8:04 am

Re: Got lost on mqtt.readSubscription

by brubell on Fri Jun 29, 2018 11:43 am

If you want to have your client wait for subscription updates, before the loop, implement:

Code: Select all | TOGGLE FULL SIZE
client.loop_background()

which runs a thread in the background so you can continue doing things in your script.
or

Code: Select all | TOGGLE FULL SIZE
client.loop_blocking()
which runs a message loop forever. If you just want to listen to an event, implement this.
Then, when the on_message callback calls the message method (https://github.com/adafruit/io-client-p ... ent.py#L34), save the incoming payload to a new value.

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

Re: Got lost on mqtt.readSubscription

by MSPAdafruitIO on Fri Jun 29, 2018 12:13 pm

Hi brubell,

thx for answer.

Let me explain better.

Nodemcu is starting. Let's say due to power fail or so.

1.) During start I want to read the last value of the feed just to continue from the last value.
2.) After that I'm waiting for messages and I read the value

2.) Is ready, working fine and I'm able to read. No Problem

The question is on 1.) During start I don't have a pending message because all messages are processed by the client.
How can I force the server to give me the last values of an feed or how can I read the value by myself?

Cu
Gerhard

MSPAdafruitIO
 
Posts: 2
Joined: Fri Jun 29, 2018 8:04 am

Re: Got lost on mqtt.readSubscription

by brubell on Mon Jul 02, 2018 2:23 pm

You can get the previous point of data from IO by getting previousData

https://io.adafruit.com/api/docs/#opera ... eviousData

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

Please be positive and constructive with your questions and comments.