I have an Awair Air Quality Edge Driver which has a function that fetch the air data via Local API as a JSON string. This said function gets called every minute in the init life cycle and every time the user uses the refresh capability to get the latest air data.
Now, I want to implement some MQTT features onto the device. What I want to achieve is that every time the data refreshes, if the change in one of the co2, PM, and VOC values is greater than 20% of corresponding previous data value, encode the new data into a JSON string and send it to the MQTT broker along with a warning message.
I have successfully established a connection to the MQTT broker, but right now I am stuck on how to record the data in order to do the comparison. Any idea on how to do that? Different approaches are also gladly welcome. Thank you very much in advance.