diff --git a/lib/arduino-lmic-1.5.0-arduino-2-tweaked/src/lmic/lmic.c b/lib/arduino-lmic-1.5.0-arduino-2-tweaked/src/lmic/lmic.c index c0c1bbc3..a6e42933 100644 --- a/lib/arduino-lmic-1.5.0-arduino-2-tweaked/src/lmic/lmic.c +++ b/lib/arduino-lmic-1.5.0-arduino-2-tweaked/src/lmic/lmic.c @@ -907,7 +907,7 @@ static ostime_t nextJoinState (void) { } else { LMIC.txChnl = os_getRndU1() & 0x3F; s1_t dr = DR_SF7 - ++LMIC.txCnt; - if( dr < DR_SF10 ) { + if( LMIC.txCnt > DR_SF7 ) { dr = DR_SF10; failed = 1; // All DR exhausted - signal failed } diff --git a/platformio.ini b/platformio.ini index 8e3d7397..014772e3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,7 +26,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.5.7 +release_version = 1.5.8 ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose debug_level = 0 diff --git a/src/battery.cpp b/src/battery.cpp index 11371748..0e894965 100644 --- a/src/battery.cpp +++ b/src/battery.cpp @@ -49,4 +49,9 @@ uint16_t read_voltage() { return voltage; } +bool batt_sufficient() { + uint16_t volts = read_voltage(); + return (( volts < 1000 ) || (volts > OTA_MIN_BATT)); // no battery or battery sufficient +} + #endif // HAS_BATTERY_PROBE \ No newline at end of file diff --git a/src/battery.h b/src/battery.h index 93696fb5..b4a83676 100644 --- a/src/battery.h +++ b/src/battery.h @@ -9,5 +9,6 @@ uint16_t read_voltage(void); void calibrate_voltage(void); +bool batt_sufficient(void); #endif diff --git a/src/hal/lopy.h b/src/hal/lopy.h index d8d678cb..545ac8ab 100644 --- a/src/hal/lopy.h +++ b/src/hal/lopy.h @@ -3,9 +3,7 @@ #define HAS_LORA 1 // comment out if device shall not send data via LoRa #define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1272_radio 1 -//#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED -#define HAS_LED GPIO_NUM_12 // use if LoPy is on Expansion Board, this has a user LED -#define LED_ACTIVE_LOW 1 // use if LoPy is on Expansion Board, this has a user LED +#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED #define HAS_RGB_LED GPIO_NUM_0 // WS2812B RGB LED on GPIO0 // Hardware pin definitions for Pycom LoPy board @@ -22,19 +20,16 @@ #define HAS_ANTENNA_SWITCH 16 // pin for switching wifi antenna #define WIFI_ANTENNA 0 // 0 = internal, 1 = external -// uncomment this only if your LoPy runs on a Pytrack expansion board with GPS -#define HAS_GPS 1 -#define GPS_QUECTEL_L76 GPIO_NUM_25, GPIO_NUM_26 // SDA (P22), SCL (P21) -#define GPS_ADDR 0x10 +// uncomment this only if your LoPy runs on a PYTRACK BOARD +//#define HAS_GPS 1 +//#define GPS_QUECTEL_L76 GPIO_NUM_25, GPIO_NUM_26 // SDA (P22), SCL (P21) +//#define GPS_ADDR 0x10 -// uncomment this only if your LoPy runs on a expansion board 3.0 +// uncomment this only if your LoPy runs on a EXPANSION BOARD +//#define HAS_LED GPIO_NUM_12 // use if LoPy is on Expansion Board, this has a user LED +//#define LED_ACTIVE_LOW 1 // use if LoPy is on Expansion Board, this has a user LED +//#define HAS_BUTTON GPIO_NUM_13 // user button on expansion board +//define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown //#define HAS_BATTERY_PROBE ADC1_GPIO39_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 -//#define BATT_FACTOR 2 // voltage divider 1MOhm/1MOhm on board -//#define HAS_BUTTON GPIO_NUM_13 // (P14) -//#define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown - -// uncomment this only if your LoPy runs on a expansion board 2.0 -//#define HAS_BATTERY_PROBE ADC1_GPIO39_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 -//#define BATT_FACTOR 4 // voltage divider 115kOhm/56kOhm on board -//#define HAS_BUTTON GPIO_NUM_13 // (P10) -//#define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown +//#define BATT_FACTOR 2 // voltage divider 1MOhm/1MOhm -> expansion board 3.0 +//#define BATT_FACTOR 4 // voltage divider 115kOhm/56kOhm -> expansion board 2.0 diff --git a/src/hal/lopy4.h b/src/hal/lopy4.h index 47f37f7f..cef619f0 100644 --- a/src/hal/lopy4.h +++ b/src/hal/lopy4.h @@ -1,11 +1,9 @@ -// Hardware related definitions for Pycom LoPy Board (not: LoPy4) +// Hardware related definitions for Pycom LoPy4 Board #define HAS_LORA 1 // comment out if device shall not send data via LoRa #define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 -//#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED -#define HAS_LED GPIO_NUM_12 // use if LoPy is on Expansion Board, this has a user LED -#define LED_ACTIVE_LOW 1 // use if LoPy is on Expansion Board, this has a user LED +#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED #define HAS_RGB_LED GPIO_NUM_0 // WS2812B RGB LED on GPIO0 #define BOARD_HAS_PSRAM // use extra 4MB extern RAM @@ -23,19 +21,16 @@ #define HAS_ANTENNA_SWITCH 21 // pin for switching wifi antenna #define WIFI_ANTENNA 0 // 0 = internal, 1 = external -// uncomment this only if your LoPy runs on a Pytrack expansion board with GPS +// uncomment this only if your LoPy runs on a PYTRACK BOARD //#define HAS_GPS 1 //#define GPS_QUECTEL_L76 GPIO_NUM_25, GPIO_NUM_26 // SDA (P22), SCL (P21) //#define GPS_ADDR 0x10 -// uncomment this only if your LoPy runs on a expansion board 3.0 -#define HAS_BATTERY_PROBE ADC1_GPIO39_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 -#define BATT_FACTOR 2 // voltage divider 1MOhm/1MOhm on board -#define HAS_BUTTON GPIO_NUM_13 // (P14) -#define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown - -// uncomment this only if your LoPy runs on a expansion board 2.0 +// uncomment this only if your LoPy runs on a EXPANSION BOARD +//#define HAS_LED GPIO_NUM_12 // use if LoPy is on Expansion Board, this has a user LED +//#define LED_ACTIVE_LOW 1 // use if LoPy is on Expansion Board, this has a user LED +//#define HAS_BUTTON GPIO_NUM_13 // user button on expansion board +//define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown //#define HAS_BATTERY_PROBE ADC1_GPIO39_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 -//#define BATT_FACTOR 4 // voltage divider 115kOhm/56kOhm on board -//#define HAS_BUTTON GPIO_NUM_13 // (P10) -//#define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown \ No newline at end of file +//#define BATT_FACTOR 2 // voltage divider 1MOhm/1MOhm -> expansion board 3.0 +//#define BATT_FACTOR 4 // voltage divider 115kOhm/56kOhm -> expansion board 2.0 \ No newline at end of file diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 26ef93a3..7f93c1e6 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -45,8 +45,8 @@ void gen_lora_deveui(uint8_t *pdeveui) { *p++ = dmac[5]; *p++ = dmac[4]; *p++ = dmac[3]; - *p++ = 0xff; *p++ = 0xfe; + *p++ = 0xff; *p++ = dmac[2]; *p++ = dmac[1]; *p++ = dmac[0]; @@ -247,9 +247,7 @@ void lorawan_loop(void *pvParameters) { configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check while (1) { - //vTaskSuspendAll(); os_runloop_once(); // execute LMIC jobs - //xTaskResumeAll(); vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU } } diff --git a/src/ota.cpp b/src/ota.cpp index 15ef87b5..bf826953 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -43,13 +43,15 @@ inline String getHeaderValue(String header, String headerName) { void start_ota_update() { +/* // check battery status if we can before doing ota #ifdef HAS_BATTERY_PROBE - if (batt_voltage < OTA_MIN_BATT) { + if (!batt_sufficient()) { ESP_LOGW(TAG, "Battery voltage %dmV too low for OTA", batt_voltage); return; } #endif +*/ // turn on LED #if (HAS_LED != NOT_A_PIN) diff --git a/src/ota.h b/src/ota.h index 59c1e464..135591ea 100644 --- a/src/ota.h +++ b/src/ota.h @@ -5,6 +5,7 @@ #include "globals.h" #include "update.h" +#include "battery.h" #include #include #include