I have been trying to figure out why my agent code is losing data when it tries to send data from the device to an mqtt server. I have tried bracketing calls to imp.getmemoryfree() around various calls and it seems like I am losing memory during the publishing of new data to the server.
I am connecting to the server and then publishing some topics which seem to be the cause of the leak, but I don’t understand why since all the strings are local to the function. After several days of sending data the Agent runs out of memory and restarts. Any suggestions what I might be doing wrong?
local config_topic1 = "homeassistant/sensor/duration_compressor/config";
local config_payload1 = {
"device_class":"duration",
"state_topic":"homeassistant/sensor/sensorCompressor/state",
"unit_of_measurement":"s",
"value_template":"{{ value_json.duration}}",
"unique_id":"compressor_duration01ae",
"device":{
"identifiers":[
"compress01ae"
],
"name":"Pipe Compressor"
}
};
local message = mqtt_client.createmessage(config_topic1, http.jsonencode(config_payload1) ,
{"qos": mqtt.AT_LEAST_ONCE});
message.sendasync(function(result) {
if (result != 0) server.error("Error code " + result);
});