Coder Social home page Coder Social logo

Comments (9)

knolleary avatar knolleary commented on May 24, 2024

There isn't any 5 second delay in the library - can you point to where you think there is one?

from pubsubclient.

ppatierno avatar ppatierno commented on May 24, 2024

I know that there isn't an explicit delay function called....
It seems that the problem is the readPacket() function here

for (uint16_t i = 0;i<length;i++)
{
if (len < MQTT_MAX_PACKET_SIZE) {
buffer[len++] = readByte();
} else {
readByte();
len = 0; // This will cause the packet to be ignored.
}
}

If I comment readByte() there isn't the delay....
The problem there is when the client doesn't receive any packet and it is checked if there is something to read.

Paolo.

from pubsubclient.

knolleary avatar knolleary commented on May 24, 2024

The client checks to see if there is data available before reading the packet. But once it starts reading the packet it will block until a whole packet has been read.

The readByte() line you reference is only called when the incoming packet is larger than MQTT_MAX_PACKET_SIZE - the client will read the whole packet off the network but discarding it so you won't get a callback for it. Do you know how large the message arriving is?

from pubsubclient.

ppatierno avatar ppatierno commented on May 24, 2024

If I write a simple sketch with only client.loop() inside main loop() and print millis() function output I see

1161118
1166130
1171137
1176144
1181154
1186161

As you can see there is a about 5 sec between the calls....

The example is simple

void loop()
{
client.loop();
Serial.println(millis());
}

The client is connected but it doesn't publish anything and it isn't subscribed to anything.
Sometimes the client.loop() is much faster and it happens where there is the pingreq/pingresp exchange with the broker.

Paolo.

from pubsubclient.

knolleary avatar knolleary commented on May 24, 2024

That suggests there is data available for the client to try reading - which shouldn't be the case if the client isn't subscribed to anything. As I linked to in my previous comment, the client will only try reading a whole packet from the network if _client->available() returns true. Otherwise loop returns straight away.

What hardware are you running this on?

from pubsubclient.

ppatierno avatar ppatierno commented on May 24, 2024

I'm running on a new Intel Galileo board :-)
It seems that on this board _client->available() doesn't return immediately if there aren't bytes to receive ?

from pubsubclient.

knolleary avatar knolleary commented on May 24, 2024

Possibly - obviously I cannot comment on how the galileo performs.

I don't consider this an issue with this library - so with your agreement, I'd like to close this item?

from pubsubclient.

ppatierno avatar ppatierno commented on May 24, 2024

Oh yes...I try to discover where is the problem.
Did you see the other my issue with IPAddress class ?

from pubsubclient.

knolleary avatar knolleary commented on May 24, 2024

Yes - not had time to look.

from pubsubclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.