Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More MQTT Ethernet configuration - timeout #1453

Open
wants to merge 3 commits into
base: development
Choose a base branch
from

Conversation

mobrembski
Copy link

Hi All!

I will give you a background why i've created this PR.

My device is quite standalone, and it doesn't requires MQTT broker to be connected all the time. It's great if it is connected, but if it's not connected - it should be able to still operate normally.
The problem is that current MySensors library in practice doesn't allow to run code without connection to broker. In practice, because in theory it allows but when i run my code on my device, user loop() is handled every 2 seconds because MQTT is blocking MCU while waiting for connection to be established. If it fails, it runs user loop for one time and then it retries to connect, blocking for another second.
It is not very useful to have application loop executed every 2 seconds...
My solution is very simple. Just give end user ability to change default connection timeout settings. If he doesn't supply his customized settings, then default (1s) is used - just like it is now.

@@ -159,7 +159,11 @@ bool reconnectMQTT(void)

return true;
}
#if defined(MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about setting the default value in MyConfig.h (like we do for baud rate here). That way we don't need to have the if clause here and on line 258.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you wish, no problem! Will do in an hour

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mobrembski mobrembski force-pushed the mqtt_eth_times_more_config branch 2 times, most recently from e27f08a to 947f1a0 Compare November 16, 2020 17:46
@mfalkvidd
Copy link
Member

Nice work. Our CI pipeline is out of order at the moment unfortunately, probably due to changes in the Github API. People in the core team are looking at it.

In the meanwhile, here are some minor things:

  1. Could you please add the new keywords to keywords.txt? If keywords aren't in keywords.txt, they will not be highlighted in the Arduino IDE. Highlighting makes the code easier to follow and helps spot spelling mistakes.
    Just add these here
    MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT
    MY_MQTT_ETH_INIT_DELAY

  2. This is a bit quirky, but to make Doxygen generate documentation, the new keywords must be defined at

    #define MY_MQTT_CLIENT_PUBLISH_RETAIN

If keywords aren't included in Doxygen, they will not be available at https://www.mysensors.org/apidocs/index.html

Just add defines for these:
MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT
MY_MQTT_ETH_INIT_DELAY

@mobrembski
Copy link
Author

Nice work. Our CI pipeline is out of order at the moment unfortunately, probably due to changes in the Github API. People in the core team are looking at it.

In the meanwhile, here are some minor things:

  1. Could you please add the new keywords to keywords.txt? If keywords aren't in keywords.txt, they will not be highlighted in the Arduino IDE. Highlighting makes the code easier to follow and helps spot spelling mistakes.
    Just add these here
    MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT
    MY_MQTT_ETH_INIT_DELAY
  2. This is a bit quirky, but to make Doxygen generate documentation, the new keywords must be defined at
    #define MY_MQTT_CLIENT_PUBLISH_RETAIN

If keywords aren't included in Doxygen, they will not be available at https://www.mysensors.org/apidocs/index.html

Just add defines for these:
MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT
MY_MQTT_ETH_INIT_DELAY

No problem!
Done ;)

MyConfig.h Outdated Show resolved Hide resolved
MyConfig.h Outdated Show resolved Hide resolved
MY_MQTT_ETH_INIT_DELAY configuration field is useful for adjusting
Ethernet Chip initialisation delay time by library user.
@mobrembski
Copy link
Author

It appears that current EthernetClient implementation for Linux GW doesn't support setSocketTimeout. But it think it can be added easily, will try....

@mobrembski
Copy link
Author

I've added implementation of setConnectionTimeout based on setsockopt SO_SNDTIMEO and SO_RCVTIMEO, please have a look.
I'm not checking return status for setSockOpt since setting SO_SNDTIMEO and SO_RCVTIMEO is not obligatory and it will result in working socket even if it fails.

@mobrembski mobrembski force-pushed the mqtt_eth_times_more_config branch 2 times, most recently from e9e656a to 11a279b Compare November 18, 2020 08:12
@mobrembski
Copy link
Author

Unfortunately, still ESP platforms doesnt support connection timeout, and i can't see an option to implement it...
So i need to ifdef around that

@mobrembski
Copy link
Author

Hi all, i can see butler assertion:
A mail with a patch has been sent to you that, if applied to your PR, will make it follow the MySensors coding standards.
You can apply the patch using:
git apply restyling.patch

is there any option to get what he has produced? I can't find what's wrong in coding style

@mfalkvidd
Copy link
Member

@mobrembski
Copy link
Author

@mfalkvidd No, i didnt ;) that's why i was asking :)
Thanks for link!

@mfalkvidd
Copy link
Member

I'll check the log files to see if I can find anything related to the missing email.

MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT is useful for adjusting default
MQTT TCP/IP connection timeout by library user.
@mfalkvidd
Copy link
Member

I think gsm has same problem as esp.

/var/lib/jenkins/jobs/MySensors/jobs/MySensors/branches/PR-1453/workspace/MySensors/core/MyGatewayTransportMQTTClient.cpp:256:18: error: 'TinyGsmClient {aka class TinyGsmSim800::GsmClient}' has no member named 'setConnectionTimeout'; did you mean 'setTimeout'?
_MQTT_ethClient.setConnectionTimeout(MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT);
^~~~~~~~~~~~~~~~~~~~
setTimeout
exit status 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants