This shows you the differences between two versions of the page.
|
iothings:laboratoare:2025_code:lab9_1 [2025/11/23 12:46] dan.tudose |
iothings:laboratoare:2025_code:lab9_1 [2025/11/24 16:58] (current) dan.tudose |
||
|---|---|---|---|
| Line 19: | Line 19: | ||
| const char* DEVICE_ID = "sparrow-01"; | const char* DEVICE_ID = "sparrow-01"; | ||
| - | #define I2C_SDA 21 | + | // Hardware (adapt to your Sparrow board) |
| - | #define I2C_SCL 22 | + | #define I2C_SDA 21 |
| - | #define NEOPIXEL_PIN 3 | + | #define I2C_SCL 22 |
| + | #define NEOPIXEL_PIN 3 | ||
| #define MIN_VALID_EPOCH 1577836800UL // Jan 1 2020 used to detect if NTP time is set | #define MIN_VALID_EPOCH 1577836800UL // Jan 1 2020 used to detect if NTP time is set | ||
| Line 62: | Line 63: | ||
| Serial.println("NTP time synced"); | Serial.println("NTP time synced"); | ||
| } | } | ||
| + | } | ||
| + | |||
| + | bool waitForTime(uint32_t timeoutMs = 8000) { | ||
| + | unsigned long start = millis(); | ||
| + | while (!hasValidTime() && millis() - start < timeoutMs) { | ||
| + | syncTimeIfNeeded(); | ||
| + | delay(200); | ||
| + | } | ||
| + | return hasValidTime(); | ||
| } | } | ||
| Line 330: | Line 340: | ||
| connectWiFi(); | connectWiFi(); | ||
| - | syncTimeIfNeeded(); | + | waitForTime(); |
| secureClient.setTimeout(15000); | secureClient.setTimeout(15000); | ||
| - | secureClient.setInsecure(); // NOTE: uses HTTPS but skips cert validation (lab use) | + | secureClient.setInsecure(); // NOTE: uses HTTPS but skips cert validation |
| initBME(); | initBME(); | ||
| Line 356: | Line 366: | ||
| delay(10); // tiny delay to keep loop friendly | delay(10); // tiny delay to keep loop friendly | ||
| } | } | ||
| + | |||
| </code> | </code> | ||