From 1ae052da4e4c2f7ef3a37a7b170e9c0cc3728e31 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 22 Jan 2022 13:48:53 +0100 Subject: [PATCH 1/8] fix description Port#3 in readme.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 55c482c3..f14abef5 100644 --- a/README.md +++ b/README.md @@ -337,9 +337,9 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering. byte 11: Bluetooth channel switch interval in seconds/100 (0..255) [efault 10] byte 12: Bluetooth scanner status (1=on, 0=0ff) [default 1] byte 13: Wifi antenna switch (0=internal, 1=external) [default 0] - byte 14: count randomizated MACs only (0=disabled, 1=enabled) [default 1] + byte 14: 0 (reserved) byte 15: RGB LED luminosity (0..100 %) [default 30] - byte 16: 0 (reserved) + byte 16: Payloadmask (0..255) byte 17: 0 (reserved) bytes 18-28: Software version (ASCII format, terminating with zero) From 03e79267f8d96a9e0e0227047e4242ce46e5bb8b Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 22 Jan 2022 13:59:04 +0100 Subject: [PATCH 2/8] fix issue wrong Payload in TTNv3 #844 --- src/TTN/packed_decoder.js | 2 +- src/TTNv3/packed_decodeUplink.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TTN/packed_decoder.js b/src/TTN/packed_decoder.js index f338e6df..93aefd04 100644 --- a/src/TTN/packed_decoder.js +++ b/src/TTN/packed_decoder.js @@ -45,7 +45,7 @@ function Decoder(bytes, port) { if (port === 3) { // device config data - return decode(bytes, [uint8, uint8, int16, uint8, uint8, uint8, uint8, bitmap1, bitmap2, version], ['loradr', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags', 'payloadmask', 'version']); + return decode(bytes, [uint8, uint8, int16, uint8, uint8, uint8, uint8, bitmap2, version], ['loradr', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'payloadmask', 'version']); } if (port === 4) { diff --git a/src/TTNv3/packed_decodeUplink.js b/src/TTNv3/packed_decodeUplink.js index a010f3dc..388d8f0e 100644 --- a/src/TTNv3/packed_decodeUplink.js +++ b/src/TTNv3/packed_decodeUplink.js @@ -53,7 +53,7 @@ function decodeUplink(input) { if (input.fPort === 3) { // device config data - data = decode(input.bytes, [uint8, uint8, int16, uint8, uint8, uint8, uint8, bitmap1, bitmap2, version], ['loradr', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags', 'payloadmask', 'version']); + data = decode(input.bytes, [uint8, uint8, int16, uint8, uint8, uint8, uint8, bitmap2, version], ['loradr', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'payloadmask', 'version']); } if (input.fPort === 4) { From d8877933554c37a0af5cf483cb1fa7421d426657 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 23 Jan 2022 11:52:12 +0100 Subject: [PATCH 3/8] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f14abef5..9e20653c 100644 --- a/README.md +++ b/README.md @@ -325,7 +325,7 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering. **Port #3:** Device configuration query result - byte 1: Lora SF (7..12) [default 9] + byte 1: Lora SF (0..15, see rcommand 0x05) [default 5] byte 2: Lora TXpower (2..15) [default 15] byte 3: Lora ADR (1=on, 0=off) [default 1] byte 4: Screensaver status (1=on, 0=off) [default 0] @@ -334,13 +334,13 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering. bytes 7-8: RSSI limiter threshold value (negative) [default 0] byte 9: Lora Payload send cycle in seconds/2 (0..255) [default 120] byte 10: Wifi channel hopping interval in seconds/100 (0..255), 0 means no hopping [default 50] - byte 11: Bluetooth channel switch interval in seconds/100 (0..255) [efault 10] + byte 11: Bluetooth channel switch interval in seconds/100 (0..255) [default 10] byte 12: Bluetooth scanner status (1=on, 0=0ff) [default 1] byte 13: Wifi antenna switch (0=internal, 1=external) [default 0] byte 14: 0 (reserved) byte 15: RGB LED luminosity (0..100 %) [default 30] - byte 16: Payloadmask (0..255) - byte 17: 0 (reserved) + byte 16: Flags (Bitmask, 0..255) + byte 17: Payloadmask (Bitmask, 0..255, see rcommand 0x14) bytes 18-28: Software version (ASCII format, terminating with zero) From c810fe6833fbc806d6c0017bc43c05a29f636309 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 23 Jan 2022 11:55:31 +0100 Subject: [PATCH 4/8] Revert "fix issue wrong Payload in TTNv3 #844" This reverts commit 03e79267f8d96a9e0e0227047e4242ce46e5bb8b. --- src/TTN/packed_decoder.js | 2 +- src/TTNv3/packed_decodeUplink.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TTN/packed_decoder.js b/src/TTN/packed_decoder.js index 93aefd04..f338e6df 100644 --- a/src/TTN/packed_decoder.js +++ b/src/TTN/packed_decoder.js @@ -45,7 +45,7 @@ function Decoder(bytes, port) { if (port === 3) { // device config data - return decode(bytes, [uint8, uint8, int16, uint8, uint8, uint8, uint8, bitmap2, version], ['loradr', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'payloadmask', 'version']); + return decode(bytes, [uint8, uint8, int16, uint8, uint8, uint8, uint8, bitmap1, bitmap2, version], ['loradr', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags', 'payloadmask', 'version']); } if (port === 4) { diff --git a/src/TTNv3/packed_decodeUplink.js b/src/TTNv3/packed_decodeUplink.js index 388d8f0e..a010f3dc 100644 --- a/src/TTNv3/packed_decodeUplink.js +++ b/src/TTNv3/packed_decodeUplink.js @@ -53,7 +53,7 @@ function decodeUplink(input) { if (input.fPort === 3) { // device config data - data = decode(input.bytes, [uint8, uint8, int16, uint8, uint8, uint8, uint8, bitmap2, version], ['loradr', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'payloadmask', 'version']); + data = decode(input.bytes, [uint8, uint8, int16, uint8, uint8, uint8, uint8, bitmap1, bitmap2, version], ['loradr', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags', 'payloadmask', 'version']); } if (input.fPort === 4) { From 7e6e160aa8491fac9471309990ddf74ed5662491 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 23 Jan 2022 12:00:09 +0100 Subject: [PATCH 5/8] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9e20653c..81771f5c 100644 --- a/README.md +++ b/README.md @@ -325,22 +325,22 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering. **Port #3:** Device configuration query result - byte 1: Lora SF (0..15, see rcommand 0x05) [default 5] + byte 1: Lora DR (0..15, see rcommand 0x05) [default 5] byte 2: Lora TXpower (2..15) [default 15] byte 3: Lora ADR (1=on, 0=off) [default 1] byte 4: Screensaver status (1=on, 0=off) [default 0] byte 5: Display status (1=on, 0=off) [default 0] byte 6: Counter mode (0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed) [default 0] - bytes 7-8: RSSI limiter threshold value (negative) [default 0] - byte 9: Lora Payload send cycle in seconds/2 (0..255) [default 120] + bytes 7-8: RSSI limiter threshold value (negative, MSB) [default 0] + byte 9: Scan and send cycle in seconds/2 (0..255) [default 120] byte 10: Wifi channel hopping interval in seconds/100 (0..255), 0 means no hopping [default 50] byte 11: Bluetooth channel switch interval in seconds/100 (0..255) [default 10] byte 12: Bluetooth scanner status (1=on, 0=0ff) [default 1] byte 13: Wifi antenna switch (0=internal, 1=external) [default 0] byte 14: 0 (reserved) byte 15: RGB LED luminosity (0..100 %) [default 30] - byte 16: Flags (Bitmask, 0..255) - byte 17: Payloadmask (Bitmask, 0..255, see rcommand 0x14) + byte 16: Payloadmask (Bitmask, 0..255, see rcommand 0x14) + byte 17: 0 (reserved) bytes 18-28: Software version (ASCII format, terminating with zero) From d21d478f8b6fa2838072e2e2bb826d6bdbfc71d2 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Mon, 24 Jan 2022 11:35:42 +0100 Subject: [PATCH 6/8] fix batt LEDlevel blinking --- src/power.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/power.cpp b/src/power.cpp index d9c4cccf..4ac70f4e 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -43,8 +43,14 @@ void AXP192_powerevent_IRQ(void) { ESP_LOGI(TAG, "Battery was removed."); if (pmu.isChargingIRQ()) ESP_LOGI(TAG, "Battery charging."); - if (pmu.isChargingDoneIRQ()) + if (pmu.isChargingDoneIRQ()) { ESP_LOGI(TAG, "Battery charging done."); +#ifdef PMU_LED_RUN_MODE + pmu.setChgLEDMode(PMU_LED_RUN_MODE); +#else + pmu.setChgLEDMode(AXP20X_LED_LOW_LEVEL); +#endif + } if (pmu.isBattTempLowIRQ()) ESP_LOGI(TAG, "Battery high temperature."); if (pmu.isBattTempHighIRQ()) From b63f466905c3afc9f36b7d36d7ec943061ed9493 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Mon, 21 Feb 2022 10:44:13 +0100 Subject: [PATCH 7/8] fix LORA preprocessor directives --- include/lorawan.h | 6 ++++- include/timekeeper.h | 4 ++- src/timekeeper.cpp | 64 +++++++++++++++++--------------------------- src/timesync.cpp | 10 ++++--- 4 files changed, 40 insertions(+), 44 deletions(-) diff --git a/include/lorawan.h b/include/lorawan.h index 394284be..0c870bb9 100644 --- a/include/lorawan.h +++ b/include/lorawan.h @@ -1,3 +1,5 @@ +#if (HAS_LORA) + #ifndef _LORAWAN_H #define _LORAWAN_H @@ -48,4 +50,6 @@ const char *getCrName(rps_t rps); void showLoraKeys(void); #endif // VERBOSE -#endif \ No newline at end of file +#endif + +#endif // HAS_LORA \ No newline at end of file diff --git a/include/timekeeper.h b/include/timekeeper.h index bb97a043..ee20913e 100644 --- a/include/timekeeper.h +++ b/include/timekeeper.h @@ -10,6 +10,8 @@ #include "dcf77.h" #include "esp_sntp.h" +#define HAS_LORA_TIME ((HAS_LORA) && ((TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN))) + #define SECS_YR_2000 (946684800UL) // the time at the start of y2k #define GPS_UTC_DIFF 315964800UL // seconds diff between gps and utc epoch #define LEAP_SECS_SINCE_GPSEPOCH 18UL // state of 2021 @@ -32,7 +34,7 @@ void setTimeSyncIRQ(void); uint8_t timepulse_init(void); bool timeIsValid(time_t const t); void calibrateTime(void); -void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec, +bool IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec, timesource_t mytimesource); time_t compileTime(void); time_t mkgmtime(const struct tm *ptm); diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index 6a4d2904..f2765bf7 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -1,13 +1,5 @@ #include "timekeeper.h" -#if !(HAS_LORA) -#if (TIME_SYNC_LORASERVER) -#error TIME_SYNC_LORASERVER defined, but device has no LORA configured -#elif (TIME_SYNC_LORAWAN) -#error TIME_SYNC_LORAWAN defined, but device has no LORA configured -#endif -#endif - #if (defined HAS_DCF77 && defined HAS_IF482) #error You must define at most one of IF482 or DCF77! #endif @@ -44,48 +36,38 @@ void calibrateTime(void) { time_t t = 0; uint16_t t_msec = 0; - // kick off asychronous lora timesync if we have -#if (HAS_LORA) && ((TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN)) + // kick off asynchronous lora timesync if we have +#if (HAS_LORA_TIME) timesync_request(); -#endif - - // if no LORA timesource is available, or if we lost time, then fallback to - // local time source RTS or GPS - if (((!TIME_SYNC_LORASERVER) && (!TIME_SYNC_LORAWAN)) || - (timeSource == _unsynced)) { - -// has RTC -> fallback to RTC time -#ifdef HAS_RTC - t = get_rtctime(&t_msec); - // set time from RTC - method will check if time is valid - setMyTime((uint32_t)t, t_msec, _rtc); -#endif - -// no RTC -> fallback to GPS time -#if (HAS_GPS) - t = get_gpstime(&t_msec); - // set time from GPS - method will check if time is valid - setMyTime((uint32_t)t, t_msec, _gps); -#endif - - } // fallback - - else - - // no fallback time source available -> we can't set time + if (timeSource == _lora) // did have lora time before? return; +#endif + +// get GPS time, if we have +#if (HAS_GPS) + t = get_gpstime(&t_msec); + if (setMyTime((uint32_t)t, t_msec, _gps)) + return; +#endif + +// fallback to RTC time, if we have +#ifdef HAS_RTC + t = get_rtctime(&t_msec); + if (setMyTime((uint32_t)t, t_msec, _rtc)) + return; +#endif } // calibrateTime() // set system time (UTC), calibrate RTC and RTC_INT pps -void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec, +bool IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec, timesource_t mytimesource) { struct timeval tv = {0}; // called with invalid timesource? if (mytimesource == _unsynced) - return; + return false; // increment t_sec if t_msec > 1000 time_t time_to_set = (time_t)(t_sec + t_msec / 1000); @@ -126,13 +108,17 @@ void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec, timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ); ESP_LOGD(TAG, "[%0.3f] Timesync finished, time was set | timesource=%d", _seconds(), mytimesource); + return true; + } else { + timesyncer.attach(TIME_SYNC_INTERVAL_RETRY * 60, setTimeSyncIRQ); ESP_LOGV(TAG, "[%0.3f] Failed to synchronise time from source %c | unix sec " "obtained from source: %d | unix sec at program compilation: %d", _seconds(), timeSetSymbols[mytimesource], time_to_set, compileTime()); + return false; } } @@ -172,7 +158,7 @@ uint8_t timepulse_init() { // use ESP32 hardware timer as time base for calendar time ppsIRQ = timerBegin(1, 8000, true); // set 80 MHz prescaler to 1/10000 sec timerAlarmWrite(ppsIRQ, 10000, true); // 1000ms - timerAttachInterrupt(ppsIRQ, &CLOCKIRQ, true); + timerAttachInterrupt(ppsIRQ, &CLOCKIRQ, false); timerAlarmEnable(ppsIRQ); ESP_LOGI(TAG, "Timepulse: internal (ESP32 hardware timer)"); return 1; // success diff --git a/src/timesync.cpp b/src/timesync.cpp index 9b2c5f99..80355eb8 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -13,6 +13,8 @@ accept this. */ +#if (HAS_LORA) + #if (TIME_SYNC_LORASERVER) && (TIME_SYNC_LORAWAN) #error Duplicate timesync method selected. You must select either LORASERVER or LORAWAN timesync. #endif @@ -173,7 +175,7 @@ void timesync_store(uint32_t timestamp, timesync_t timestamp_type) { // callback function to receive time answer from network or answer void IRAM_ATTR timesync_serverAnswer(void *pUserData, int flag) { -#if (TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN) +#if (HAS_LORA_TIME) // if no timesync handshake is pending then exit if (!timeSyncPending) @@ -277,5 +279,7 @@ Exit: xTaskNotify(timeSyncProcTask, (rc ? rcv_seqNo : TIME_SYNC_END_FLAG), eSetBits); -#endif // (TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN) -} \ No newline at end of file +#endif // (HAS_LORA_TIME) +} + +#endif // HAS_LORA \ No newline at end of file From 7f6cea2e0222c4bc950b38c4d64bb2706cb84cfc Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Mon, 21 Feb 2022 10:45:27 +0100 Subject: [PATCH 8/8] preparations for upgrade to arduino-espressif v2.x --- src/boot.cpp | 2 +- src/i2c.cpp | 7 +++++-- src/lmic_config.h | 3 +++ src/main.cpp | 8 ++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/boot.cpp b/src/boot.cpp index c4679a95..28202243 100644 --- a/src/boot.cpp +++ b/src/boot.cpp @@ -95,7 +95,7 @@ void start_boot_menu(void) { // setup watchdog, based on esp32 timer2 interrupt wdTimer = timerBegin(0, 80, true); // timer 0, div 80, countup - timerAttachInterrupt(wdTimer, &watchdog, true); // callback for device reset + timerAttachInterrupt(wdTimer, &watchdog, false); // callback for device reset timerAlarmWrite(wdTimer, BOOTDELAY * 1000000, false); // set time in us timerAlarmEnable(wdTimer); // enable watchdog diff --git a/src/i2c.cpp b/src/i2c.cpp index 2d882043..530dee4c 100644 --- a/src/i2c.cpp +++ b/src/i2c.cpp @@ -7,9 +7,12 @@ static const char TAG[] = __FILE__; SemaphoreHandle_t I2Caccess; -void i2c_init(void) { Wire.begin(MY_DISPLAY_SDA, MY_DISPLAY_SCL, 100000); } +void i2c_init(void) { + Wire.setPins(MY_DISPLAY_SDA, MY_DISPLAY_SCL); + Wire.begin(); +} -void i2c_deinit(void) { Wire.~TwoWire(); } +void i2c_deinit(void) { Wire.end(); } void i2c_scan(void) { diff --git a/src/lmic_config.h b/src/lmic_config.h index 51e40e9c..51c7b63f 100644 --- a/src/lmic_config.h +++ b/src/lmic_config.h @@ -1,5 +1,8 @@ // COUNTRY AND PROJECT SPECIFIC DEFINITIONS FOR LMIC STACK +// workaround for arduino-espressif32 v2.0.0 (see isse #714 @ MCCI_LMIC) +#define hal_init LMICHAL_init + // COUNTRY SETTINGS // --> please check with you local regulations for ISM band frequency use! diff --git a/src/main.cpp b/src/main.cpp index 2e20fb76..6292380e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -450,7 +450,7 @@ void setup() { // https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/ // prescaler 80 -> divides 80 MHz CPU freq to 1 MHz, timer 0, count up displayIRQ = timerBegin(0, 80, true); - timerAttachInterrupt(displayIRQ, &DisplayIRQ, true); + timerAttachInterrupt(displayIRQ, &DisplayIRQ, false); timerAlarmWrite(displayIRQ, DISPLAYREFRESH_MS * 1000, true); timerAlarmEnable(displayIRQ); #endif @@ -460,7 +460,7 @@ void setup() { // https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/ // prescaler 80 -> divides 80 MHz CPU freq to 1 MHz, timer 3, count up matrixDisplayIRQ = timerBegin(3, 80, true); - timerAttachInterrupt(matrixDisplayIRQ, &MatrixDisplayIRQ, true); + timerAttachInterrupt(matrixDisplayIRQ, &MatrixDisplayIRQ, false); timerAlarmWrite(matrixDisplayIRQ, MATRIX_DISPLAY_SCAN_US, true); timerAlarmEnable(matrixDisplayIRQ); #endif @@ -480,14 +480,14 @@ void setup() { cyclicTimer.attach(HOMECYCLE, setCyclicIRQ); // only if we have a timesource we do timesync -#if ((TIME_SYNC_LORAWAN) || (TIME_SYNC_LORASERVER) || (HAS_GPS) || (HAS_RTC)) +#if ((HAS_LORA_TIME) || (HAS_GPS) || (HAS_RTC)) #if (defined HAS_IF482 || defined HAS_DCF77) ESP_LOGI(TAG, "Starting Clock Controller..."); clock_init(); #endif -#if (TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN) +#if (HAS_LORA_TIME) timesync_init(); // create loraserver time sync task #endif