Hot answers tagged

7

The problem is that float numbers are seldom an exact representation. So the float is stored as the closest number that is exactly representable as a float, namely 10446438 × 2−18 = 39.84999847412109375. When you multiply this by 100, you get 16322559 × 2−12 = 3984.999755859375. And than casting to an int or long results in 3984, not 3985. so whenever you ...


2

Assuming little-endian bools (least significant bool first), you should use simple bit-shifting, not floating point power calculations: for(int id=start_index;id<=stop_index;id++){ result |= b_array[id] ? (1 << run) : 0; run++; } The ternary operation (b_array[id] ? (1 << run) : 0) means: If b_array[id] is true, then Or result ...


2

After parsing the time into numbers, you can use the standard C time library time.h. More specifically, use the mktime function to convert a struct tm into a time_t, and use difftime to get the seconds since the start of the Unix expoch: #include <time.h> void loop() { struct tm ltm = {0}; ltm.tm_year = 2019 - 1900; ltm.tm_mon = 11 - 1; ...


2

Please see the comments in the code: // SDMacAdress is zero terminated // (it should be because you use strcp not strncp) // char arr[12]; you need one extra byte for the zero char arr[13]; strcpy(arr, SDMacAddress); auto getNum = [](char c) { // you forgot upercase HEX letters (A-F) // don't use sophisticated code // the best programmers produce ...


1

The IPAddress class has a member function bool fromString(const char *address).


1

If you have a fixed format you can use strtok() to slice the string into individual segments, then convert those segments to integers. They can then be used with TimeLib.h with the setTime() function. You can then query TimeLib for the unix timestamp with now(). Edit: using PaulStoffregen's TimeLib, this code sets current time and returns current unix ...


1

If you want 4 decimal places, you may try something like this: gps_string = String(gps.location.lat(), 4) + " x " + String(gps.location.lng(), 4);


Only top voted, non community-wiki answers of a minimum length are eligible