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

Improve uptime accuracy #305

Closed
wants to merge 4 commits into from
Closed

Improve uptime accuracy #305

wants to merge 4 commits into from

Conversation

bertmelis
Copy link
Contributor

Improve accuracy of the uptime calculation by storing uptime as milliseconds.
Conversion to seconds is only done when preparing to main code.

Drawback: the maximum uptime is a lot lower than before, but still way more than I'd ever live.

Improve accuracy of the uptime calculation by storing uptime as
milliseconds.
Delete hardcoded KeepAlive value.
When omitted, it defaults to 15secs in asyn-mqtt-client library.
@bertmelis
Copy link
Contributor Author

PS I also committed the keepalive to my fork so it showed up here. I'm in the assumption that the hardcoded keepalive value for MQTT can be deleted as mentioned in #301.

@bertmelis
Copy link
Contributor Author

I didn't test the config mode but you're probably right as this isn't a "normal" string but a variable "IPaddress". I was a bit hasty/blunt.

PS I'm going crazy of my autocorrect. It's always correcting to a like Dutch word.

@bertmelis
Copy link
Contributor Author

I just tested online using idone.com:

#include <iostream>
#include <cstring>
using namespace std; // consider removing this line in serious projects

int main() {
	int MAX_IP_STRING_LENGTH = strlen("192.168.129.100");
	char _apIpStr[MAX_IP_STRING_LENGTH];
	snprintf(_apIpStr, MAX_IP_STRING_LENGTH + 1, "%d.%d.%d.%d", 192, 168, 123, 123);
	cout << _apIpStr << "\n";
	return 0;
}

without the +1, the output is 192.168.123.12.

By the way: it has nothing to do with the actual IP address you are using. It's the output of this IP address in the logger and in MQTT that's incorrect.

@avdleeuw
Copy link

avdleeuw commented Mar 6, 2017

Bert,

good point. But unfortunately, MAX_IP_STRING_LENGTH is not determined with a 'strlen' function.

In Limits.hpp, you can find this definition (notice the 'sizeof'):

const uint8_t MAX_IP_STRING_LENGTH = sizeof("123.123.123.123");

When I add this to your sample code and run it on ideone.com as well, it becomes obvious where the difference stems from.

#include <iostream>
#include <cstring>
using namespace std; // consider removing this line in serious projects

int main() {
	int MAX_IP_STRING_LENGTH = strlen("192.168.129.100");
	char _apIpStr[MAX_IP_STRING_LENGTH];
	snprintf(_apIpStr, MAX_IP_STRING_LENGTH + 1, "%d.%d.%d.%d", 192, 168, 123, 123);
	cout << _apIpStr << "\n";
	cout << "Strlen:" << MAX_IP_STRING_LENGTH << endl;
	cout << "Sizeof:" << sizeof("192.168.129.100") << endl;
	return 0;
}

Output:

192.168.123.123
Strlen:15
Sizeof:16

@bertmelis
Copy link
Contributor Author

You're totally right.

@bertmelis bertmelis closed this Mar 6, 2017
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