Is there a way to get a channel's last update data by using MQTT API?

2 views (last 30 days)
When a client sensor device power on, it needs to follow all the parameters that the system sets.
I use one channel to collect sensor data and use another one to pass parameters to the sensor.
Using HTTP API, it is easy to get all channel data at once, such as URL:
When devices are limited by the computer power, they only use MQTT API, It seems no way to get the latest data in a channel after just powering on.
Even sensor uses subscribe function, it must wait until the next update and then gets all the correct parameters.
Is there a way could get a channel's last update data by using MQTT API as the client's request?

Answers (1)

Christopher Stapels
Christopher Stapels on 1 Jul 2022
There is not a way to get the last update via MQTT. Here is a fairly complicated workaround however:
Set up a react on a new channel (say channel B) that triggers code to repeat the last value writted to channel A. Then set that react to trigger on insert to the channel. Now the device is subscribed to channel A, and does MQTT publish to channel B. The react triggers, and writes to channel A, and the devices gets the updated value via its subscription.
  1 Comment
Malik Ali
Malik Ali on 6 Sep 2022
Hi sir, i am working on a project in which i am sending dht11 sensor data with nodemcu on thingspeak channel and now i want to control my led connected on nodemcu on the basis of thingspeak channel value. In short i want a decision making process on thingspeak. can you help me how can i do this task.

Sign in to comment.


Find more on Write Data to Channel in Help Center and File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!