From bd724557c1cdc22c4bd81479e9c9ec1ef43dea88 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 17 Sep 2018 17:23:02 +0200 Subject: [PATCH] v1.4.32 --- README.md | 1 + lib/BintrayClient/src/BintrayCertificates.h | 1 + lib/BintrayClient/src/BintrayClient.cpp | 11 +- lib/BintrayClient/src/BintrayClient.h | 1 + platformio.ini | 259 +++++++++++--------- publish_firmware.py | 16 +- src/OTA.cpp | 39 ++- src/OTA.h | 2 + src/globals.h | 4 - src/hal/ttgov21.h | 69 ------ src/hal/ttgov21new.h | 30 +++ src/hal/ttgov21old.h | 32 +++ src/main.cpp | 4 +- src/paxcounter.conf | 2 + src/payload.cpp | 10 +- src/payload.h | 1 + 16 files changed, 274 insertions(+), 208 deletions(-) delete mode 100644 src/hal/ttgov21.h create mode 100644 src/hal/ttgov21new.h create mode 100644 src/hal/ttgov21old.h diff --git a/README.md b/README.md index 9dbb980f..870f3656 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering. byte 3-10: Uptime [seconds] byte 11: CPU temperature [°C] bytes 12-15: Free RAM [bytes] + bytes 16-17: Last CPU reset reason [core 0, core 1] **Port #3:** Device configuration query result diff --git a/lib/BintrayClient/src/BintrayCertificates.h b/lib/BintrayClient/src/BintrayCertificates.h index d85bb4e4..89854c84 100644 --- a/lib/BintrayClient/src/BintrayCertificates.h +++ b/lib/BintrayClient/src/BintrayCertificates.h @@ -1,4 +1,5 @@ /* + Parts of this file Copyright (c) 2014-present PlatformIO Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/BintrayClient/src/BintrayClient.cpp b/lib/BintrayClient/src/BintrayClient.cpp index b0e7543f..955bca20 100644 --- a/lib/BintrayClient/src/BintrayClient.cpp +++ b/lib/BintrayClient/src/BintrayClient.cpp @@ -1,4 +1,5 @@ /* + Parts of this file Copyright (c) 2014-present PlatformIO Licensed under the Apache License, Version 2.0 (the "License"); @@ -94,7 +95,7 @@ String BintrayClient::requestHTTPContent(const String &url) const } else { - Serial.printf("GET request failed, error: %s\n", http.errorToString(httpCode).c_str()); + ESP_LOGE(TAG, "GET request failed, error: %s", http.errorToString(httpCode).c_str()); } http.end(); @@ -109,7 +110,7 @@ String BintrayClient::getLatestVersion() const const size_t bufferSize = 1024; if (jsonResult.length() > bufferSize) { - Serial.println("Error: Could parse JSON. Input data is too big!"); + ESP_LOGE(TAG, "Error: Firmware version data invalid."); return version; } StaticJsonBuffer jsonBuffer; @@ -118,7 +119,7 @@ String BintrayClient::getLatestVersion() const // Check for errors in parsing if (!root.success()) { - Serial.println("Error: Could not parse JSON!"); + ESP_LOGE(TAG, "Error: Firmware version data not found."); return version; } return root.get("name"); @@ -133,7 +134,7 @@ String BintrayClient::getBinaryPath(const String &version) const const size_t bufferSize = 1024; if (jsonResult.length() > bufferSize) { - Serial.println("Error: Could parse JSON. Input data is too big!"); + ESP_LOGE(TAG, "Error: Firmware download path data invalid."); return path; } StaticJsonBuffer jsonBuffer; @@ -142,7 +143,7 @@ String BintrayClient::getBinaryPath(const String &version) const JsonObject &firstItem = root[0]; if (!root.success()) { //Check for errors in parsing - Serial.println("Error: Could not parse JSON!"); + ESP_LOGE(TAG, "Error: Firmware download path not found."); return path; } return "/" + getUser() + "/" + getRepository() + "/" + firstItem.get("path"); diff --git a/lib/BintrayClient/src/BintrayClient.h b/lib/BintrayClient/src/BintrayClient.h index 9761c7c6..d0b7e67d 100644 --- a/lib/BintrayClient/src/BintrayClient.h +++ b/lib/BintrayClient/src/BintrayClient.h @@ -1,4 +1,5 @@ /* + Parts of this file Copyright (c) 2014-present PlatformIO Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/platformio.ini b/platformio.ini index 0bd773fe..97148ac3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,8 +11,9 @@ ;env_default = heltec ;env_default = ttgov1 ;env_default = ttgov2 -env_default = ttgov21 -;env_default = ttgobeam +;env_default = ttgov21old +;env_default = ttgov21new +env_default = ttgobeam ;env_default = lopy ;env_default = lopy4 ;env_default = fipy @@ -25,14 +26,11 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng [bintray] user = cyberman54 repository = paxcounter-firmware -package = ttgov21_old api_token = 2e10f923df5d47b9c7e25752510322a1d65ee997 -[common] -release_version = 7 - [ota] -; build configuration based on Bintray and Wi-Fi settings +;release_version = max. 9 chars total, using decimal format "a.b.c" +release_version = 1.4.32 wifi_ssid = testnet wifi_password = test0815 build_flags = @@ -40,18 +38,24 @@ build_flags = '-DWIFI_PASS="${ota.wifi_password}"' '-DBINTRAY_USER="${bintray.user}"' '-DBINTRAY_REPO="${bintray.repository}"' - '-DBINTRAY_PACKAGE="${bintray.package}"' - -DVERSION=${common.release_version} -lib_deps_ota = - https://github.com/platformio/bintray-secure-ota.git + '-DBINTRAY_PACKAGE="${PIOENV}"' + '-DPROGVERSION="${ota.release_version}"' -[common_env_data] +[common] +; DEBUG LEVEL +; For production run setto 0, otherwise device will leak RAM while running! +; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose +debug_level = 0 +; UPLOAD MODE +; select esptool for USB/UART flashing, custom for OTA upload +upload_protocol = esptool +;upload_protocol = custom +extra_scripts = pre:publish_firmware.py platform_espressif32 = espressif32@1.3.0 -;platform_espressif32 = https://github.com/platformio/platform-espressif32.git#feature/stage board_build.partitions = min_spiffs.csv +monitor_speed = 115200 lib_deps_all = ArduinoJson@^5.13.1 -; ArduinoJson${ota.lib_deps_ota} lib_deps_display = U8g2@>=2.23.16 lib_deps_rgbled = @@ -59,204 +63,227 @@ lib_deps_rgbled = lib_deps_gps = TinyGPSPlus@>=1.0.2 Time@>=1.5 -build_flags = +build_flags = ; override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -include "src/paxcounter.conf" -include "src/hal/${PIOENV}.h" ${ota.build_flags} -w -; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- -; otherwise device may leak RAM -; -; None -; -DCORE_DEBUG_LEVEL=0 -; Error -; -DCORE_DEBUG_LEVEL=1 -; Warn -; -DCORE_DEBUG_LEVEL=2 -; Info - -DCORE_DEBUG_LEVEL=3 -; Debug -; -DCORE_DEBUG_LEVEL=4 -; Verbose -; -DCORE_DEBUG_LEVEL=5 + -DCORE_DEBUG_LEVEL=${common.debug_level} + [env:ebox] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = esp32dev -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 115200 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} + ${common.lib_deps_all} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} [env:heltec] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = heltec_wifi_lora_32 -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 115200 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_display} + ${common.lib_deps_all} + ${common.lib_deps_display} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} [env:ttgov1] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = esp32dev -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 115200 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_display} + ${common.lib_deps_all} + ${common.lib_deps_display} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} [env:ttgov2] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = esp32dev -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 921600 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_display} + ${common.lib_deps_all} + ${common.lib_deps_display} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} -[env:ttgov21] -platform = ${common_env_data.platform_espressif32} +[env:ttgov21old] +platform = ${common.platform_espressif32} framework = arduino board = esp32dev -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 921600 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_display} + ${common.lib_deps_all} + ${common.lib_deps_display} build_flags = - ${common_env_data.build_flags} -;upload_protocol = custom -;extra_scripts = pre:publish_firmware.py + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} +[env:ttgov21new] +platform = ${common.platform_espressif32} +framework = arduino +board = esp32dev +board_build.partitions = ${common.board_build.partitions} +upload_speed = 921600 +lib_deps = + ${common.lib_deps_all} + ${common.lib_deps_display} +build_flags = + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} [env:ttgobeam] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = esp32dev -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 921600 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_gps} + ${common.lib_deps_all} + ${common.lib_deps_gps} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} -mfix-esp32-psram-cache-issue -;upload_protocol = custom -;extra_scripts = pre:publish_firmware.py +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} [env:fipy] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = esp32dev -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 921600 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_rgbled} + ${common.lib_deps_all} + ${common.lib_deps_rgbled} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} [env:lopy] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = esp32dev -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 921600 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_rgbled} - ${common_env_data.lib_deps_gps} + ${common.lib_deps_all} + ${common.lib_deps_rgbled} + ${common.lib_deps_gps} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} [env:lopy4] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = esp32dev -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 921600 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_rgbled} - ${common_env_data.lib_deps_gps} + ${common.lib_deps_all} + ${common.lib_deps_rgbled} + ${common.lib_deps_gps} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} -mfix-esp32-psram-cache-issue +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} [env:lolin32litelora] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = lolin32 -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 921600 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_rgbled} + ${common.lib_deps_all} + ${common.lib_deps_rgbled} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} [env:lolin32lora] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = lolin32 -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 921600 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_rgbled} + ${common.lib_deps_all} + ${common.lib_deps_rgbled} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} [env:lolin32lite] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = lolin32 -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 921600 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_rgbled} + ${common.lib_deps_all} + ${common.lib_deps_rgbled} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} [env:generic] -platform = ${common_env_data.platform_espressif32} +platform = ${common.platform_espressif32} framework = arduino board = esp32dev -board_build.partitions = ${common_env_data.board_build.partitions} +board_build.partitions = ${common.board_build.partitions} upload_speed = 921600 -monitor_speed = 115200 lib_deps = - ${common_env_data.lib_deps_all} - ${common_env_data.lib_deps_rgbled} - ${common_env_data.lib_deps_gps} - ${common_env_data.lib_deps_display} + ${common.lib_deps_all} + ${common.lib_deps_rgbled} + ${common.lib_deps_gps} + ${common.lib_deps_display} build_flags = - ${common_env_data.build_flags} + ${common.build_flags} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} diff --git a/publish_firmware.py b/publish_firmware.py index 7086d013..b9848707 100644 --- a/publish_firmware.py +++ b/publish_firmware.py @@ -16,31 +16,30 @@ import requests from os.path import basename from platformio import util -Import('env') +Import("env") project_config = util.load_project_config() bintray_config = {k: v for k, v in project_config.items("bintray")} -version = project_config.get("common", "release_version") +version = project_config.get("ota", "release_version") +package = env.get("PIOENV") # # Push new firmware to the Bintray storage using API # -def publish_firmware(source, target, env): +def publish_bintray(source, target, env): firmware_path = str(source[0]) firmware_name = basename(firmware_path) print("Uploading {0} to Bintray. Version: {1}".format( firmware_name, version)) - print(firmware_path, firmware_name) - url = "/".join([ "https://api.bintray.com", "content", bintray_config.get("user"), bintray_config.get("repository"), - bintray_config.get("package"), version, firmware_name + package, version, firmware_name ]) print(url) @@ -65,7 +64,8 @@ def publish_firmware(source, target, env): # Custom upload command and program name + env.Replace( - PROGNAME="firmware_v_%s" % version, - UPLOADCMD=publish_firmware + PROGNAME="firmware_" + package + "_v%s" % version, + UPLOADCMD=publish_bintray ) \ No newline at end of file diff --git a/src/OTA.cpp b/src/OTA.cpp index 87609949..7f46ea85 100644 --- a/src/OTA.cpp +++ b/src/OTA.cpp @@ -59,16 +59,16 @@ void checkFirmwareUpdates() { // Fetch the latest firmware version ESP_LOGI(TAG, "OTA mode, checking latest firmware version on server..."); const String latest = bintray.getLatestVersion(); + if (latest.length() == 0) { ESP_LOGI( TAG, "Could not load info about the latest firmware. Rebooting to runmode."); return; - } else if (atoi(latest.c_str()) <= VERSION) { + } else if (version_compare(latest, cfg.version) <= 0) { ESP_LOGI(TAG, "Current firmware is up to date. Rebooting to runmode."); return; } - ESP_LOGI(TAG, "New firmware version v%s available. Downloading...", latest.c_str()); processOTAUpdate(latest); @@ -218,4 +218,39 @@ void processOTAUpdate(const String &version) { "There was no valid content in the response from the OTA server!"); client.flush(); } +} + +// helper function to compare two versions. Returns 1 if v2 is +// smaller, -1 if v1 is smaller, 0 if equal + +int version_compare(const String v1, const String v2) { + // vnum stores each numeric part of version + int vnum1 = 0, vnum2 = 0; + + // loop untill both string are processed + for (int i = 0, j = 0; (i < v1.length() || j < v2.length());) { + // storing numeric part of version 1 in vnum1 + while (i < v1.length() && v1[i] != '.') { + vnum1 = vnum1 * 10 + (v1[i] - '0'); + i++; + } + + // storing numeric part of version 2 in vnum2 + while (j < v2.length() && v2[j] != '.') { + vnum2 = vnum2 * 10 + (v2[j] - '0'); + j++; + } + + if (vnum1 > vnum2) + return 1; + if (vnum2 > vnum1) + return -1; + + // if equal, reset variables and go for next numeric + // part + vnum1 = vnum2 = 0; + i++; + j++; + } + return 0; } \ No newline at end of file diff --git a/src/OTA.h b/src/OTA.h index fc66973c..1a17fa24 100644 --- a/src/OTA.h +++ b/src/OTA.h @@ -1,6 +1,7 @@ #ifndef OTA_H #define OTA_H +#include "globals.h" #include #include #include @@ -9,5 +10,6 @@ void checkFirmwareUpdates(); void processOTAUpdate(const String &version); void start_ota_update(); +int version_compare(const String v1, const String v2); #endif // OTA_H \ No newline at end of file diff --git a/src/globals.h b/src/globals.h index 20acd5cb..fd057b5d 100644 --- a/src/globals.h +++ b/src/globals.h @@ -4,10 +4,6 @@ // The mother of all embedded development... #include -// attn: increment version after modifications to configData_t truct! -#define PROGVERSION "1.4.30" // use max 10 chars here! -#define PROGNAME "PAXCNT" - // std::set for unified array functions #include #include diff --git a/src/hal/ttgov21.h b/src/hal/ttgov21.h deleted file mode 100644 index 6d59065d..00000000 --- a/src/hal/ttgov21.h +++ /dev/null @@ -1,69 +0,0 @@ -/* Hardware related definitions for TTGO V2.1 Board -/ ATTENTION: check your board version! -/ Different versions are on the market which need different settings in this file: -/ - without label -> use settings (2) -/ - labeled V1.5 on pcb -> use settings (2) -/ - labeled V1.6 on pcb -> use settings (1) -/ Choose the right configuration below -*/ - -/* -// (1) settings for board labeled "T3_V1.6" on pcb - -#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 // HPD13A LoRa SoC - -#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C -#define HAS_LED GPIO_NUM_25 // green on board LED -#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // uses GPIO7 -#define BATT_FACTOR 2 // voltage divider 100k/100k on board - -// re-define pin definitions of pins_arduino.h -#define PIN_SPI_SS GPIO_NUM_18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input -#define PIN_SPI_MOSI GPIO_NUM_27 // ESP32 GPIO27 (Pin27) -- HPD13A MOSI/DSI (Pin6) SPI Data Input -#define PIN_SPI_MISO GPIO_NUM_19 // ESP32 GPIO19 (Pin19) -- HPD13A MISO/DSO (Pin7) SPI Data Output -#define PIN_SPI_SCK GPIO_NUM_5 // ESP32 GPIO5 (Pin5) -- HPD13A SCK (Pin5) SPI Clock Input - -// non arduino pin definitions -#define RST GPIO_NUM_23 // ESP32 GPIO23 <-> HPD13A RESET -#define DIO0 GPIO_NUM_26 // ESP32 GPIO26 <-> HPD13A IO0 -#define DIO1 GPIO_NUM_33 // ESP32 GPIO33 <-> HPDIO1 <-> HPD13A IO1 -#define DIO2 GPIO_NUM_32 // ESP32 GPIO32 <-> HPDIO2 <-> HPD13A IO2 - -// Hardware pin definitions for TTGO V2 Board with OLED SSD1306 0,96" I2C Display -#define OLED_RST U8X8_PIN_NONE // connected to CPU RST/EN -#define OLED_SDA GPIO_NUM_21 // ESP32 GPIO21 -- SD1306 D1+D2 -#define OLED_SCL GPIO_NUM_22 // ESP32 GPIO22 -- SD1306 D0 - -*/ - -// (2) settings for boards without label on pcb, or labeled v1.5 on pcb - -#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 // HPD13A LoRa SoC -#define HAS_LED NOT_A_PIN // no usable LED on board - -#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C -#define DISPLAY_FLIP 1 // rotated display -#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // uses GPIO7 -#define BATT_FACTOR 2 // voltage divider 100k/100k on board - -// re-define pin definitions of pins_arduino.h -#define PIN_SPI_SS GPIO_NUM_18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input -#define PIN_SPI_MOSI GPIO_NUM_27 // ESP32 GPIO27 (Pin27) -- HPD13A MOSI/DSI (Pin6) SPI Data Input -#define PIN_SPI_MISO GPIO_NUM_19 // ESP32 GPIO19 (Pin19) -- HPD13A MISO/DSO (Pin7) SPI Data Output -#define PIN_SPI_SCK GPIO_NUM_5 // ESP32 GPIO5 (Pin5) -- HPD13A SCK (Pin5) SPI Clock Input - -// non arduino pin definitions -#define RST LMIC_UNUSED_PIN // connected to ESP32 RST/EN (old board) -//#define RST GPIO_NUM_12 // (boards labeled v1.5) -#define DIO0 GPIO_NUM_26 // ESP32 GPIO26 <-> HPD13A IO0 -#define DIO1 GPIO_NUM_33 // ESP32 GPIO33 <-> HPDIO1 <-> HPD13A IO1 -#define DIO2 GPIO_NUM_32 // ESP32 GPIO32 <-> HPDIO2 <-> HPD13A IO2 - -// Hardware pin definitions for TTGO V2 Board with OLED SSD1306 0,96" I2C Display -#define OLED_RST U8X8_PIN_NONE // connected to CPU RST/EN -#define OLED_SDA GPIO_NUM_21 // ESP32 GPIO21 -- SD1306 D1+D2 -#define OLED_SCL GPIO_NUM_22 // ESP32 GPIO22 -- SD1306 D0 diff --git a/src/hal/ttgov21new.h b/src/hal/ttgov21new.h new file mode 100644 index 00000000..ce64323f --- /dev/null +++ b/src/hal/ttgov21new.h @@ -0,0 +1,30 @@ +/* Hardware related definitions for TTGO V2.1 Board +// ATTENTION: check your board version! +// This settings are for boards labeled v1.6 on pcb, NOT for v1.5 or older +*/ + +#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 // HPD13A LoRa SoC + +#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C +#define HAS_LED GPIO_NUM_25 // green on board LED +#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // uses GPIO7 +#define BATT_FACTOR 2 // voltage divider 100k/100k on board + +// re-define pin definitions of pins_arduino.h +#define PIN_SPI_SS GPIO_NUM_18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input +#define PIN_SPI_MOSI GPIO_NUM_27 // ESP32 GPIO27 (Pin27) -- HPD13A MOSI/DSI (Pin6) SPI Data Input +#define PIN_SPI_MISO GPIO_NUM_19 // ESP32 GPIO19 (Pin19) -- HPD13A MISO/DSO (Pin7) SPI Data Output +#define PIN_SPI_SCK GPIO_NUM_5 // ESP32 GPIO5 (Pin5) -- HPD13A SCK (Pin5) SPI Clock Input + +// non arduino pin definitions +#define RST GPIO_NUM_23 // ESP32 GPIO23 <-> HPD13A RESET +#define DIO0 GPIO_NUM_26 // ESP32 GPIO26 <-> HPD13A IO0 +#define DIO1 GPIO_NUM_33 // ESP32 GPIO33 <-> HPDIO1 <-> HPD13A IO1 +#define DIO2 GPIO_NUM_32 // ESP32 GPIO32 <-> HPDIO2 <-> HPD13A IO2 + +// Hardware pin definitions for TTGO V2 Board with OLED SSD1306 0,96" I2C Display +#define OLED_RST U8X8_PIN_NONE // connected to CPU RST/EN +#define OLED_SDA GPIO_NUM_21 // ESP32 GPIO21 -- SD1306 D1+D2 +#define OLED_SCL GPIO_NUM_22 // ESP32 GPIO22 -- SD1306 D0 \ No newline at end of file diff --git a/src/hal/ttgov21old.h b/src/hal/ttgov21old.h new file mode 100644 index 00000000..f6882187 --- /dev/null +++ b/src/hal/ttgov21old.h @@ -0,0 +1,32 @@ +/* Hardware related definitions for TTGO V2.1 Board +// ATTENTION: check your board version! +// This settings are for boards without label on pcb, or labeled v1.5 on pcb +*/ + +#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 // HPD13A LoRa SoC +#define HAS_LED NOT_A_PIN // no usable LED on board + +#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C +#define DISPLAY_FLIP 1 // rotated display +#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // uses GPIO7 +#define BATT_FACTOR 2 // voltage divider 100k/100k on board + +// re-define pin definitions of pins_arduino.h +#define PIN_SPI_SS GPIO_NUM_18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input +#define PIN_SPI_MOSI GPIO_NUM_27 // ESP32 GPIO27 (Pin27) -- HPD13A MOSI/DSI (Pin6) SPI Data Input +#define PIN_SPI_MISO GPIO_NUM_19 // ESP32 GPIO19 (Pin19) -- HPD13A MISO/DSO (Pin7) SPI Data Output +#define PIN_SPI_SCK GPIO_NUM_5 // ESP32 GPIO5 (Pin5) -- HPD13A SCK (Pin5) SPI Clock Input + +// non arduino pin definitions +#define RST LMIC_UNUSED_PIN // connected to ESP32 RST/EN (old board) +//#define RST GPIO_NUM_12 // (boards labeled v1.5) +#define DIO0 GPIO_NUM_26 // ESP32 GPIO26 <-> HPD13A IO0 +#define DIO1 GPIO_NUM_33 // ESP32 GPIO33 <-> HPDIO1 <-> HPD13A IO1 +#define DIO2 GPIO_NUM_32 // ESP32 GPIO32 <-> HPDIO2 <-> HPD13A IO2 + +// Hardware pin definitions for TTGO V2 Board with OLED SSD1306 0,96" I2C Display +#define OLED_RST U8X8_PIN_NONE // connected to CPU RST/EN +#define OLED_SDA GPIO_NUM_21 // ESP32 GPIO21 -- SD1306 D1+D2 +#define OLED_SCL GPIO_NUM_22 // ESP32 GPIO22 -- SD1306 D0 diff --git a/src/main.cpp b/src/main.cpp index 6de8432c..d84deb18 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -90,7 +90,7 @@ void setup() { esp_log_set_vprintf(redirect_log); #endif - ESP_LOGI(TAG, "Starting %s v%s", PROGNAME, PROGVERSION); + ESP_LOGI(TAG, "Starting %s v%s", PRODUCTNAME, PROGVERSION); // initialize system event handler for wifi task, needed for // wifi_sniffer_init() @@ -213,7 +213,7 @@ void setup() { #ifdef HAS_DISPLAY strcat_P(features, " OLED"); DisplayState = cfg.screenon; - init_display(PROGNAME, PROGVERSION); + init_display(PRODUCTNAME, PROGVERSION); // setup display refresh trigger IRQ using esp32 hardware timer // https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/ diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 68681b9b..92380894 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -4,6 +4,8 @@ // // Note: After editing, before "build", use "clean" button in PlatformIO! +#define PRODUCTNAME "PAXCNT" + // Verbose enables serial output #define VERBOSE 1 // comment out to silence the device, for mute use build option diff --git a/src/payload.cpp b/src/payload.cpp index 61514f94..38c2df76 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -52,8 +52,8 @@ void PayloadConvert::addConfig(configData_t value) { cursor += 10; } -void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, - float cputemp, uint32_t mem) { +void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, + uint32_t mem, uint8_t reset1, uint8_t reset2) { buffer[cursor++] = highByte(voltage); buffer[cursor++] = lowByte(voltage); @@ -124,6 +124,7 @@ void PayloadConvert::addConfig(configData_t value) { value.screenon ? true : false, value.countermode ? true : false, value.blescan ? true : false, value.wifiant ? true : false, value.vendorfilter ? true : false, value.gpsmode ? true : false); + writeVersion(value.version); } void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, @@ -160,6 +161,11 @@ void PayloadConvert::writeUptime(uint64_t uptime) { intToBytes(cursor, uptime, 8); } +void PayloadConvert::writeVersion(char * version) { + memcpy(buffer + cursor, version, 10); + cursor += 10; +} + void PayloadConvert::writeLatLng(double latitude, double longitude) { intToBytes(cursor, latitude, 4); intToBytes(cursor, longitude, 4); diff --git a/src/payload.h b/src/payload.h index 6cf453e5..5973bdd9 100644 --- a/src/payload.h +++ b/src/payload.h @@ -64,6 +64,7 @@ private: void writeUint8(uint8_t i); void writeHumidity(float humidity); void writeTemperature(float temperature); + void writeVersion(char * version); void writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, bool g, bool h);