Hot answers tagged

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 ...


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; ...


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);


1

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


1

There is a subtle distinction between an array of characters and a C string. All C strings are arrays of characters, but not all arrays of characters are C strings. A C string is an array of characters terminated with a NULL. Therefore C strings cannot contain NULL (zero value) characters. There are a whole set of C library functions that operate on C ...


1

Epoch are seconds from 1970-01-01. Get it from JSON as unsigned long. They are a number in the returned JSON (no ") from https://openweathermap.org/ doc: "sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049}, to convert it to string with TimeLib.h: #include <TimeLib.h> #include <ArduinoJson.h> void setup() { Serial.begin(115200)...


1

C and C++ programs get compiled in multiple passes through various programs/steps. One of the first is the C Preprocessor, which handles the #define preprocessor directive. It's basically a big find/replace function. After the preprocessor is done, anywhere you had D8 outside of a string literal, would have the value 13. It's not a variable or a string -- ...


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