Reputation: 89
Is there any way to fetch actual sensor state from MQTT without using cache or anything else?
For example after NR restart i need to get all actual values saved in MQTT, how can i do that?
Upvotes: 2
Views: 3833
Reputation: 26
You must save the last value in a Database.
I do not know how many values you would save. Check out https://www.npmjs.com/package/json-db-node-red, maybe it's enough for you.
Store all incomming values in this json object like a key:value store.
I do not have a solution to trigger a page load in node-red. But you can insert a button to start a flow to show the saved data.
Upvotes: 0
Reputation: 59628
Values are not saved in MQTT, it is not a database it is a messaging system.
Also you do not fetch data with MQTT, you subscribe to a topic and messages are delivered to the client when they are published.
The only exceptions to these statements are the following:
Retained messages. If the retained flag is set on a message by the publisher then the last published message with the retained flag on a topic will be delivered to any clients that subscribe to that topic. This is useful for making sure a subscriber always has access the last published value.
High QOS subscriptions. If the client is configured to subscribe to a topic with QOS 1 or 2 then the broker should queue any messages published on that topic while the client is offline and deliver them to the client when they reconnect and resubscribe to the topic (assuming the same client-id is used and unless the cleansession flag is set to true).
If you want to poll sensors for their current value, you could always have the sensor subscribe to a commands topic and use this to instruct them to publish their latest value.
Upvotes: 2