Using M5StickC ESP32 with built-in MPU6886 accelerometer to read vibrations. In the loop() section the code gets 10 readings per second and if the readings exceed a threshold, it starts publishing the results in a JSON MQTT message on asyncmqttclient, again 10 publishes per second. The period of full publishing continues on until the readings fall back under the threshold+5 seconds.
However,when it starts publishing 10 messages per second, the accelerometer readings go haywire and the values are higher than they should be in reality. This is the results under asyncmqttclient publish:
The blue ellipse is just one knock. Goes up and down, and the vibration ends there. However the green ellipse part is the period where the code sends the publish messages, they should normally be down and silent like this:
This second graph values are from the same code, the only difference is i commented out the asyncmqttclient publish mqtt command. If i use pubsubclient it also gives the correct values.
if (eq_status) { // Earthquake still happening
eq_time_count++ ;
if (((slta && !staLta.checkTrigger()) || (!slta && eq_time_count > eq_pet)) || (master && !slave_eq_state)) { // EQ Ends...
eq_status = false;
eq_time_count = 0;
updateState("LISTENING");
publish_mqtt(MQTT_PUB_EVENT, updateEvent(ax,ay,az,pga).c_str(), 0, true);
digitalWrite(M5_LED, HIGH);
if (SPK_HAT) ledcWriteTone(spkChannel, 0);
lcd.set_brightness(lcd_brightness);
} else {
/* THIS IS THE PROBLEMATIC PART /
publish_mqtt(MQTT_PUB_EVENT, updateEvent(ax,ay,az,pga).c_str(), 0, true);
/client.publish(MQTT_PUB_EVENT,updateEvent(ax,ay,az,pga).c_str());*/
}
} else {
if (flush_update) { // Send periodic event update message
flush_event++;
if (flush_event > (flush_period*10)) {
publish_mqtt(MQTT_PUB_EVENT, updateEvent(ax,ay,az,pga).c_str(), 0, true);
flush_event = 0;
}
}
}
I think there could be something wrong with either asyncmqttclient or espasyncTCP, or could there be any other cause?

