From c4c817828e9200d54a5b032c0746d73181d72fa8 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 9 May 2020 12:22:29 +0200 Subject: [PATCH 01/26] T-Beam v10 chare current control added (#604) --- src/hal/ttgobeam10.h | 4 +++- src/power.cpp | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/hal/ttgobeam10.h b/src/hal/ttgobeam10.h index abebe0d5..49fb51d9 100644 --- a/src/hal/ttgobeam10.h +++ b/src/hal/ttgobeam10.h @@ -31,7 +31,9 @@ Reset -> reset device #define HAS_BUTTON GPIO_NUM_38 // middle on board button #define HAS_PMU 1 // AXP192 power management chip #define PMU_INT GPIO_NUM_35 // AXP192 interrupt - +#define PMU_CHGC AXP1XX_CHARGE_CUR_280MA // AXP102 battery charge current +// possible AXP192 battery charge current values (mA): +// 100/190/280/360/450/550/630/700/780/880/960/1000/1080/1160/1240/1320 #define HAS_LED NOT_A_PIN // GPS settings diff --git a/src/power.cpp b/src/power.cpp index 2c6012b5..7204b829 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -124,6 +124,11 @@ void AXP192_init(void) { pmu.setTimeOutShutdown(false); // no automatic shutdown pmu.setTSmode(AXP_TS_PIN_MODE_DISABLE); // TS pin mode off to save power +// set charge current according to user setting if we have +#ifdef PMU_CHGC + pmu.setChargeControlCur(PMU_CHGC); +#endif + // switch ADCs on pmu.adc1Enable(AXP202_BATT_VOL_ADC1, true); pmu.adc1Enable(AXP202_BATT_CUR_ADC1, true); From 2a7c020e1b611a20255643e356b787b4296dcb10 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 9 May 2020 13:41:19 +0200 Subject: [PATCH 02/26] do i2cscan earlier in main.cpp --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3d83ebce..b4b1ee5c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -193,6 +193,9 @@ void setup() { // read (and initialize on first run) runtime settings from NVRAM loadConfig(); // includes initialize if necessary + // now that we are powered, we scan i2c bus for devices + i2c_scan(); + // initialize display #ifdef HAS_DISPLAY strcat_P(features, " OLED"); @@ -201,9 +204,6 @@ void setup() { dp_init(RTC_runmode == RUNMODE_POWERCYCLE ? true : false); #endif - // scan i2c bus for devices - i2c_scan(); - #ifdef BOARD_HAS_PSRAM assert(psramFound()); ESP_LOGI(TAG, "PSRAM found and initialized"); From b2254540c2fcc66d600f395f59b352ae50ebbfe4 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 9 May 2020 13:42:08 +0200 Subject: [PATCH 03/26] AXP192 charge current user settings --- src/hal/ttgobeam10.h | 2 +- src/power.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/hal/ttgobeam10.h b/src/hal/ttgobeam10.h index 49fb51d9..e84279f2 100644 --- a/src/hal/ttgobeam10.h +++ b/src/hal/ttgobeam10.h @@ -31,7 +31,7 @@ Reset -> reset device #define HAS_BUTTON GPIO_NUM_38 // middle on board button #define HAS_PMU 1 // AXP192 power management chip #define PMU_INT GPIO_NUM_35 // AXP192 interrupt -#define PMU_CHGC AXP1XX_CHARGE_CUR_280MA // AXP102 battery charge current +#define PMU_CHGC AXP1XX_CHARGE_CUR_1000MA // AXP102 battery charge current // possible AXP192 battery charge current values (mA): // 100/190/280/360/450/550/630/700/780/880/960/1000/1080/1160/1240/1320 #define HAS_LED NOT_A_PIN diff --git a/src/power.cpp b/src/power.cpp index 7204b829..74324c5e 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -124,11 +124,6 @@ void AXP192_init(void) { pmu.setTimeOutShutdown(false); // no automatic shutdown pmu.setTSmode(AXP_TS_PIN_MODE_DISABLE); // TS pin mode off to save power -// set charge current according to user setting if we have -#ifdef PMU_CHGC - pmu.setChargeControlCur(PMU_CHGC); -#endif - // switch ADCs on pmu.adc1Enable(AXP202_BATT_VOL_ADC1, true); pmu.adc1Enable(AXP202_BATT_CUR_ADC1, true); @@ -148,6 +143,13 @@ void AXP192_init(void) { pmu.clearIRQ(); #endif // PMU_INT +// set charge current according to user setting if we have +#ifdef PMU_CHGC + pmu.setChargeControlCur(PMU_CHGC); + pmu.setChargingTargetVoltage(AXP202_TARGET_VOL_4_2V); + pmu.enableChargeing(true); +#endif + ESP_LOGI(TAG, "AXP192 PMU initialized"); } } From 62d28c54b653b228a38f77f82a188373f72f89aa Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 9 May 2020 22:48:29 +0200 Subject: [PATCH 04/26] charge current control added --- include/power.h | 20 ++++++++++++++++++++ src/main.cpp | 5 +++++ src/power.cpp | 28 ++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/include/power.h b/include/power.h index 795fbb87..d11235c0 100644 --- a/include/power.h +++ b/include/power.h @@ -18,6 +18,22 @@ #define BAT_MIN_VOLTAGE 3100 // millivolts #endif +#ifndef PMU_CHG_CUTOFF +#ifdef HAS_PMU +#define PMU_CHG_CUTOFF AXP202_TARGET_VOL_4_2V +#elif defined HAS_IP5306 +#define PMU_CHG_CUTOFF 0 +#endif +#endif + +#ifndef PMU_CHG_CURRENT +#ifdef HAS_PMU +#define PMU_CHG_CURRENT AXP1XX_CHARGE_CUR_450MA +#elif defined HAS_IP5306 +#define PMU_CHG_CURRENT 2 +#endif +#endif + typedef uint8_t (*mapFn_t)(uint16_t, uint16_t, uint16_t); uint16_t read_voltage(void); @@ -37,10 +53,14 @@ void AXP192_showstatus(void); #endif // HAS_PMU #ifdef HAS_IP5306 +void IP5306_init(void); void printIP5306Stats(void); uint8_t IP5306_GetPowerSource(void); uint8_t IP5306_GetBatteryLevel(void); uint8_t IP5306_GetBatteryFull(void); +void IP5306_SetChargerEnabled(uint8_t v); +void IP5306_SetChargeCutoffVoltage(uint8_t v); +void IP5306_SetEndChargeCurrentDetection(uint8_t v); #endif // The following map functions were taken from diff --git a/src/main.cpp b/src/main.cpp index b4b1ee5c..66d9c3cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -185,8 +185,13 @@ void setup() { digitalWrite(EXT_POWER_SW, EXT_POWER_ON); strcat_P(features, " VEXT"); #endif + +#if defined HAS_PMU || defined HAS_IP5306 #ifdef HAS_PMU AXP192_init(); +#elif defined HAS_IP5306 + IP5306_init(); +#endif strcat_P(features, " PMU"); #endif diff --git a/src/power.cpp b/src/power.cpp index 74324c5e..5d3d770e 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -143,10 +143,10 @@ void AXP192_init(void) { pmu.clearIRQ(); #endif // PMU_INT -// set charge current according to user setting if we have -#ifdef PMU_CHGC - pmu.setChargeControlCur(PMU_CHGC); - pmu.setChargingTargetVoltage(AXP202_TARGET_VOL_4_2V); +// set charging parameterss according to user settings if we have (see power.h) +#ifdef PMU_CHARGE_CURRENT + pmu.setChargeControlCur(PMU_CHARGE_CURRENT); + pmu.setChargingTargetVoltage(PMU_CHARGE_CUTOFF); pmu.enableChargeing(true); #endif @@ -299,6 +299,20 @@ uint8_t IP5306_GetBatteryLevel(void) { return IP5306_LEDS2PCT(state); } +void IP5306_SetChargerEnabled(uint8_t v) { + ip5306_set_bits(IP5306_REG_SYS_0, 4, 1, v); // 0:dis,*1:en +} + +void IP5306_SetChargeCutoffVoltage(uint8_t v) { + ip5306_set_bits(IP5306_REG_CHG_2, 2, 2, + v); //*0:4.2V, 1:4.3V, 2:4.35V, 3:4.4V +} + +void IP5306_SetEndChargeCurrentDetection(uint8_t v) { + ip5306_set_bits(IP5306_REG_CHG_1, 6, 2, + v); // 0:200mA, 1:400mA, *2:500mA, 3:600mA +} + void printIP5306Stats(void) { bool usb = IP5306_GetPowerSource(); bool full = IP5306_GetBatteryFull(); @@ -309,4 +323,10 @@ void printIP5306Stats(void) { full ? "CHARGED" : (usb ? "CHARGING" : "DISCHARGING"), level); } +void IP5306_init(void) { + IP5306_SetChargerEnabled(1); + IP5306_SetChargeCutoffVoltage(PMU_CHG_CUTOFF); + IP5306_SetEndChargeCurrentDetection(PMU_CHG_CURRENT); +} + #endif // HAS_IP5306 \ No newline at end of file From c7441ad58a34937be6e9ecb967674c4cdec7cc96 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 9 May 2020 22:49:00 +0200 Subject: [PATCH 05/26] display library select added --- build.py | 10 +++++++--- platformio.ini | 19 ++++++++++++------- src/hal/ecopower.h | 1 + src/hal/generic.h | 1 + src/hal/heltec.h | 1 + src/hal/heltecv2.h | 1 + src/hal/lolin32lora.h | 1 + src/hal/m5core.h | 8 +++++++- src/hal/m5fire.h | 8 +++++++- src/hal/octopus32.h | 1 + src/hal/ttgobeam.h | 1 + src/hal/ttgobeam10.h | 16 +++++++++++----- src/hal/ttgofox.h | 1 + src/hal/ttgov1.h | 1 + src/hal/ttgov2.h | 1 + src/hal/ttgov21new.h | 1 + src/hal/ttgov21old.h | 1 + src/hal/wemos32oled.h | 1 + 18 files changed, 57 insertions(+), 17 deletions(-) diff --git a/build.py b/build.py index c4f3ccc3..a3b3c13b 100644 --- a/build.py +++ b/build.py @@ -66,16 +66,20 @@ myboard = mykeys["board"] myuploadspeed = mykeys["upload_speed"] env.Replace(BOARD=myboard) env.Replace(UPLOAD_SPEED=myuploadspeed) +print('\033[94m' + "Target board: " + myboard + " @ " + myuploadspeed + "bps" + '\033[0m') # re-set partition table mypartitiontable = config.get("env", "board_build.partitions") board = env.BoardConfig(myboard) board.manifest['build']['partitions'] = mypartitiontable - -# display target -print('\033[94m' + "TARGET BOARD: " + myboard + " @ " + myuploadspeed + "bps" + '\033[0m') print('\033[94m' + "Partition table: " + mypartitiontable + '\033[0m') +# set display library +if "display_library" in mykeys: + mydisplay = mykeys["display_library"] + env.Append(display_library=mydisplay) + print('\033[94m' + "Display library: " + mydisplay + '\033[0m') + # parse ota key file with open(otakeyfile) as myfile: for line in myfile: diff --git a/platformio.ini b/platformio.ini index aab79dcf..93162009 100644 --- a/platformio.ini +++ b/platformio.ini @@ -45,7 +45,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.9.991 +release_version = 1.9.992 ; 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 = 3 @@ -55,15 +55,18 @@ lorakeyfile = loraconf.h lmicconfigfile = lmic_config.h platform_espressif32 = espressif32@1.12.1 monitor_speed = 115200 -upload_speed = 115200 +upload_speed = 115200 ; set by build.py and taken from hal file +display_library = ; set by build.py and taken from hal file lib_deps_lora = MCCI LoRaWAN LMIC library@3.1.0 ; MCCI LMIC by Terrill Moore lib_deps_display = + QRCode@0.0.1 +lib_deps_oled_display = ss_oled@4.1.3 ; fast and small OLED lib by Larry Bank BitBang_I2C@2.1.1 - QRCode@0.0.1 - TFT_eSPI@2.2.2 -lib_deps_matrix_display = +lib_deps_tft_display = + TFT_eSPI@2.2.4 +lib_deps_ledmatrix = Ultrathin_LED_Matrix@>=1.0.0 lib_deps_rgbled = SmartLeds@>=1.2.0 @@ -80,16 +83,18 @@ lib_deps_basic = 76@>=1.2.4 ; #76 Timezone by Jack Christensen 274@>=2.3.4 ; #274 RTC by Michael Miller SimpleButton - AXP202X_Library@>=1.1.0 ; AXP202 PMU lib by Lewis He + ;AXP202X_Library@>=1.1.0 ; AXP202 PMU lib by Lewis He + https://github.com/lewisxhe/AXP202X_Library.git esp32-micro-sdcard lib_deps_all = ${common.lib_deps_basic} ${common.lib_deps_lora} ${common.lib_deps_display} + ${common.display_library} ${common.lib_deps_rgbled} ${common.lib_deps_gps} ${common.lib_deps_sensors} - ${common.lib_deps_matrix_display} + ${common.lib_deps_ledmatrix} build_flags_basic = -include "src/hal/${board.halfile}" -include "src/paxcounter.conf" diff --git a/src/hal/ecopower.h b/src/hal/ecopower.h index 69a595d3..2ddab925 100644 --- a/src/hal/ecopower.h +++ b/src/hal/ecopower.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board esp32dev +// display_library lib_deps_oled_display #ifndef _GENERIC_H #define _GENERIC_H diff --git a/src/hal/generic.h b/src/hal/generic.h index 87be95f5..0010f69d 100644 --- a/src/hal/generic.h +++ b/src/hal/generic.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 115200 // board esp32dev +// display_library lib_deps_oled_display #ifndef _GENERIC_H #define _GENERIC_H diff --git a/src/hal/heltec.h b/src/hal/heltec.h index 6cea89f7..f85e7a8b 100644 --- a/src/hal/heltec.h +++ b/src/hal/heltec.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board heltec_wifi_lora_32 +// display_library lib_deps_oled_display #ifndef _HELTEC_H #define _HELTEC_H diff --git a/src/hal/heltecv2.h b/src/hal/heltecv2.h index c970f77e..91186f65 100644 --- a/src/hal/heltecv2.h +++ b/src/hal/heltecv2.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board heltec_wifi_lora_32_V2 +// display_library lib_deps_oled_display #ifndef _HELTECV2_H #define _HELTECV2_H diff --git a/src/hal/lolin32lora.h b/src/hal/lolin32lora.h index 15cdb331..69b183ad 100644 --- a/src/hal/lolin32lora.h +++ b/src/hal/lolin32lora.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board lolin32 +// display_library lib_deps_oled_display #ifndef _LOLINLORA_H #define _LOLINLORA_H diff --git a/src/hal/m5core.h b/src/hal/m5core.h index b391efe6..671bcc81 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board m5stack-core-esp32 +// display_library lib_deps_tft_display #ifndef _M5CORE_H #define _M5CORE_H @@ -38,7 +39,12 @@ #define HAS_LED NOT_A_PIN // no on board LED (?) #define HAS_BUTTON (39) // on board button A -#define HAS_IP5306 1 +// power management settings +#define HAS_IP5306 1 // has IP5306 chip +#define PMU_CHG_CURRENT 2 // battery charge current +// possible values: 0:200mA, 1:400mA, *2:500mA, 3:600mA +#define PMU_CHG_CUTOFF 0 // battery charge cutoff +// possible values: *0:4.2V, 1:4.3V, 2:4.35V, 3:4.4V // GPS settings #define HAS_GPS 1 // use on board GPS diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index 553493be..47805c97 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board m5stack-fire +// display_library lib_deps_tft_display #ifndef _M5FIRE_H #define _M5FIRE_H @@ -41,7 +42,12 @@ #define HAS_RGB_LED SmartLed rgb_led(LED_SK6812, RGB_LED_COUNT, GPIO_NUM_15) // LED_SK6812 RGB LED on GPIO15 #define HAS_BUTTON (39) // on board button A -#define HAS_IP5306 1 +// power management settings +#define HAS_IP5306 1 // has IP5306 chip +#define PMU_CHG_CURRENT 2 // battery charge current +// possible values: 0:200mA, 1:400mA, *2:500mA, 3:600mA +#define PMU_CHG_CUTOFF 0 // battery charge cutoff +// possible values: *0:4.2V, 1:4.3V, 2:4.35V, 3:4.4V // GPS settings #define HAS_GPS 0 // use on board GPS diff --git a/src/hal/octopus32.h b/src/hal/octopus32.h index b040b71f..eb648496 100644 --- a/src/hal/octopus32.h +++ b/src/hal/octopus32.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board featheresp32 +// display_library lib_deps_oled_display #ifndef _OCTOPUS_H #define _OCTOPUS_H diff --git a/src/hal/ttgobeam.h b/src/hal/ttgobeam.h index 7451a5b3..b317efda 100644 --- a/src/hal/ttgobeam.h +++ b/src/hal/ttgobeam.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board ttgo-t-beam +// display_library lib_deps_oled_display #ifndef _TTGOBEAM_H #define _TTGOBEAM_H diff --git a/src/hal/ttgobeam10.h b/src/hal/ttgobeam10.h index e84279f2..d9432942 100644 --- a/src/hal/ttgobeam10.h +++ b/src/hal/ttgobeam10.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board ttgo-t-beam +// display_library lib_deps_oled_display #ifndef _TTGOBEAM_H #define _TTGOBEAM_H @@ -29,13 +30,18 @@ Reset -> reset device #define HAS_LORA 1 // comment out if device shall not send data via LoRa #define CFG_sx1276_radio 1 // HPD13A LoRa SoC #define HAS_BUTTON GPIO_NUM_38 // middle on board button -#define HAS_PMU 1 // AXP192 power management chip -#define PMU_INT GPIO_NUM_35 // AXP192 interrupt -#define PMU_CHGC AXP1XX_CHARGE_CUR_1000MA // AXP102 battery charge current -// possible AXP192 battery charge current values (mA): -// 100/190/280/360/450/550/630/700/780/880/960/1000/1080/1160/1240/1320 #define HAS_LED NOT_A_PIN +// power management settings +#define HAS_PMU 1 // has AXP192 chip +#define PMU_INT GPIO_NUM_35 // battery interrupt +#define PMU_CHG_CURRENT AXP1XX_CHARGE_CUR_1000MA // battery charge current +// possible values (mA): +// 100/190/280/360/450/550/630/700/780/880/960/1000/1080/1160/1240/1320 +#define PMU_CHG_CUTOFF AXP202_TARGET_VOL_4_2V // battery charge cutoff +// possible values (V): +// 4_1/4_15/4_2/4_36 + // GPS settings #define HAS_GPS 1 // use on board GPS #define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_34, GPIO_NUM_12 // UBlox NEO 6M diff --git a/src/hal/ttgofox.h b/src/hal/ttgofox.h index d61460a8..a72d38de 100644 --- a/src/hal/ttgofox.h +++ b/src/hal/ttgofox.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board esp32dev +// display_library lib_deps_oled_display #ifndef _TTGOFOX_H #define _TTGOFOX_H diff --git a/src/hal/ttgov1.h b/src/hal/ttgov1.h index bdf42be6..4189035b 100644 --- a/src/hal/ttgov1.h +++ b/src/hal/ttgov1.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 115200 // board ttgo-lora32-v1 +// display_library lib_deps_oled_display #ifndef _TTGOV1_H #define _TTGOV1_H diff --git a/src/hal/ttgov2.h b/src/hal/ttgov2.h index 37d58359..9374c48e 100644 --- a/src/hal/ttgov2.h +++ b/src/hal/ttgov2.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board ttgo-lora32-v1 +// display_library lib_deps_oled_display #ifndef _TTGOV2_H #define _TTGOV2_H diff --git a/src/hal/ttgov21new.h b/src/hal/ttgov21new.h index 309acd2d..c7ef6e51 100644 --- a/src/hal/ttgov21new.h +++ b/src/hal/ttgov21new.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board esp32dev +// display_library lib_deps_oled_display #ifndef _TTGOV21NEW_H #define _TTGOV21NEW_H diff --git a/src/hal/ttgov21old.h b/src/hal/ttgov21old.h index 5ac72589..547059fb 100644 --- a/src/hal/ttgov21old.h +++ b/src/hal/ttgov21old.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board esp32dev +// display_library lib_deps_oled_display #ifndef _TTGOV21OLD_H #define _TTGOV21OLD_H diff --git a/src/hal/wemos32oled.h b/src/hal/wemos32oled.h index 1ad3cb28..66c74e37 100644 --- a/src/hal/wemos32oled.h +++ b/src/hal/wemos32oled.h @@ -1,6 +1,7 @@ // clang-format off // upload_speed 921600 // board lolin32 +// display_library lib_deps_oled_display #ifndef _WEMOS32OLED_H #define _WEMOS32OLED_H From cdf60c6df94ac38a4cbfb0cf9b1ad82e305b92af Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 9 May 2020 23:38:51 +0200 Subject: [PATCH 06/26] changed ssoled to OneBitDisplay library --- include/display.h | 2 +- src/display.cpp | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/display.h b/include/display.h index c6b39033..b5219a32 100644 --- a/include/display.h +++ b/include/display.h @@ -5,7 +5,7 @@ #include "qrcode.h" #if (HAS_DISPLAY) == 1 -#include +#include #elif (HAS_DISPLAY) == 2 #include #endif diff --git a/src/display.cpp b/src/display.cpp index 732b3063..134962a3 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -50,7 +50,7 @@ static int dp_row = 0, dp_col = 0, dp_font = 0; QRCode qrcode; #if (HAS_DISPLAY) == 1 -SSOLED ssoled; +OBDISP ssoled; #elif (HAS_DISPLAY) == 2 TFT_eSPI tft = TFT_eSPI(); #endif @@ -58,15 +58,16 @@ TFT_eSPI tft = TFT_eSPI(); void dp_setup(int contrast) { #if (HAS_DISPLAY) == 1 // I2C OLED - int rc = oledInit(&ssoled, OLED_TYPE, OLED_ADDR, MY_DISPLAY_FLIP, - MY_DISPLAY_INVERT, USE_HW_I2C, MY_DISPLAY_SDA, - MY_DISPLAY_SCL, MY_DISPLAY_RST, - OLED_FREQUENCY); // use standard I2C bus at 400Khz + + int rc = obdI2CInit(&ssoled, OLED_TYPE, OLED_ADDR, MY_DISPLAY_FLIP, + MY_DISPLAY_INVERT, USE_HW_I2C, MY_DISPLAY_SDA, + MY_DISPLAY_SCL, MY_DISPLAY_RST, + OLED_FREQUENCY); // use standard I2C bus at 400Khz assert(rc != OLED_NOT_FOUND); // set display buffer - oledSetBackBuffer(&ssoled, displaybuf); - oledSetTextWrap(&ssoled, true); + obdSetBackBuffer(&ssoled, displaybuf); + obdSetTextWrap(&ssoled, true); dp_font = MY_FONT_NORMAL; #elif (HAS_DISPLAY) == 2 // SPI TFT @@ -466,7 +467,7 @@ void dp_setTextCursor(int x, int y) { #if (HAS_DISPLAY) == 1 dp_row = y; - oledSetCursor(&ssoled, dp_col, dp_row); + obdSetCursor(&ssoled, dp_col, dp_row); #elif (HAS_DISPLAY) == 2 switch (dp_font >> 1) { @@ -538,8 +539,8 @@ void dp_printf(const char *format, ...) { } va_end(arg); #if (HAS_DISPLAY) == 1 - oledWriteString(&ssoled, 0, -1, dp_row, temp, dp_font >> 1, dp_font & 0x01, - false); + obdWriteString(&ssoled, 0, -1, dp_row, temp, dp_font >> 1, dp_font & 0x01, + false); #elif (HAS_DISPLAY) == 2 tft.printf(temp); #endif @@ -550,7 +551,7 @@ void dp_printf(const char *format, ...) { void dp_dump(uint8_t *pBuffer) { #if (HAS_DISPLAY) == 1 - oledDumpBuffer(&ssoled, pBuffer); + obdDumpBuffer(&ssoled, pBuffer); #elif (HAS_DISPLAY) == 2 // probably oled buffer stucture is not suitable for tft -> to be checked tft.drawBitmap(0, 0, pBuffer, MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT, @@ -561,7 +562,7 @@ void dp_dump(uint8_t *pBuffer) { void dp_clear(void) { dp_setTextCursor(0, 0); #if (HAS_DISPLAY) == 1 - oledFill(&ssoled, 0, 1); + obdFill(&ssoled, 0, 1); #elif (HAS_DISPLAY) == 2 tft.fillScreen(MY_DISPLAY_BGCOLOR); #endif @@ -569,7 +570,7 @@ void dp_clear(void) { void dp_contrast(uint8_t contrast) { #if (HAS_DISPLAY) == 1 - oledSetContrast(&ssoled, contrast); + obdSetContrast(&ssoled, contrast); #elif (HAS_DISPLAY) == 2 // to do: gamma correction for TFT #endif @@ -577,7 +578,7 @@ void dp_contrast(uint8_t contrast) { void dp_power(uint8_t screenon) { #if (HAS_DISPLAY) == 1 - oledPower(&ssoled, screenon); + obdPower(&ssoled, screenon); #elif (HAS_DISPLAY) == 2 // to come #endif @@ -590,7 +591,7 @@ void dp_shutdown(void) { ESP_LOGV(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0); else { cfg.screenon = 0; - oledPower(&ssoled, false); + obdPower(&ssoled, false); delay(DISPLAYREFRESH_MS / 1000 * 1.1); I2C_MUTEX_UNLOCK(); // release i2c bus access } @@ -630,7 +631,7 @@ void dp_fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t bRender) { #if (HAS_DISPLAY) == 1 for (uint16_t xi = x; xi < x + width; xi++) - oledDrawLine(&ssoled, xi, y, xi, y + height - 1, bRender); + obdDrawLine(&ssoled, xi, y, xi, y + height - 1, 1, bRender); #elif (HAS_DISPLAY) == 2 tft.fillRect(x, y, width, height, MY_DISPLAY_FGCOLOR); #endif From cfb40d300c8e73b408958bf26b7bbe0bff1c3bec Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 15 May 2020 18:00:07 +0200 Subject: [PATCH 07/26] new board olimex-poe added --- platformio.ini | 12 +++++++----- src/hal/olimexpoe.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 src/hal/olimexpoe.h diff --git a/platformio.ini b/platformio.ini index 93162009..34c6426e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -33,6 +33,7 @@ halfile = generic.h ;halfile = tinypicomatrix.h ;halfile = m5core.h ;halfile = m5fire.h +;halfile = olimexpoe.h [platformio] ; upload firmware to board with usb cable @@ -58,11 +59,13 @@ monitor_speed = 115200 upload_speed = 115200 ; set by build.py and taken from hal file display_library = ; set by build.py and taken from hal file lib_deps_lora = - MCCI LoRaWAN LMIC library@3.1.0 ; MCCI LMIC by Terrill Moore + https://github.com/mcci-catena/arduino-lmic.git + ;MCCI LoRaWAN LMIC library@3.1.0 ; MCCI LMIC by Terrill Moore lib_deps_display = + OneBitDisplay@1.3.0 QRCode@0.0.1 lib_deps_oled_display = - ss_oled@4.1.3 ; fast and small OLED lib by Larry Bank + OneBitDisplay@1.3.0 BitBang_I2C@2.1.1 lib_deps_tft_display = TFT_eSPI@2.2.4 @@ -83,8 +86,7 @@ lib_deps_basic = 76@>=1.2.4 ; #76 Timezone by Jack Christensen 274@>=2.3.4 ; #274 RTC by Michael Miller SimpleButton - ;AXP202X_Library@>=1.1.0 ; AXP202 PMU lib by Lewis He - https://github.com/lewisxhe/AXP202X_Library.git + AXP202X_Library@>=1.1.1 ; AXP202 PMU lib by Lewis He esp32-micro-sdcard lib_deps_all = ${common.lib_deps_basic} @@ -115,7 +117,7 @@ framework = arduino board = esp32dev board_build.partitions = min_spiffs.csv upload_speed = ${common.upload_speed} -;upload_port = COM5 +;upload_port = COM8 platform = ${common.platform_espressif32} lib_deps = ${common.lib_deps_all} build_flags = ${common.build_flags_all} diff --git a/src/hal/olimexpoe.h b/src/hal/olimexpoe.h new file mode 100644 index 00000000..c5191c67 --- /dev/null +++ b/src/hal/olimexpoe.h @@ -0,0 +1,40 @@ +// clang-format off +// upload_speed 921600 +// board esp32dev +// display_library lib_deps_oled_display + +#ifndef _GENERIC_H +#define _GENERIC_H + +#include + +// i2c bus definitions +#define MY_DISPLAY_SDA (13) +#define MY_DISPLAY_SCL (16) + +// enable only if you want to store a local paxcount table on the device +#define HAS_SDCARD 1 // this board has an SD-card-reader/writer +// Pins for SD-card +#define SDCARD_CS (13) +#define SDCARD_MOSI (15) +#define SDCARD_MISO (2) +#define SDCARD_SCLK (14) + +// user defined sensors +#define HAS_SENSORS 1 // comment out if device has user defined sensors + +//#define BOARD_HAS_PSRAM // use if board has external PSRAM +#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature + +//#define BAT_MEASURE_ADC ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 +#define BAT_MEASURE_ADC ADC1_GPIO39_CHANNEL // external power probe GPIO pin +#define BAT_VOLTAGE_DIVIDER 2.1277f // voltage divider 47k/442k on board + +#define EXT_POWER_SW GPIO_NUM_12 // switches PoE power, Vext control 0 = off / 1 = on +#define EXT_POWER_ON 1 +//#define EXT_POWER_OFF 1 + +#define HAS_BUTTON (34) // on board button +#define HAS_LED NOT_A_PIN // no on board LED + +#endif From 2b46a69dbe981332f176289f1a176b530fbd53cb Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 15 May 2020 18:30:21 +0200 Subject: [PATCH 08/26] revert display lib driver handling & update lmic --- platformio.ini | 10 +++------- src/hal/ecopower.h | 1 - src/hal/heltec.h | 1 - src/hal/heltecv2.h | 1 - src/hal/lolin32lora.h | 1 - src/hal/m5core.h | 3 +-- src/hal/m5fire.h | 1 - src/hal/octopus32.h | 1 - src/hal/olimexpoe.h | 1 - src/hal/ttgobeam.h | 1 - src/hal/ttgobeam10.h | 1 - src/hal/ttgofox.h | 1 - src/hal/ttgov1.h | 1 - src/hal/ttgov2.h | 1 - src/hal/ttgov21new.h | 1 - src/hal/ttgov21old.h | 1 - src/hal/wemos32oled.h | 1 - 17 files changed, 4 insertions(+), 24 deletions(-) diff --git a/platformio.ini b/platformio.ini index 34c6426e..40015f00 100644 --- a/platformio.ini +++ b/platformio.ini @@ -59,16 +59,13 @@ monitor_speed = 115200 upload_speed = 115200 ; set by build.py and taken from hal file display_library = ; set by build.py and taken from hal file lib_deps_lora = - https://github.com/mcci-catena/arduino-lmic.git - ;MCCI LoRaWAN LMIC library@3.1.0 ; MCCI LMIC by Terrill Moore + MCCI LoRaWAN LMIC library@3.2.0 ; MCCI LMIC by Terrill Moore lib_deps_display = OneBitDisplay@1.3.0 QRCode@0.0.1 -lib_deps_oled_display = - OneBitDisplay@1.3.0 BitBang_I2C@2.1.1 -lib_deps_tft_display = - TFT_eSPI@2.2.4 + ;TFT_eSPI@2.2.6 + https://github.com/Bodmer/TFT_eSPI.git lib_deps_ledmatrix = Ultrathin_LED_Matrix@>=1.0.0 lib_deps_rgbled = @@ -92,7 +89,6 @@ lib_deps_all = ${common.lib_deps_basic} ${common.lib_deps_lora} ${common.lib_deps_display} - ${common.display_library} ${common.lib_deps_rgbled} ${common.lib_deps_gps} ${common.lib_deps_sensors} diff --git a/src/hal/ecopower.h b/src/hal/ecopower.h index 2ddab925..69a595d3 100644 --- a/src/hal/ecopower.h +++ b/src/hal/ecopower.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board esp32dev -// display_library lib_deps_oled_display #ifndef _GENERIC_H #define _GENERIC_H diff --git a/src/hal/heltec.h b/src/hal/heltec.h index f85e7a8b..6cea89f7 100644 --- a/src/hal/heltec.h +++ b/src/hal/heltec.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board heltec_wifi_lora_32 -// display_library lib_deps_oled_display #ifndef _HELTEC_H #define _HELTEC_H diff --git a/src/hal/heltecv2.h b/src/hal/heltecv2.h index 91186f65..c970f77e 100644 --- a/src/hal/heltecv2.h +++ b/src/hal/heltecv2.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board heltec_wifi_lora_32_V2 -// display_library lib_deps_oled_display #ifndef _HELTECV2_H #define _HELTECV2_H diff --git a/src/hal/lolin32lora.h b/src/hal/lolin32lora.h index 69b183ad..15cdb331 100644 --- a/src/hal/lolin32lora.h +++ b/src/hal/lolin32lora.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board lolin32 -// display_library lib_deps_oled_display #ifndef _LOLINLORA_H #define _LOLINLORA_H diff --git a/src/hal/m5core.h b/src/hal/m5core.h index 671bcc81..fb69cf3a 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board m5stack-core-esp32 -// display_library lib_deps_tft_display #ifndef _M5CORE_H #define _M5CORE_H @@ -30,7 +29,7 @@ //#define HAS_SENSORS 1 // comment out if device has user defined sensors #define CFG_sx1276_radio 1 // select LoRa chip -#define BOARD_HAS_PSRAM // use if board has external PSRAM +//#define BOARD_HAS_PSRAM // use if board has external PSRAM #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature #define HAS_DISPLAY 2 // TFT-LCD, support work in progess, not ready yet diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index 47805c97..9572f6bf 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board m5stack-fire -// display_library lib_deps_tft_display #ifndef _M5FIRE_H #define _M5FIRE_H diff --git a/src/hal/octopus32.h b/src/hal/octopus32.h index eb648496..b040b71f 100644 --- a/src/hal/octopus32.h +++ b/src/hal/octopus32.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board featheresp32 -// display_library lib_deps_oled_display #ifndef _OCTOPUS_H #define _OCTOPUS_H diff --git a/src/hal/olimexpoe.h b/src/hal/olimexpoe.h index c5191c67..62edcd3a 100644 --- a/src/hal/olimexpoe.h +++ b/src/hal/olimexpoe.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board esp32dev -// display_library lib_deps_oled_display #ifndef _GENERIC_H #define _GENERIC_H diff --git a/src/hal/ttgobeam.h b/src/hal/ttgobeam.h index b317efda..7451a5b3 100644 --- a/src/hal/ttgobeam.h +++ b/src/hal/ttgobeam.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board ttgo-t-beam -// display_library lib_deps_oled_display #ifndef _TTGOBEAM_H #define _TTGOBEAM_H diff --git a/src/hal/ttgobeam10.h b/src/hal/ttgobeam10.h index d9432942..73e72dde 100644 --- a/src/hal/ttgobeam10.h +++ b/src/hal/ttgobeam10.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board ttgo-t-beam -// display_library lib_deps_oled_display #ifndef _TTGOBEAM_H #define _TTGOBEAM_H diff --git a/src/hal/ttgofox.h b/src/hal/ttgofox.h index a72d38de..d61460a8 100644 --- a/src/hal/ttgofox.h +++ b/src/hal/ttgofox.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board esp32dev -// display_library lib_deps_oled_display #ifndef _TTGOFOX_H #define _TTGOFOX_H diff --git a/src/hal/ttgov1.h b/src/hal/ttgov1.h index 4189035b..bdf42be6 100644 --- a/src/hal/ttgov1.h +++ b/src/hal/ttgov1.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 115200 // board ttgo-lora32-v1 -// display_library lib_deps_oled_display #ifndef _TTGOV1_H #define _TTGOV1_H diff --git a/src/hal/ttgov2.h b/src/hal/ttgov2.h index 9374c48e..37d58359 100644 --- a/src/hal/ttgov2.h +++ b/src/hal/ttgov2.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board ttgo-lora32-v1 -// display_library lib_deps_oled_display #ifndef _TTGOV2_H #define _TTGOV2_H diff --git a/src/hal/ttgov21new.h b/src/hal/ttgov21new.h index c7ef6e51..309acd2d 100644 --- a/src/hal/ttgov21new.h +++ b/src/hal/ttgov21new.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board esp32dev -// display_library lib_deps_oled_display #ifndef _TTGOV21NEW_H #define _TTGOV21NEW_H diff --git a/src/hal/ttgov21old.h b/src/hal/ttgov21old.h index 547059fb..5ac72589 100644 --- a/src/hal/ttgov21old.h +++ b/src/hal/ttgov21old.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board esp32dev -// display_library lib_deps_oled_display #ifndef _TTGOV21OLD_H #define _TTGOV21OLD_H diff --git a/src/hal/wemos32oled.h b/src/hal/wemos32oled.h index 66c74e37..1ad3cb28 100644 --- a/src/hal/wemos32oled.h +++ b/src/hal/wemos32oled.h @@ -1,7 +1,6 @@ // clang-format off // upload_speed 921600 // board lolin32 -// display_library lib_deps_oled_display #ifndef _WEMOS32OLED_H #define _WEMOS32OLED_H From 6e487983b55190722eac417b3cd33cd43a4177b6 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 16 May 2020 15:30:05 +0200 Subject: [PATCH 09/26] SD card reader native mode added --- README.md | 5 ++++- include/sdcard.h | 31 +++++++++++++++++++++++++++---- src/sdcard.cpp | 27 +++++++++++++++++++++++---- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7d0a8c15..864cee17 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,10 @@ There in the sensor configuration select "TheThingsNetwork" and set Decoding Pro # SD-card Data can be stored on an SD-card if one is availabe. Simply choose the file in src/hal and add the following lines to your hal-file: - #define HAS_SDCARD 1 // this board has an SD-card-reader/writer + #define HAS_SDCARD 1 // this board has an SD-card-reader/writer, with SPI interface + OR + #define HAS_SDCARD 2 // this board has an SD-card-reader/writer, using native SD interface + // Pins for SD-card #define SDCARD_CS (13) // fill in the correct numbers for your board #define SDCARD_MOSI (15) diff --git a/include/sdcard.h b/include/sdcard.h index 4323c6a3..8157bb32 100644 --- a/include/sdcard.h +++ b/include/sdcard.h @@ -4,14 +4,37 @@ #include #include #include + +#if HAS_SDCARD == 1 #include +#elif HAS_SDCARD == 2 +#include +#else +#error HAS_SDCARD unknown card reader value, must be either 1 or 2 +#endif #include "sds011read.h" -#define SDCARD_FILE_NAME "paxcount.%02d" -#define SDCARD_FILE_HEADER "date, time, wifi, bluet" +#ifndef SDCARD_CS +#define SDCARD_CS SS +#endif -bool sdcard_init( void ); -void sdcardWriteData( uint16_t, uint16_t); +#ifndef SDCARD_MOSI +#define SDCARD_MOSI MOSI +#endif + +#ifndef SDCARD_MISO +#define SDCARD_MISO MISO +#endif + +#ifndef SDCARD_SCLK +#define SDCARD_SCLK SCK +#endif + +#define SDCARD_FILE_NAME "/paxcount.%02d" +#define SDCARD_FILE_HEADER "date, time, wifi, bluet" + +bool sdcard_init(void); +void sdcardWriteData(uint16_t, uint16_t); #endif diff --git a/src/sdcard.cpp b/src/sdcard.cpp index 5faab5cd..3b573c70 100644 --- a/src/sdcard.cpp +++ b/src/sdcard.cpp @@ -14,12 +14,19 @@ static void createFile(void); File fileSDCard; bool sdcard_init() { - ESP_LOGD(TAG, "looking for SD-card..."); + ESP_LOGI(TAG, "looking for SD-card..."); +#if HAS_SDCARD == 1 + pinMode(SS, OUTPUT); useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK); - if (useSDCard) +#elif HAS_SDCARD == 2 + useSDCard = SD_MMC.begin(); +#endif + + if (useSDCard) { + ESP_LOGI(TAG, "SD-card found"); createFile(); - else - ESP_LOGD(TAG, "SD-card not found"); + } else + ESP_LOGI(TAG, "SD-card not found"); return useSDCard; } @@ -64,10 +71,22 @@ void createFile(void) { for (int i = 0; i < 100; i++) { sprintf(bufferFilename, SDCARD_FILE_NAME, i); ESP_LOGD(TAG, "SD: looking for file <%s>", bufferFilename); + +#if HAS_SDCARD == 1 bool fileExists = SD.exists(bufferFilename); +#elif HAS_SDCARD == 2 + bool fileExists = SD_MMC.exists(bufferFilename); +#endif + if (!fileExists) { ESP_LOGD(TAG, "SD: file does not exist: opening"); + +#if HAS_SDCARD == 1 fileSDCard = SD.open(bufferFilename, FILE_WRITE); +#elif HAS_SDCARD == 2 + fileSDCard = SD_MMC.open(bufferFilename, FILE_WRITE); +#endif + if (fileSDCard) { ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename); fileSDCard.print(SDCARD_FILE_HEADER); From 011dc171c1dfb77a1e08a3be35397e912926a094 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 16 May 2020 15:30:45 +0200 Subject: [PATCH 10/26] olimexpoe hal file updated --- src/hal/{olimexpoe.h => olimexpoeiso.h} | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) rename src/hal/{olimexpoe.h => olimexpoeiso.h} (55%) diff --git a/src/hal/olimexpoe.h b/src/hal/olimexpoeiso.h similarity index 55% rename from src/hal/olimexpoe.h rename to src/hal/olimexpoeiso.h index 62edcd3a..8035a887 100644 --- a/src/hal/olimexpoe.h +++ b/src/hal/olimexpoeiso.h @@ -1,28 +1,15 @@ // clang-format off // upload_speed 921600 -// board esp32dev +// board esp32-poe-iso -#ifndef _GENERIC_H -#define _GENERIC_H +#ifndef _OLIMEXPOEISO_H +#define _OLIMEXPOEISO_H #include -// i2c bus definitions -#define MY_DISPLAY_SDA (13) -#define MY_DISPLAY_SCL (16) - // enable only if you want to store a local paxcount table on the device -#define HAS_SDCARD 1 // this board has an SD-card-reader/writer -// Pins for SD-card -#define SDCARD_CS (13) -#define SDCARD_MOSI (15) -#define SDCARD_MISO (2) -#define SDCARD_SCLK (14) +#define HAS_SDCARD 2 // this board has an SD-card-reader/writer -// user defined sensors -#define HAS_SENSORS 1 // comment out if device has user defined sensors - -//#define BOARD_HAS_PSRAM // use if board has external PSRAM #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature //#define BAT_MEASURE_ADC ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 @@ -33,7 +20,7 @@ #define EXT_POWER_ON 1 //#define EXT_POWER_OFF 1 -#define HAS_BUTTON (34) // on board button +#define HAS_BUTTON KEY_BUILTIN // on board button #define HAS_LED NOT_A_PIN // no on board LED #endif From 10616ffc52d3dbe6a89306279f41d56d712208ec Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 16 May 2020 18:01:00 +0200 Subject: [PATCH 11/26] sdcard fix --- README.md | 4 ++-- src/sdcard.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 864cee17..474a7bc1 100644 --- a/README.md +++ b/README.md @@ -207,9 +207,9 @@ There in the sensor configuration select "TheThingsNetwork" and set Decoding Pro # SD-card Data can be stored on an SD-card if one is availabe. Simply choose the file in src/hal and add the following lines to your hal-file: - #define HAS_SDCARD 1 // this board has an SD-card-reader/writer, with SPI interface + #define HAS_SDCARD 1 // SD-card-reader/writer, using SPI interface OR - #define HAS_SDCARD 2 // this board has an SD-card-reader/writer, using native SD interface + #define HAS_SDCARD 2 // SD-card-reader/writer, using SDMMC interface // Pins for SD-card #define SDCARD_CS (13) // fill in the correct numbers for your board diff --git a/src/sdcard.cpp b/src/sdcard.cpp index 3b573c70..cd6b8618 100644 --- a/src/sdcard.cpp +++ b/src/sdcard.cpp @@ -16,7 +16,7 @@ File fileSDCard; bool sdcard_init() { ESP_LOGI(TAG, "looking for SD-card..."); #if HAS_SDCARD == 1 - pinMode(SS, OUTPUT); + pinMode(SDCARD_CS, OUTPUT); useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK); #elif HAS_SDCARD == 2 useSDCard = SD_MMC.begin(); From 73ee2df3d4ad437b8da099126d28a9f42500a307 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 16 May 2020 23:49:34 +0200 Subject: [PATCH 12/26] Ethernet MQTT client (experimental) --- include/mqttclient.h | 23 +++++++ include/senddata.h | 1 + src/hal/olimexpoeiso.h | 8 +-- src/main.cpp | 6 ++ src/mqttclient.cpp | 134 +++++++++++++++++++++++++++++++++++++++++ src/senddata.cpp | 6 ++ 6 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 include/mqttclient.h create mode 100644 src/mqttclient.cpp diff --git a/include/mqttclient.h b/include/mqttclient.h new file mode 100644 index 00000000..28013301 --- /dev/null +++ b/include/mqttclient.h @@ -0,0 +1,23 @@ +#ifndef _MQTTCLIENT_H +#define _MQTTCLIENT_H + +#include "globals.h" +#include "rcommand.h" +#include +#include + +#define MQTT_NAME "paxcounter" +#define MQTT_INTOPIC "rcommand" +#define MQTT_PORT 1883 + +extern TaskHandle_t mqttTask; + +void mqtt_enqueuedata(MessageBuffer_t *message); +void mqtt_queuereset(void); +void mqtt_client_task(void *param); +void mqtt_connect(IPAddress mqtt_host, uint16_t mqtt_port); +void mqtt_callback(char *topic, byte *payload, unsigned int length); +void WiFiEvent(WiFiEvent_t event); +esp_err_t mqtt_init(void); + +#endif // _MQTTCLIENT_H \ No newline at end of file diff --git a/include/senddata.h b/include/senddata.h index 7be85016..fd31f884 100644 --- a/include/senddata.h +++ b/include/senddata.h @@ -2,6 +2,7 @@ #define _SENDDATA_H #include "spislave.h" +#include "mqttclient.h" #include "cyclic.h" #include "sensor.h" #include "lorawan.h" diff --git a/src/hal/olimexpoeiso.h b/src/hal/olimexpoeiso.h index 8035a887..227473f9 100644 --- a/src/hal/olimexpoeiso.h +++ b/src/hal/olimexpoeiso.h @@ -10,16 +10,16 @@ // enable only if you want to store a local paxcount table on the device #define HAS_SDCARD 2 // this board has an SD-card-reader/writer +// enable only if you want to send paxcount via ethernet port to mqtt server +#define HAS_MQTT 1 // use MQTT on ethernet interface + #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature //#define BAT_MEASURE_ADC ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 +//#define BAT_VOLTAGE_DIVIDER 2 // voltage divider 470k/470k on board #define BAT_MEASURE_ADC ADC1_GPIO39_CHANNEL // external power probe GPIO pin #define BAT_VOLTAGE_DIVIDER 2.1277f // voltage divider 47k/442k on board -#define EXT_POWER_SW GPIO_NUM_12 // switches PoE power, Vext control 0 = off / 1 = on -#define EXT_POWER_ON 1 -//#define EXT_POWER_OFF 1 - #define HAS_BUTTON KEY_BUILTIN // on board button #define HAS_LED NOT_A_PIN // no on board LED diff --git a/src/main.cpp b/src/main.cpp index 66d9c3cb..ffb9f68c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -330,6 +330,12 @@ void setup() { assert(spi_init() == ESP_OK); #endif +// initialize MQTT +#ifdef HAS_MQTT + strcat_P(features, " MQTT"); + assert(mqtt_init() == ESP_OK); +#endif + #ifdef HAS_SDCARD if (sdcard_init()) strcat_P(features, " SD"); diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp new file mode 100644 index 00000000..7b521658 --- /dev/null +++ b/src/mqttclient.cpp @@ -0,0 +1,134 @@ +#ifdef HAS_MQTT + +#include "mqttclient.h" + +static const char TAG[] = __FILE__; + +IPAddress mqtt_server_ip(192, 168, 11, 57); + +QueueHandle_t MQTTSendQueue; +TaskHandle_t mqttTask; + +WiFiClient ipClient; +PubSubClient client(ipClient); + +void WiFiEvent(WiFiEvent_t event) { + switch (event) { + case SYSTEM_EVENT_ETH_START: + ESP_LOGI(TAG, "ETH Started"); + ETH.setHostname(MQTT_NAME); + break; + case SYSTEM_EVENT_ETH_CONNECTED: + ESP_LOGI(TAG, "ETH Connected"); + break; + case SYSTEM_EVENT_ETH_GOT_IP: + ESP_LOGI(TAG, "ETH MAC: %s", ETH.macAddress()); + ESP_LOGI(TAG, "IPv4: %s", ETH.localIP()); + ESP_LOGI(TAG, "Link Speed %d Mbps %s", ETH.linkSpeed(), + ETH.fullDuplex() ? "full duplex" : "half duplex"); + mqtt_connect(mqtt_server_ip, MQTT_PORT); + break; + case SYSTEM_EVENT_ETH_DISCONNECTED: + ESP_LOGI(TAG, "ETH Disconnected"); + break; + case SYSTEM_EVENT_ETH_STOP: + ESP_LOGI(TAG, "ETH Stopped"); + break; + default: + break; + } +} + +void mqtt_connect(IPAddress mqtt_host, uint16_t mqtt_port) { + // attempt to connect to MQTT server + if (ipClient.connect(mqtt_server_ip, MQTT_PORT)) { + if (client.connect(MQTT_NAME)) { + ESP_LOGW(TAG, "MQTT server connected, subscribing"); + client.subscribe(MQTT_INTOPIC); + } else { + ESP_LOGW(TAG, "MQTT server not responding, retrying later"); + } + } else + ESP_LOGW(TAG, "MQTT server not connected, retrying later"); +} + +void mqtt_client_task(void *param) { + while (1) { + MessageBuffer_t msg; + char cPort[4], cMsg[PAYLOAD_BUFFER_SIZE + 1]; + + // fetch next or wait for payload to send from queue + if (xQueueReceive(MQTTSendQueue, &msg, portMAX_DELAY) != pdTRUE) { + ESP_LOGE(TAG, "Premature return from xQueueReceive() with no data!"); + continue; + } + + // send data + if (client.connected()) { + snprintf(cPort, sizeof(cPort), "%d", msg.MessagePort); + snprintf(cMsg, sizeof(cMsg), "%s", msg.Message); + client.publish(cPort, cMsg); + client.loop(); + ESP_LOGI(TAG, "%d byte(s) sent to MQTT", msg.MessageSize); + } else { + mqtt_enqueuedata(&msg); // re-enqueue the undelivered message + delay(10000); + // attempt to reconnect to MQTT server + mqtt_connect(mqtt_server_ip, MQTT_PORT); + } + } +} + +esp_err_t mqtt_init(void) { + assert(SEND_QUEUE_SIZE); + MQTTSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t)); + if (MQTTSendQueue == 0) { + ESP_LOGE(TAG, "Could not create MQTT send queue. Aborting."); + return ESP_FAIL; + } + ESP_LOGI(TAG, "MQTT send queue created, size %d Bytes", + SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE); + + WiFi.onEvent(WiFiEvent); + assert(ETH.begin()); + + client.setServer(mqtt_server_ip, MQTT_PORT); + client.setCallback(mqtt_callback); + + ESP_LOGI(TAG, "Starting MQTTloop..."); + xTaskCreate(mqtt_client_task, "mqttloop", 4096, (void *)NULL, 2, &mqttTask); + + return ESP_OK; +} + +void mqtt_enqueuedata(MessageBuffer_t *message) { + // enqueue message in MQTT send queue + BaseType_t ret; + MessageBuffer_t DummyBuffer; + sendprio_t prio = message->MessagePrio; + + switch (prio) { + case prio_high: + // clear space in queue if full, then fallthrough to normal + if (!uxQueueSpacesAvailable(MQTTSendQueue)) + xQueueReceive(MQTTSendQueue, &DummyBuffer, (TickType_t)0); + case prio_normal: + ret = xQueueSendToFront(MQTTSendQueue, (void *)message, (TickType_t)0); + break; + case prio_low: + default: + ret = xQueueSendToBack(MQTTSendQueue, (void *)message, (TickType_t)0); + break; + } + if (ret != pdTRUE) + ESP_LOGW(TAG, "MQTT sendqueue is full"); +} + +void mqtt_queuereset(void) { xQueueReset(MQTTSendQueue); } + +void mqtt_callback(char *topic, byte *payload, unsigned int length) { + if ((length) && (topic == MQTT_INTOPIC)) + rcommand(payload, length); +} + +#endif // HAS_MQTT \ No newline at end of file diff --git a/src/senddata.cpp b/src/senddata.cpp index 07de525a..d6067131 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -50,6 +50,9 @@ void SendPayload(uint8_t port, sendprio_t prio) { #ifdef HAS_SPI spi_enqueuedata(&SendBuffer); #endif +#ifdef HAS_MQTT + mqtt_enqueuedata(&SendBuffer); +#endif // write data to sdcard, if present #ifdef HAS_SDCARD @@ -179,4 +182,7 @@ void flushQueues() { #ifdef HAS_SPI spi_queuereset(); #endif +#ifdef HAS_MQTT + mqtt_queuereset(); +#endif } From e720728ff5a25ed476a41b167e5f5b478763767c Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 16 May 2020 23:59:24 +0200 Subject: [PATCH 13/26] v1.9.993 --- platformio.ini | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/platformio.ini b/platformio.ini index 40015f00..1929fa3c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -7,7 +7,7 @@ ; ---> SELECT THE TARGET PLATFORM HERE! <--- [board] -halfile = generic.h +;halfile = generic.h ;halfile = ebox.h ;halfile = eboxtube.h ;halfile = ecopower.h @@ -33,7 +33,7 @@ halfile = generic.h ;halfile = tinypicomatrix.h ;halfile = m5core.h ;halfile = m5fire.h -;halfile = olimexpoe.h +halfile = olimexpoeiso.h [platformio] ; upload firmware to board with usb cable @@ -46,10 +46,10 @@ description = Paxcounter is a device for metering passenger flows in realtime. I [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.9.992 +release_version = 1.9.993 ; 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 = 3 +debug_level = 4 extra_scripts = pre:build.py otakeyfile = ota.conf lorakeyfile = loraconf.h @@ -85,6 +85,7 @@ lib_deps_basic = SimpleButton AXP202X_Library@>=1.1.1 ; AXP202 PMU lib by Lewis He esp32-micro-sdcard + PubSubClient lib_deps_all = ${common.lib_deps_basic} ${common.lib_deps_lora} @@ -113,7 +114,7 @@ framework = arduino board = esp32dev board_build.partitions = min_spiffs.csv upload_speed = ${common.upload_speed} -;upload_port = COM8 +;upload_port = COM11 platform = ${common.platform_espressif32} lib_deps = ${common.lib_deps_all} build_flags = ${common.build_flags_all} From c5c9e933d4052b9a1df7b7959b8ca3fa1a2d9e26 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 17 May 2020 23:07:38 +0200 Subject: [PATCH 14/26] MQTT client (experimental) --- include/mqttclient.h | 8 +++-- src/mqttclient.cpp | 80 +++++++++++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/include/mqttclient.h b/include/mqttclient.h index 28013301..4e366aba 100644 --- a/include/mqttclient.h +++ b/include/mqttclient.h @@ -6,16 +6,18 @@ #include #include -#define MQTT_NAME "paxcounter" -#define MQTT_INTOPIC "rcommand" +#define MQTT_CLIENT "paxcounter" +#define MQTT_INTOPIC "pax_IN" +#define MQTT_OUTTOPIC "pax_OUT" #define MQTT_PORT 1883 +#define MQTT_SERVER "broker.hivemq.com" extern TaskHandle_t mqttTask; void mqtt_enqueuedata(MessageBuffer_t *message); void mqtt_queuereset(void); void mqtt_client_task(void *param); -void mqtt_connect(IPAddress mqtt_host, uint16_t mqtt_port); +int mqtt_connect(IPAddress mqtt_host, uint16_t mqtt_port); void mqtt_callback(char *topic, byte *payload, unsigned int length); void WiFiEvent(WiFiEvent_t event); esp_err_t mqtt_init(void); diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp index 7b521658..a113b7f5 100644 --- a/src/mqttclient.cpp +++ b/src/mqttclient.cpp @@ -4,58 +4,81 @@ static const char TAG[] = __FILE__; -IPAddress mqtt_server_ip(192, 168, 11, 57); +IPAddress mqtt_server_ip; QueueHandle_t MQTTSendQueue; TaskHandle_t mqttTask; WiFiClient ipClient; -PubSubClient client(ipClient); +PubSubClient mqttClient(ipClient); void WiFiEvent(WiFiEvent_t event) { switch (event) { case SYSTEM_EVENT_ETH_START: - ESP_LOGI(TAG, "ETH Started"); - ETH.setHostname(MQTT_NAME); + ESP_LOGI(TAG, "Ethernet link layer started"); + ETH.setHostname(MQTT_CLIENT); break; case SYSTEM_EVENT_ETH_CONNECTED: - ESP_LOGI(TAG, "ETH Connected"); + ESP_LOGI(TAG, "Network link connected"); break; case SYSTEM_EVENT_ETH_GOT_IP: - ESP_LOGI(TAG, "ETH MAC: %s", ETH.macAddress()); - ESP_LOGI(TAG, "IPv4: %s", ETH.localIP()); + ESP_LOGI(TAG, "ETH MAC: %s", ETH.macAddress().c_str()); + ESP_LOGI(TAG, "IPv4: %s", ETH.localIP().toString().c_str()); ESP_LOGI(TAG, "Link Speed %d Mbps %s", ETH.linkSpeed(), ETH.fullDuplex() ? "full duplex" : "half duplex"); mqtt_connect(mqtt_server_ip, MQTT_PORT); break; case SYSTEM_EVENT_ETH_DISCONNECTED: - ESP_LOGI(TAG, "ETH Disconnected"); + ESP_LOGI(TAG, "Network link disconnected"); break; case SYSTEM_EVENT_ETH_STOP: - ESP_LOGI(TAG, "ETH Stopped"); + ESP_LOGI(TAG, "Ethernet link layer stopped"); break; default: break; } } -void mqtt_connect(IPAddress mqtt_host, uint16_t mqtt_port) { +int mqtt_connect(IPAddress mqtt_host, uint16_t mqtt_port) { + // resolve server + if (WiFi.hostByName(MQTT_SERVER, mqtt_server_ip)) { + ESP_LOGI(TAG, "Attempting to connect to %s [%s]", MQTT_SERVER, + mqtt_server_ip.toString().c_str()); + } else { + ESP_LOGI(TAG, "Could not resolve %s", MQTT_SERVER); + return -1; + } + // attempt to connect to MQTT server - if (ipClient.connect(mqtt_server_ip, MQTT_PORT)) { - if (client.connect(MQTT_NAME)) { - ESP_LOGW(TAG, "MQTT server connected, subscribing"); - client.subscribe(MQTT_INTOPIC); + if (ipClient.connect(mqtt_host, mqtt_port)) { + + mqttClient.setServer(mqtt_server_ip, MQTT_PORT); + mqttClient.setCallback(mqtt_callback); + + String clientId = "Paxcounter-"; + clientId += String(random(0xffff), HEX); + + if (mqttClient.connect(clientId.c_str())) { + ESP_LOGI(TAG, "MQTT server connected, subscribing..."); + mqttClient.publish(MQTT_OUTTOPIC, "hello world"); + mqttClient.subscribe(MQTT_INTOPIC); + ESP_LOGI(TAG, "MQTT topic subscribed"); } else { ESP_LOGW(TAG, "MQTT server not responding, retrying later"); + return -1; } - } else + } else { ESP_LOGW(TAG, "MQTT server not connected, retrying later"); + return -1; + } } void mqtt_client_task(void *param) { + + MessageBuffer_t msg; + char cPort[4], cMsg[PAYLOAD_BUFFER_SIZE + 1]; + while (1) { - MessageBuffer_t msg; - char cPort[4], cMsg[PAYLOAD_BUFFER_SIZE + 1]; // fetch next or wait for payload to send from queue if (xQueueReceive(MQTTSendQueue, &msg, portMAX_DELAY) != pdTRUE) { @@ -63,12 +86,12 @@ void mqtt_client_task(void *param) { continue; } - // send data - if (client.connected()) { - snprintf(cPort, sizeof(cPort), "%d", msg.MessagePort); + // send data to mqtt server + if (mqttClient.connected()) { + snprintf(cPort, sizeof(cPort), "Port_%d", msg.MessagePort); snprintf(cMsg, sizeof(cMsg), "%s", msg.Message); - client.publish(cPort, cMsg); - client.loop(); + mqttClient.publish(cPort, cMsg); + mqttClient.loop(); ESP_LOGI(TAG, "%d byte(s) sent to MQTT", msg.MessageSize); } else { mqtt_enqueuedata(&msg); // re-enqueue the undelivered message @@ -76,7 +99,7 @@ void mqtt_client_task(void *param) { // attempt to reconnect to MQTT server mqtt_connect(mqtt_server_ip, MQTT_PORT); } - } + } // while(1) } esp_err_t mqtt_init(void) { @@ -89,15 +112,12 @@ esp_err_t mqtt_init(void) { ESP_LOGI(TAG, "MQTT send queue created, size %d Bytes", SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE); - WiFi.onEvent(WiFiEvent); - assert(ETH.begin()); - - client.setServer(mqtt_server_ip, MQTT_PORT); - client.setCallback(mqtt_callback); - ESP_LOGI(TAG, "Starting MQTTloop..."); xTaskCreate(mqtt_client_task, "mqttloop", 4096, (void *)NULL, 2, &mqttTask); + WiFi.onEvent(WiFiEvent); + ETH.begin(); + return ESP_OK; } @@ -127,7 +147,7 @@ void mqtt_enqueuedata(MessageBuffer_t *message) { void mqtt_queuereset(void) { xQueueReset(MQTTSendQueue); } void mqtt_callback(char *topic, byte *payload, unsigned int length) { - if ((length) && (topic == MQTT_INTOPIC)) + if ((length >= 1) && (topic == MQTT_INTOPIC)) rcommand(payload, length); } From e0b04775e01f3596845ca6e978d2a7bb8eb9a26d Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 20 May 2020 12:34:58 +0200 Subject: [PATCH 15/26] sdcard.h: bugfix conditional compile --- include/sdcard.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/sdcard.h b/include/sdcard.h index 8157bb32..5fa78512 100644 --- a/include/sdcard.h +++ b/include/sdcard.h @@ -5,6 +5,7 @@ #include #include +#ifdef HAS_SDCARD #if HAS_SDCARD == 1 #include #elif HAS_SDCARD == 2 @@ -12,6 +13,7 @@ #else #error HAS_SDCARD unknown card reader value, must be either 1 or 2 #endif +#endif #include "sds011read.h" From 897343a96a58bcb85b32d223a45219cb73024736 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 20 May 2020 12:40:14 +0200 Subject: [PATCH 16/26] m5core.h: bugfix PSRAM --- src/hal/m5core.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hal/m5core.h b/src/hal/m5core.h index fb69cf3a..5ebccbb6 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -29,7 +29,6 @@ //#define HAS_SENSORS 1 // comment out if device has user defined sensors #define CFG_sx1276_radio 1 // select LoRa chip -//#define BOARD_HAS_PSRAM // use if board has external PSRAM #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature #define HAS_DISPLAY 2 // TFT-LCD, support work in progess, not ready yet From c5635f59b27d73aa85ccbe1ce01a3acbb8390b23 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 20 May 2020 12:40:37 +0200 Subject: [PATCH 17/26] mqtt code sanitizations --- include/mqttclient.h | 2 +- src/main.cpp | 1 + src/mqttclient.cpp | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/mqttclient.h b/include/mqttclient.h index 4e366aba..1a6767b7 100644 --- a/include/mqttclient.h +++ b/include/mqttclient.h @@ -19,7 +19,7 @@ void mqtt_queuereset(void); void mqtt_client_task(void *param); int mqtt_connect(IPAddress mqtt_host, uint16_t mqtt_port); void mqtt_callback(char *topic, byte *payload, unsigned int length); -void WiFiEvent(WiFiEvent_t event); +void NetworkEvent(WiFiEvent_t event); esp_err_t mqtt_init(void); #endif // _MQTTCLIENT_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ffb9f68c..17a8fa04 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,7 @@ Task Core Prio Purpose ------------------------------------------------------------------------------- ledloop 0 3 blinks LEDs spiloop 0 2 reads/writes data on spi interface +mqttloop 0 2 reads/writes data on ETH interface IDLE 0 0 ESP32 arduino scheduler -> runs wifi sniffer lmictask 1 2 MCCI LMiC LORAWAN stack diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp index a113b7f5..e6302255 100644 --- a/src/mqttclient.cpp +++ b/src/mqttclient.cpp @@ -12,7 +12,7 @@ TaskHandle_t mqttTask; WiFiClient ipClient; PubSubClient mqttClient(ipClient); -void WiFiEvent(WiFiEvent_t event) { +void NetworkEvent(WiFiEvent_t event) { switch (event) { case SYSTEM_EVENT_ETH_START: ESP_LOGI(TAG, "Ethernet link layer started"); @@ -115,7 +115,7 @@ esp_err_t mqtt_init(void) { ESP_LOGI(TAG, "Starting MQTTloop..."); xTaskCreate(mqtt_client_task, "mqttloop", 4096, (void *)NULL, 2, &mqttTask); - WiFi.onEvent(WiFiEvent); + WiFi.onEvent(NetworkEvent); ETH.begin(); return ESP_OK; From 98789a7dd53503871953d90db07d0c7c7d94f823 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 20 May 2020 12:41:03 +0200 Subject: [PATCH 18/26] disable SD card on Olimex-POE (currently broken) --- src/hal/olimexpoeiso.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hal/olimexpoeiso.h b/src/hal/olimexpoeiso.h index 227473f9..7ac4611f 100644 --- a/src/hal/olimexpoeiso.h +++ b/src/hal/olimexpoeiso.h @@ -8,7 +8,7 @@ #include // enable only if you want to store a local paxcount table on the device -#define HAS_SDCARD 2 // this board has an SD-card-reader/writer +//#define HAS_SDCARD 2 // this board has an SD-card-reader/writer // enable only if you want to send paxcount via ethernet port to mqtt server #define HAS_MQTT 1 // use MQTT on ethernet interface From 9c0b504841ced28e803fb6b6a5ef8ea63f49fefe Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 20 May 2020 18:29:07 +0200 Subject: [PATCH 19/26] mqtt test (experimental) --- include/mqttclient.h | 2 +- src/mqttclient.cpp | 38 ++++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/include/mqttclient.h b/include/mqttclient.h index 1a6767b7..a2fd04df 100644 --- a/include/mqttclient.h +++ b/include/mqttclient.h @@ -17,7 +17,7 @@ extern TaskHandle_t mqttTask; void mqtt_enqueuedata(MessageBuffer_t *message); void mqtt_queuereset(void); void mqtt_client_task(void *param); -int mqtt_connect(IPAddress mqtt_host, uint16_t mqtt_port); +int mqtt_connect(const char *my_host, const uint16_t my_port); void mqtt_callback(char *topic, byte *payload, unsigned int length); void NetworkEvent(WiFiEvent_t event); esp_err_t mqtt_init(void); diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp index e6302255..4a030f58 100644 --- a/src/mqttclient.cpp +++ b/src/mqttclient.cpp @@ -4,13 +4,11 @@ static const char TAG[] = __FILE__; -IPAddress mqtt_server_ip; - QueueHandle_t MQTTSendQueue; TaskHandle_t mqttTask; -WiFiClient ipClient; -PubSubClient mqttClient(ipClient); +WiFiClient EthClient; +PubSubClient mqttClient(EthClient); void NetworkEvent(WiFiEvent_t event) { switch (event) { @@ -24,9 +22,9 @@ void NetworkEvent(WiFiEvent_t event) { case SYSTEM_EVENT_ETH_GOT_IP: ESP_LOGI(TAG, "ETH MAC: %s", ETH.macAddress().c_str()); ESP_LOGI(TAG, "IPv4: %s", ETH.localIP().toString().c_str()); - ESP_LOGI(TAG, "Link Speed %d Mbps %s", ETH.linkSpeed(), + ESP_LOGI(TAG, "Link Speed: %d Mbps %s", ETH.linkSpeed(), ETH.fullDuplex() ? "full duplex" : "half duplex"); - mqtt_connect(mqtt_server_ip, MQTT_PORT); + mqtt_connect(MQTT_SERVER, MQTT_PORT); break; case SYSTEM_EVENT_ETH_DISCONNECTED: ESP_LOGI(TAG, "Network link disconnected"); @@ -39,29 +37,32 @@ void NetworkEvent(WiFiEvent_t event) { } } -int mqtt_connect(IPAddress mqtt_host, uint16_t mqtt_port) { +int mqtt_connect(const char *my_host, const uint16_t my_port) { + IPAddress mqtt_server_ip; + + static String clientId = "paxcounter-" + String(random(0xffff), HEX); + ESP_LOGI(TAG, "MQTT name is %s", clientId.c_str()); + // resolve server - if (WiFi.hostByName(MQTT_SERVER, mqtt_server_ip)) { - ESP_LOGI(TAG, "Attempting to connect to %s [%s]", MQTT_SERVER, + if (WiFi.hostByName(my_host, mqtt_server_ip)) { + ESP_LOGI(TAG, "Attempting to connect to %s [%s]", my_host, mqtt_server_ip.toString().c_str()); } else { - ESP_LOGI(TAG, "Could not resolve %s", MQTT_SERVER); + ESP_LOGI(TAG, "Could not resolve %s", my_host); return -1; } // attempt to connect to MQTT server - if (ipClient.connect(mqtt_host, mqtt_port)) { + if (EthClient.connect(mqtt_server_ip, my_port)) { - mqttClient.setServer(mqtt_server_ip, MQTT_PORT); + mqttClient.setServer(mqtt_server_ip, my_port); mqttClient.setCallback(mqtt_callback); - String clientId = "Paxcounter-"; - clientId += String(random(0xffff), HEX); - if (mqttClient.connect(clientId.c_str())) { ESP_LOGI(TAG, "MQTT server connected, subscribing..."); mqttClient.publish(MQTT_OUTTOPIC, "hello world"); mqttClient.subscribe(MQTT_INTOPIC); + mqttClient.loop(); ESP_LOGI(TAG, "MQTT topic subscribed"); } else { ESP_LOGW(TAG, "MQTT server not responding, retrying later"); @@ -88,8 +89,9 @@ void mqtt_client_task(void *param) { // send data to mqtt server if (mqttClient.connected()) { - snprintf(cPort, sizeof(cPort), "Port_%d", msg.MessagePort); - snprintf(cMsg, sizeof(cMsg), "%s", msg.Message); + snprintf(cPort, sizeof(cPort), "%d", msg.MessagePort); + snprintf(cMsg, sizeof(cMsg), "%0X", msg.Message); + ESP_LOGI(TAG, "Topic=%s | Message=%s", cPort, cMsg); mqttClient.publish(cPort, cMsg); mqttClient.loop(); ESP_LOGI(TAG, "%d byte(s) sent to MQTT", msg.MessageSize); @@ -97,7 +99,7 @@ void mqtt_client_task(void *param) { mqtt_enqueuedata(&msg); // re-enqueue the undelivered message delay(10000); // attempt to reconnect to MQTT server - mqtt_connect(mqtt_server_ip, MQTT_PORT); + mqtt_connect(MQTT_SERVER, MQTT_PORT); } } // while(1) } From 05e5d31a53a4b2deb7b45c1ea4ccf4583937fb48 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Thu, 21 May 2020 19:42:42 +0200 Subject: [PATCH 20/26] mqtt client (experimental) --- README.md | 5 +++-- include/cyclic.h | 1 + include/mqttclient.h | 6 +++--- include/sdcard.h | 1 + src/cyclic.cpp | 5 +++++ src/hal/olimexpoeiso.h | 4 +--- src/mqttclient.cpp | 39 ++++++++++++++++++++++----------------- src/sdcard.cpp | 7 +++---- 8 files changed, 39 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 474a7bc1..c4ff5856 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,8 @@ Depending on board hardware following features are supported: - IF482 (serial) and DCF77 (gpio) time telegram generator - Switch external power / battery - LED Matrix display (similar to [this 64x16 model](https://www.instructables.com/id/64x16-RED-LED-Marquee/), can be ordered on [Aliexpress](https://www.aliexpress.com/item/P3-75-dot-matrix-led-module-3-75mm-high-clear-top1-for-text-display-304-60mm/32616683948.html)) -- SD-card (see section SD-card here) +- SD-card (see section SD-card here) for logging pax data +- Ethernet interface for MQTT communication via TCP/IP Target platform must be selected in [platformio.ini](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/platformio.ini).
Hardware dependent settings (pinout etc.) are stored in board files in /hal directory. If you want to use a ESP32 board which is not yet supported, use hal file generic.h and tailor pin mappings to your needs. Pull requests for new boards welcome.
@@ -211,7 +212,7 @@ Data can be stored on an SD-card if one is availabe. Simply choose the file in s OR #define HAS_SDCARD 2 // SD-card-reader/writer, using SDMMC interface - // Pins for SD-card + // Pins for SPI interface #define SDCARD_CS (13) // fill in the correct numbers for your board #define SDCARD_MOSI (15) #define SDCARD_MISO (2) diff --git a/include/cyclic.h b/include/cyclic.h index 44c475e8..0fdf38b1 100644 --- a/include/cyclic.h +++ b/include/cyclic.h @@ -5,6 +5,7 @@ #include "senddata.h" #include "rcommand.h" #include "spislave.h" +#include "mqttclient.h" #include "bmesensor.h" #include "display.h" #include "sds011read.h" diff --git a/include/mqttclient.h b/include/mqttclient.h index a2fd04df..1e6d36e8 100644 --- a/include/mqttclient.h +++ b/include/mqttclient.h @@ -6,13 +6,13 @@ #include #include -#define MQTT_CLIENT "paxcounter" -#define MQTT_INTOPIC "pax_IN" -#define MQTT_OUTTOPIC "pax_OUT" +#define MQTT_INTOPIC "paxcounter_in/" +#define MQTT_OUTTOPIC "paxcounter_out/" #define MQTT_PORT 1883 #define MQTT_SERVER "broker.hivemq.com" extern TaskHandle_t mqttTask; +extern PubSubClient mqttClient; void mqtt_enqueuedata(MessageBuffer_t *message); void mqtt_queuereset(void); diff --git a/include/sdcard.h b/include/sdcard.h index 5fa78512..e369deb3 100644 --- a/include/sdcard.h +++ b/include/sdcard.h @@ -38,5 +38,6 @@ bool sdcard_init(void); void sdcardWriteData(uint16_t, uint16_t); +static void createFile(void); #endif diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 31175ff9..77e7439d 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -52,6 +52,11 @@ void doHousekeeping() { ESP_LOGD(TAG, "spiloop %d bytes left | Taskstate = %d", uxTaskGetStackHighWaterMark(spiTask), eTaskGetState(spiTask)); #endif +#ifdef HAS_MQTT + ESP_LOGD(TAG, "MQTTloop %d bytes left | Taskstate = %d", + uxTaskGetStackHighWaterMark(mqttTask), eTaskGetState(mqttTask)); + mqttClient.loop(); +#endif #if (defined HAS_DCF77 || defined HAS_IF482) ESP_LOGD(TAG, "Clockloop %d bytes left | Taskstate = %d", diff --git a/src/hal/olimexpoeiso.h b/src/hal/olimexpoeiso.h index 7ac4611f..70856336 100644 --- a/src/hal/olimexpoeiso.h +++ b/src/hal/olimexpoeiso.h @@ -8,13 +8,11 @@ #include // enable only if you want to store a local paxcount table on the device -//#define HAS_SDCARD 2 // this board has an SD-card-reader/writer +//#define HAS_SDCARD 2 // this board has a SDMMC card-reader/writer // enable only if you want to send paxcount via ethernet port to mqtt server #define HAS_MQTT 1 // use MQTT on ethernet interface -#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature - //#define BAT_MEASURE_ADC ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 //#define BAT_VOLTAGE_DIVIDER 2 // voltage divider 470k/470k on board #define BAT_MEASURE_ADC ADC1_GPIO39_CHANNEL // external power probe GPIO pin diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp index 4a030f58..80e009bf 100644 --- a/src/mqttclient.cpp +++ b/src/mqttclient.cpp @@ -14,7 +14,7 @@ void NetworkEvent(WiFiEvent_t event) { switch (event) { case SYSTEM_EVENT_ETH_START: ESP_LOGI(TAG, "Ethernet link layer started"); - ETH.setHostname(MQTT_CLIENT); + ETH.setHostname(ETH.macAddress().c_str()); break; case SYSTEM_EVENT_ETH_CONNECTED: ESP_LOGI(TAG, "Network link connected"); @@ -40,7 +40,7 @@ void NetworkEvent(WiFiEvent_t event) { int mqtt_connect(const char *my_host, const uint16_t my_port) { IPAddress mqtt_server_ip; - static String clientId = "paxcounter-" + String(random(0xffff), HEX); + static String clientId = "paxcounter-" + ETH.macAddress(); ESP_LOGI(TAG, "MQTT name is %s", clientId.c_str()); // resolve server @@ -53,16 +53,15 @@ int mqtt_connect(const char *my_host, const uint16_t my_port) { } // attempt to connect to MQTT server - if (EthClient.connect(mqtt_server_ip, my_port)) { - + if (EthClient.connect(mqtt_server_ip, my_port, HOMECYCLE * 2 * 1000)) { mqttClient.setServer(mqtt_server_ip, my_port); + mqttClient.setKeepAlive(HOMECYCLE * 2); mqttClient.setCallback(mqtt_callback); if (mqttClient.connect(clientId.c_str())) { ESP_LOGI(TAG, "MQTT server connected, subscribing..."); - mqttClient.publish(MQTT_OUTTOPIC, "hello world"); + mqttClient.publish(MQTT_OUTTOPIC, clientId.c_str()); mqttClient.subscribe(MQTT_INTOPIC); - mqttClient.loop(); ESP_LOGI(TAG, "MQTT topic subscribed"); } else { ESP_LOGW(TAG, "MQTT server not responding, retrying later"); @@ -77,7 +76,6 @@ int mqtt_connect(const char *my_host, const uint16_t my_port) { void mqtt_client_task(void *param) { MessageBuffer_t msg; - char cPort[4], cMsg[PAYLOAD_BUFFER_SIZE + 1]; while (1) { @@ -87,16 +85,23 @@ void mqtt_client_task(void *param) { continue; } - // send data to mqtt server + // send data to mqtt server, if we are connected if (mqttClient.connected()) { - snprintf(cPort, sizeof(cPort), "%d", msg.MessagePort); - snprintf(cMsg, sizeof(cMsg), "%0X", msg.Message); - ESP_LOGI(TAG, "Topic=%s | Message=%s", cPort, cMsg); - mqttClient.publish(cPort, cMsg); - mqttClient.loop(); - ESP_LOGI(TAG, "%d byte(s) sent to MQTT", msg.MessageSize); - } else { - mqtt_enqueuedata(&msg); // re-enqueue the undelivered message + mqttClient.beginPublish(MQTT_OUTTOPIC, msg.MessageSize + 2, false); + mqttClient.write(msg.MessagePort); + mqttClient.write('/'); + mqttClient.write(msg.Message, msg.MessageSize); + if (mqttClient.endPublish()) { + ESP_LOGI(TAG, "%d byte(s) sent to MQTT", msg.MessageSize + 2); + continue; // while(1) + } else + goto reconnect; + + } else { // not connected, thus re-enqueue the undelivered message + + reconnect: + + mqtt_enqueuedata(&msg); delay(10000); // attempt to reconnect to MQTT server mqtt_connect(MQTT_SERVER, MQTT_PORT); @@ -149,7 +154,7 @@ void mqtt_enqueuedata(MessageBuffer_t *message) { void mqtt_queuereset(void) { xQueueReset(MQTTSendQueue); } void mqtt_callback(char *topic, byte *payload, unsigned int length) { - if ((length >= 1) && (topic == MQTT_INTOPIC)) + ESP_LOGD(TAG, "MQTT %d byte(s) received", length); rcommand(payload, length); } diff --git a/src/sdcard.cpp b/src/sdcard.cpp index cd6b8618..37458cb4 100644 --- a/src/sdcard.cpp +++ b/src/sdcard.cpp @@ -9,12 +9,11 @@ static const char TAG[] = __FILE__; static bool useSDCard; -static void createFile(void); - File fileSDCard; bool sdcard_init() { ESP_LOGI(TAG, "looking for SD-card..."); + #if HAS_SDCARD == 1 pinMode(SDCARD_CS, OUTPUT); useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK); @@ -70,7 +69,7 @@ void createFile(void) { for (int i = 0; i < 100; i++) { sprintf(bufferFilename, SDCARD_FILE_NAME, i); - ESP_LOGD(TAG, "SD: looking for file <%s>", bufferFilename); + // ESP_LOGD(TAG, "SD: looking for file <%s>", bufferFilename); #if HAS_SDCARD == 1 bool fileExists = SD.exists(bufferFilename); @@ -79,7 +78,7 @@ void createFile(void) { #endif if (!fileExists) { - ESP_LOGD(TAG, "SD: file does not exist: opening"); + // ESP_LOGD(TAG, "SD: file does not exist: opening"); #if HAS_SDCARD == 1 fileSDCard = SD.open(bufferFilename, FILE_WRITE); From 014bae059ec9e1481f3d8c8d04590011523b90f8 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 22 May 2020 00:07:49 +0200 Subject: [PATCH 21/26] mqtt client test (experimental) --- include/mqttclient.h | 1 + src/mqttclient.cpp | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/mqttclient.h b/include/mqttclient.h index 1e6d36e8..9bb90364 100644 --- a/include/mqttclient.h +++ b/include/mqttclient.h @@ -10,6 +10,7 @@ #define MQTT_OUTTOPIC "paxcounter_out/" #define MQTT_PORT 1883 #define MQTT_SERVER "broker.hivemq.com" +#define MQTT_RETRYSEC 10 // retry reconnect every 10 seconds extern TaskHandle_t mqttTask; extern PubSubClient mqttClient; diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp index 80e009bf..bfd11319 100644 --- a/src/mqttclient.cpp +++ b/src/mqttclient.cpp @@ -97,13 +97,12 @@ void mqtt_client_task(void *param) { } else goto reconnect; - } else { // not connected, thus re-enqueue the undelivered message + } else { - reconnect: - - mqtt_enqueuedata(&msg); - delay(10000); // attempt to reconnect to MQTT server + reconnect: + mqtt_enqueuedata(&msg); // postpone the undelivered message + delay(MQTT_RETRYSEC * 1000); mqtt_connect(MQTT_SERVER, MQTT_PORT); } } // while(1) @@ -151,11 +150,14 @@ void mqtt_enqueuedata(MessageBuffer_t *message) { ESP_LOGW(TAG, "MQTT sendqueue is full"); } -void mqtt_queuereset(void) { xQueueReset(MQTTSendQueue); } - void mqtt_callback(char *topic, byte *payload, unsigned int length) { - ESP_LOGD(TAG, "MQTT %d byte(s) received", length); - rcommand(payload, length); + String s = ""; + for (int i = 0; i < length; i++) + s += (char)payload[i]; + ESP_LOGD(TAG, "MQTT: Received %u byte(s) of payload [%s]", length, s); + // rcommand(payload, length); } +void mqtt_queuereset(void) { xQueueReset(MQTTSendQueue); } + #endif // HAS_MQTT \ No newline at end of file From 46cc027ee45a0e0ae65b962c9eedd63d015b3591 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 2 Jun 2020 16:34:53 +0200 Subject: [PATCH 22/26] display.cpp: check display type setting --- src/display.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/display.cpp b/src/display.cpp index 134962a3..162fa6b3 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -49,10 +49,14 @@ static int dp_row = 0, dp_col = 0, dp_font = 0; QRCode qrcode; +#ifdef HAS_DISPLAY #if (HAS_DISPLAY) == 1 OBDISP ssoled; #elif (HAS_DISPLAY) == 2 TFT_eSPI tft = TFT_eSPI(); +#else +#error Unknown display type specified in hal file +#endif #endif void dp_setup(int contrast) { From 5dd5c481ad297dadfe53fdfbdf844414af5dc02d Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 6 Jun 2020 15:09:12 +0200 Subject: [PATCH 23/26] sdcard code sanitizations --- include/sdcard.h | 2 ++ src/sdcard.cpp | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/sdcard.h b/include/sdcard.h index e369deb3..7102c460 100644 --- a/include/sdcard.h +++ b/include/sdcard.h @@ -15,7 +15,9 @@ #endif #endif +#ifdef HAS_SDS011 #include "sds011read.h" +#endif #ifndef SDCARD_CS #define SDCARD_CS SS diff --git a/src/sdcard.cpp b/src/sdcard.cpp index 37458cb4..5047ee2e 100644 --- a/src/sdcard.cpp +++ b/src/sdcard.cpp @@ -1,12 +1,12 @@ // routines for writing data to an SD-card, if present -#if (HAS_SDCARD) - // Local logging tag static const char TAG[] = __FILE__; #include "sdcard.h" +#ifdef HAS_SDCARD + static bool useSDCard; File fileSDCard; @@ -14,10 +14,13 @@ File fileSDCard; bool sdcard_init() { ESP_LOGI(TAG, "looking for SD-card..."); -#if HAS_SDCARD == 1 - pinMode(SDCARD_CS, OUTPUT); + // for usage of SD drivers on ESP32 platform see + // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdspi_host.html + // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdmmc_host.html + +#if HAS_SDCARD == 1 // use SD SPI host driver useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK); -#elif HAS_SDCARD == 2 +#elif HAS_SDCARD == 2 // use SD MMC host driver useSDCard = SD_MMC.begin(); #endif From 271f5edd0080e485f4b97d2c204f8778aa8dd44a Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 6 Jun 2020 15:09:35 +0200 Subject: [PATCH 24/26] ttgobeamv10.h display removed --- src/hal/ttgobeam10.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hal/ttgobeam10.h b/src/hal/ttgobeam10.h index 73e72dde..080b5a5d 100644 --- a/src/hal/ttgobeam10.h +++ b/src/hal/ttgobeam10.h @@ -9,7 +9,7 @@ /* Hardware related definitions for TTGO T-Beam board -(only) for newer T-Beam version T22_V10 +for T-Beam versions T22_V10 + T22_V11 pinouts taken from https://github.com/lewisxhe/TTGO-T-Beam /// Button functions: /// @@ -20,7 +20,7 @@ User, long press -> send LORA message Reset -> reset device */ -#define HAS_DISPLAY 1 +//#define HAS_DISPLAY 1 #define MY_DISPLAY_SDA SDA #define MY_DISPLAY_SCL SCL #define MY_DISPLAY_RST NOT_A_PIN From 188ad38e2b912f5963fbe3ea2b180b7d647b9a49 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 6 Jun 2020 15:11:07 +0200 Subject: [PATCH 25/26] v1.9.996 --- platformio.ini | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/platformio.ini b/platformio.ini index 1929fa3c..7030b54f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -7,7 +7,7 @@ ; ---> SELECT THE TARGET PLATFORM HERE! <--- [board] -;halfile = generic.h +halfile = generic.h ;halfile = ebox.h ;halfile = eboxtube.h ;halfile = ecopower.h @@ -33,7 +33,7 @@ ;halfile = tinypicomatrix.h ;halfile = m5core.h ;halfile = m5fire.h -halfile = olimexpoeiso.h +;halfile = olimexpoeiso.h [platformio] ; upload firmware to board with usb cable @@ -46,26 +46,26 @@ description = Paxcounter is a device for metering passenger flows in realtime. I [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.9.993 +release_version = 1.9.996 ; 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 = 4 +debug_level = 3 extra_scripts = pre:build.py otakeyfile = ota.conf lorakeyfile = loraconf.h lmicconfigfile = lmic_config.h -platform_espressif32 = espressif32@1.12.1 +platform_espressif32 = espressif32@1.12.2 monitor_speed = 115200 upload_speed = 115200 ; set by build.py and taken from hal file display_library = ; set by build.py and taken from hal file lib_deps_lora = MCCI LoRaWAN LMIC library@3.2.0 ; MCCI LMIC by Terrill Moore lib_deps_display = - OneBitDisplay@1.3.0 + ;OneBitDisplay@>1.4.0 + https://github.com/bitbank2/OneBitDisplay.git QRCode@0.0.1 BitBang_I2C@2.1.1 - ;TFT_eSPI@2.2.6 - https://github.com/Bodmer/TFT_eSPI.git + TFT_eSPI@>=2.2.8 lib_deps_ledmatrix = Ultrathin_LED_Matrix@>=1.0.0 lib_deps_rgbled = @@ -73,9 +73,9 @@ lib_deps_rgbled = lib_deps_gps = 1655@>=1.0.2 ; #1655 TinyGPSPlus by Mikal Hart lib_deps_sensors = - Adafruit Unified Sensor@>=1.1.2 + Adafruit Unified Sensor@>=1.1.3 Adafruit BME280 Library@>=2.0.2 - Adafruit BMP085 Library@>=1.0.1 + Adafruit BMP085 Library@>=1.1.0 BSEC Software Library@1.5.1474 https://github.com/ricki-z/SDS011.git lib_deps_basic = @@ -85,7 +85,7 @@ lib_deps_basic = SimpleButton AXP202X_Library@>=1.1.1 ; AXP202 PMU lib by Lewis He esp32-micro-sdcard - PubSubClient + PubSubClient@>=2.8.0 lib_deps_all = ${common.lib_deps_basic} ${common.lib_deps_lora} @@ -114,7 +114,7 @@ framework = arduino board = esp32dev board_build.partitions = min_spiffs.csv upload_speed = ${common.upload_speed} -;upload_port = COM11 +;upload_port = COM7 platform = ${common.platform_espressif32} lib_deps = ${common.lib_deps_all} build_flags = ${common.build_flags_all} From 48cbe53ceefb52210739f4b5aeaaf89783f17fb4 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 6 Jun 2020 15:15:40 +0200 Subject: [PATCH 26/26] timekeeper.cpp: removed lora check --- src/timekeeper.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index 6d8439ec..87ef0ad0 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -1,5 +1,6 @@ #include "timekeeper.h" +/* #if !(HAS_LORA) #if (TIME_SYNC_LORASERVER) #error TIME_SYNC_LORASERVER defined, but device has no LORA configured @@ -7,6 +8,7 @@ #error TIME_SYNC_LORAWAN defined, but device has no LORA configured #endif #endif +*/ // Local logging tag static const char TAG[] = __FILE__;