Closed mrdc closed 1 year ago
What does the "my_external_callback" do?
What does the "my_external_callback" do?
It processes received data triggered by an interrupt. No IO operations with network etc. Ah, it also sends data via mqtt after processing:
void mqtt_publish(String data, String topic){
mqtt_client.publish(data, topic);
}
void my_external_callback(){
...here we process incoming data
at the end we call
mqtt_publish(data, topic);
return;
}
Processing data is not exactly recommended within the interrupt handler and should be avoided.
Publishing data is more within the region "don't even consider it".
Excecuting the interrupt handler does suspend the loop and any other task the processor is doing. A save method to handle the interrupt is to store the received data somewhere - like a global variable - and to set a flag that stuff has to be done.
In the loop you can check this flag, process the data and publish the result. When you're done, reset the flag.
Excecuting the interrupt handler does suspend the loop and any other task the processor is doing.
I think in my case it was a callback with some data processing, not the real interrupt. But it's also possible that under the hood it used some sort of interrupt that's why it affected this mqtt library. The issue is in the library, because asyncmqtt worked fine w/o any issues.
The library is not interrupt- or thread-safe. You need to ensure that no other operation is using the client when using in parallel.
Closing for now, please reopen if the issue persists.
Hello,
I'm experiencing a bug when mqtt connection is closed (error
LWMQTT_MISSING_OR_WRONG_PACKET
) as soon as external callback is executed. It looks likeWiFiClientSecure
whicharduino-mqtt
uses under the hood, is not async, that's why tls connection is interrupted by this callback. The same code, which I use for a long time, works fine withasyncmqtt
, which is usesasynctcp
under the hood. I've decided to switch toarduino-mqtt
, because it's maintained and has support for client certificates.---> here I have a callback and then mqtt connection is dropped and then tls session is re-established.