Imroy / pubsubclient

A client library for the ESP8266 that provides support for MQTT
MIT License
434 stars 115 forks source link

client.publish() introduces huge delays #22

Open mactro opened 9 years ago

mactro commented 9 years ago

I have following code running on ESP:

void loop()
{
    if(millis() - t  > 10) {
        static int i = 0;
        String topic = "test/" + String(i % 10);
        String msg = "some test message " + String(t);
        mqtt->publish(topic, msg);
        i++;
        t = millis();
    }   
  mqtt->loop(); 
}

When I subscribe to the test/# topic I would expect the counter on the end of the message to have difference close to 10 between subsequent messages, but I usually get something around 100-200. What is even more bizzare, when I set up a python script on the PC to publish messages in 30ms intervals to a topic that ESP is subscribed to, the publishing rate accelerates to something around 20ms. Unfortunately after some time, ESP reboots with

rst cause:4, boot mode:(3,6)

wdt reset
load 0x40100000, len 28780, room 16 
tail 12
chksum 0x35
ho 0 tail 12 room 4
load 0x3ffe8000, len 1548, room 12 
tail 0
chksum 0x90
load 0x3ffe8610, len 3300, room 8 
tail 12
chksum 0x88
csum 0x88
Testato commented 9 years ago

Mqtt is writed for realtime execution ? Example, is it writed for drive a Drone ? I think about it like a notify sistem Il 22/lug/2015 02:58 PM, "mactro" notifications@github.com ha scritto:

I have following code running on ESP:

void loop() { if(millis() - t > 10) { static int i = 0; String topic = "test/" + String(i % 10); String msg = "some test message " + String(t); mqtt->publish(topic, msg); i++; t = millis(); } mqtt->loop(); }

When I subscribe to the test/# topic I would expect the counter on the end of the message to have difference close to 10 between subsequent messages, but I usually get something around 100-200. What is even more bizzare, when I set up a python script on the PC to publish messages in 30ms intervals to a topic that ESP is subscribed to, the publishing rate accelerates to something around 20ms. Unfortunately after some time, ESP reboots with

rst cause:4, boot mode:(3,6)

wdt reset load 0x40100000, len 28780, room 16 tail 12 chksum 0x35 ho 0 tail 12 room 4 load 0x3ffe8000, len 1548, room 12 tail 0 chksum 0x90 load 0x3ffe8610, len 3300, room 8 tail 12 chksum 0x88 csum 0x88

— Reply to this email directly or view it on GitHub https://github.com/Imroy/pubsubclient/issues/22.

mactro commented 9 years ago

Of course mqtt is not for real time, but publishing or receiving 100 messages per second is faaar from real time. Besides, I don't mind occasional delays, as long as average frequency will be around these 100Hz.

Imroy commented 9 years ago

To see how long the publish() and loop() methods can take, I modified the mqtt_basic sketch like this:

  uint32_t t = millis();
  client.publish("outTopic", "hello world");
  Serial.printf("Publish took %dms\n", millis() - t);

and

  t = millis();
  client.loop();
  Serial.printf("Loop took %dms\n", millis() - t);

Client.loop() almost always took "0ms" (i.e < 1 ms). Client.publish() took much longer - from less than 10 ms to over 100 ms. I don't know if there's much we can do about this. It's all up to the Espressif SDK and the Wifi network.

mactro commented 9 years ago

Ok, I have edited a topic to reflect your measurements. I have also done some additional testing with different QoS settings.

sudheera8 commented 7 years ago

Hi All

I have been using this library with ATWINC1500. I started off with using knolleary/pubsubclient but my requirement for QOS2 made me this fork of it. However,I have been experiencing the same speed issues. Can any one help me figure this out? Thanks in advance.

sudheera