tuanpmt / esp32-mqtt

ESP32 MQTT sample project for
https://github.com/tuanpmt/espmqtt
Apache License 2.0
176 stars 50 forks source link

Subscribe_cb preempted by mqtt_publish? #1

Open hexagon5un opened 7 years ago

hexagon5un commented 7 years ago

Hiya Tuan,

Awesome work!

I was playing with your demo code, all just fine. Then I noticed that calling a publish shortly after a subscribe seems to prevent a publish from within the subscribe callback from being run.

In your demo, the subscribe command triggers the subscribe callback which then runs code that publishes "abcde" to the test channel. When I add a publish line:

void connected_cb(void *self, void *params)
{
    mqtt_client *client = (mqtt_client *)self;
    mqtt_subscribe(client, "esp32_test", 0);
    mqtt_publish(client, "esp32_test", "howdy!", 6, 0, 0); 
}

the "abcde" as well as the debug messages from the subscribe callback never get run.

However, when I send messages to the subscribed channel, the data comes in and gets processed like it should. So it looks like it's subscribed properly, but the feedback (pub and log messages) just don't work.

I would start to dig into the timings of all this, but I think that you are much more familiar with the code at this point. :)

tuanpmt commented 7 years ago

The reason is sending thread write multiple message in the same time, and receiving thread only know last message (with msg_pending_id and msg_pending_type). I'm thinking simple way.