From 5afa92395dedb87649a755d1a7f87ec29ec50af4 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 2 May 2023 15:04:23 -0500 Subject: [PATCH 01/19] Disable TX/RX EN in favor of power EN over TX_EN --- variants/diy/v1/variant.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/variants/diy/v1/variant.h b/variants/diy/v1/variant.h index 541edfa91..9ef2153be 100644 --- a/variants/diy/v1/variant.h +++ b/variants/diy/v1/variant.h @@ -38,8 +38,10 @@ #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET -#define SX126X_RXEN 14 -#define SX126X_TXEN 13 +//#define SX126X_RXEN 14 +//#define SX126X_TXEN 13 +#define SX126X_POWER_EN (13) +#define SX126X_E22 // RX/TX for RFM95/SX127x #define RF95_RXEN 14 From 6aa9e3787237e0178c7e2d9416078fa6b84fd6e9 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 2 May 2023 15:05:23 -0500 Subject: [PATCH 02/19] Oops --- variants/diy/v1/variant.h | 1 - 1 file changed, 1 deletion(-) diff --git a/variants/diy/v1/variant.h b/variants/diy/v1/variant.h index 9ef2153be..da9e41553 100644 --- a/variants/diy/v1/variant.h +++ b/variants/diy/v1/variant.h @@ -41,7 +41,6 @@ //#define SX126X_RXEN 14 //#define SX126X_TXEN 13 #define SX126X_POWER_EN (13) -#define SX126X_E22 // RX/TX for RFM95/SX127x #define RF95_RXEN 14 From 75504793e84f760c3c10a313d93d6ab8fe89d302 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 11 May 2023 06:52:27 -0500 Subject: [PATCH 03/19] Skip setting dio2 as rf switch altogether if txen is defined --- src/mesh/SX126xInterface.cpp | 15 ++++++++------- variants/diy/v1/variant.h | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index c26b773f7..a6a4e9dc2 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -60,19 +60,20 @@ template bool SX126xInterface::init() LOG_DEBUG("Current limit set to %f\n", currentLimit); LOG_DEBUG("Current limit set result %d\n", res); -#ifdef SX126X_E22 - // E22 Emulation explicitly requires DIO2 as RF switch, so set it to TRUE again for good measure. In case somebody defines - // SX126X_TX for an E22 Module - if (res == RADIOLIB_ERR_NONE) - res = lora.setDio2AsRfSwitch(true); -#endif - #if defined(SX126X_TXEN) && (SX126X_TXEN != RADIOLIB_NC) // lora.begin sets Dio2 as RF switch control, which is not true if we are manually controlling RX and TX if (res == RADIOLIB_ERR_NONE) { + LOG_DEBUG("SX126X_TX/RX EN pins defined. Setting RF Switch: RXEN=%i, TXEN=%i\n", SX126X_RXEN, SX126X_TXEN); res = lora.setDio2AsRfSwitch(false); lora.setRfSwitchPins(SX126X_RXEN, SX126X_TXEN); } +#elif defined(SX126X_E22) + // E22 Emulation explicitly requires DIO2 as RF switch, so set it to TRUE again for good measure. In case somebody defines + // SX126X_TX for an E22 Module + if (res == RADIOLIB_ERR_NONE) { + LOG_DEBUG("SX126X_E22 mode enabled. Setting DIO2 as RF Switch\n"); + res = lora.setDio2AsRfSwitch(true); + } #endif if (config.lora.sx126x_rx_boosted_gain) { diff --git a/variants/diy/v1/variant.h b/variants/diy/v1/variant.h index da9e41553..51bc0f749 100644 --- a/variants/diy/v1/variant.h +++ b/variants/diy/v1/variant.h @@ -38,9 +38,9 @@ #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET -//#define SX126X_RXEN 14 -//#define SX126X_TXEN 13 -#define SX126X_POWER_EN (13) +#define SX126X_RXEN 14 +#define SX126X_TXEN 13 +//#define SX126X_POWER_EN (13) // RX/TX for RFM95/SX127x #define RF95_RXEN 14 From f7e1f4cea664e35c43c345d9113060088913c05f Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 11 May 2023 19:56:55 -0500 Subject: [PATCH 04/19] Fix hydra (for real this time) --- variants/diy/v1/variant.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/variants/diy/v1/variant.h b/variants/diy/v1/variant.h index 51bc0f749..c47437643 100644 --- a/variants/diy/v1/variant.h +++ b/variants/diy/v1/variant.h @@ -38,9 +38,8 @@ #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET -#define SX126X_RXEN 14 +#define SX126X_RXEN RADIOLIB_NC // Defining the RXEN ruins RFSwitching for the E22 900M30S in RadioLib #define SX126X_TXEN 13 -//#define SX126X_POWER_EN (13) // RX/TX for RFM95/SX127x #define RF95_RXEN 14 From 6cdf2817f43c345455fc083d1feef73cf56ac83c Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 11 May 2023 20:09:34 -0500 Subject: [PATCH 05/19] Put this back in place --- src/mesh/SX126xInterface.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index a6a4e9dc2..5305adfe8 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -60,6 +60,15 @@ template bool SX126xInterface::init() LOG_DEBUG("Current limit set to %f\n", currentLimit); LOG_DEBUG("Current limit set result %d\n", res); +#if defined(SX126X_E22) + // E22 Emulation explicitly requires DIO2 as RF switch, so set it to TRUE again for good measure. In case somebody defines + // SX126X_TX for an E22 Module + if (res == RADIOLIB_ERR_NONE) { + LOG_DEBUG("SX126X_E22 mode enabled. Setting DIO2 as RF Switch\n"); + res = lora.setDio2AsRfSwitch(true); + } +#endif + #if defined(SX126X_TXEN) && (SX126X_TXEN != RADIOLIB_NC) // lora.begin sets Dio2 as RF switch control, which is not true if we are manually controlling RX and TX if (res == RADIOLIB_ERR_NONE) { @@ -67,13 +76,6 @@ template bool SX126xInterface::init() res = lora.setDio2AsRfSwitch(false); lora.setRfSwitchPins(SX126X_RXEN, SX126X_TXEN); } -#elif defined(SX126X_E22) - // E22 Emulation explicitly requires DIO2 as RF switch, so set it to TRUE again for good measure. In case somebody defines - // SX126X_TX for an E22 Module - if (res == RADIOLIB_ERR_NONE) { - LOG_DEBUG("SX126X_E22 mode enabled. Setting DIO2 as RF Switch\n"); - res = lora.setDio2AsRfSwitch(true); - } #endif if (config.lora.sx126x_rx_boosted_gain) { From c52fddac53679dc447258852cb8e6a729c942816 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 12 May 2023 08:38:30 -0500 Subject: [PATCH 06/19] Adding device.is_managed protobuf (#2487) --- protobufs | 2 +- src/mesh/generated/meshtastic/config.pb.h | 13 +++++++++---- src/mesh/generated/meshtastic/deviceonly.pb.h | 2 +- src/mesh/generated/meshtastic/localonly.pb.h | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/protobufs b/protobufs index e84f0cc7c..345b3bf10 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit e84f0cc7cab2879b00085000589b9fd6527d0d68 +Subproject commit 345b3bf103237503459457ac2b74f4fedf2db102 diff --git a/src/mesh/generated/meshtastic/config.pb.h b/src/mesh/generated/meshtastic/config.pb.h index e3b6e242d..f858d46f8 100644 --- a/src/mesh/generated/meshtastic/config.pb.h +++ b/src/mesh/generated/meshtastic/config.pb.h @@ -233,6 +233,9 @@ typedef struct _meshtastic_Config_DeviceConfig { uint32_t node_info_broadcast_secs; /* Treat double tap interrupt on supported accelerometers as a button press if set to true */ bool double_tap_as_button_press; + /* If true, device is considered to be "managed" by a mesh administrator + Clients should then limit available configuration and administrative options inside the user interface */ + bool is_managed; } meshtastic_Config_DeviceConfig; /* Position Config */ @@ -529,7 +532,7 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_Config_init_default {0, {meshtastic_Config_DeviceConfig_init_default}} -#define meshtastic_Config_DeviceConfig_init_default {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0} +#define meshtastic_Config_DeviceConfig_init_default {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0, 0} #define meshtastic_Config_PositionConfig_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Config_PowerConfig_init_default {0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Config_NetworkConfig_init_default {0, "", "", "", 0, _meshtastic_Config_NetworkConfig_AddressMode_MIN, false, meshtastic_Config_NetworkConfig_IpV4Config_init_default, ""} @@ -538,7 +541,7 @@ extern "C" { #define meshtastic_Config_LoRaConfig_init_default {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}} #define meshtastic_Config_BluetoothConfig_init_default {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0} #define meshtastic_Config_init_zero {0, {meshtastic_Config_DeviceConfig_init_zero}} -#define meshtastic_Config_DeviceConfig_init_zero {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0} +#define meshtastic_Config_DeviceConfig_init_zero {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0, 0} #define meshtastic_Config_PositionConfig_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Config_PowerConfig_init_zero {0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Config_NetworkConfig_init_zero {0, "", "", "", 0, _meshtastic_Config_NetworkConfig_AddressMode_MIN, false, meshtastic_Config_NetworkConfig_IpV4Config_init_zero, ""} @@ -556,6 +559,7 @@ extern "C" { #define meshtastic_Config_DeviceConfig_rebroadcast_mode_tag 6 #define meshtastic_Config_DeviceConfig_node_info_broadcast_secs_tag 7 #define meshtastic_Config_DeviceConfig_double_tap_as_button_press_tag 8 +#define meshtastic_Config_DeviceConfig_is_managed_tag 9 #define meshtastic_Config_PositionConfig_position_broadcast_secs_tag 1 #define meshtastic_Config_PositionConfig_position_broadcast_smart_enabled_tag 2 #define meshtastic_Config_PositionConfig_fixed_position_tag 3 @@ -650,7 +654,8 @@ X(a, STATIC, SINGULAR, UINT32, button_gpio, 4) \ X(a, STATIC, SINGULAR, UINT32, buzzer_gpio, 5) \ X(a, STATIC, SINGULAR, UENUM, rebroadcast_mode, 6) \ X(a, STATIC, SINGULAR, UINT32, node_info_broadcast_secs, 7) \ -X(a, STATIC, SINGULAR, BOOL, double_tap_as_button_press, 8) +X(a, STATIC, SINGULAR, BOOL, double_tap_as_button_press, 8) \ +X(a, STATIC, SINGULAR, BOOL, is_managed, 9) #define meshtastic_Config_DeviceConfig_CALLBACK NULL #define meshtastic_Config_DeviceConfig_DEFAULT NULL @@ -765,7 +770,7 @@ extern const pb_msgdesc_t meshtastic_Config_BluetoothConfig_msg; /* Maximum encoded size of messages (where known) */ #define meshtastic_Config_BluetoothConfig_size 10 -#define meshtastic_Config_DeviceConfig_size 28 +#define meshtastic_Config_DeviceConfig_size 30 #define meshtastic_Config_DisplayConfig_size 28 #define meshtastic_Config_LoRaConfig_size 77 #define meshtastic_Config_NetworkConfig_IpV4Config_size 20 diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index d08c18ba9..3f28faae8 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -196,7 +196,7 @@ extern const pb_msgdesc_t meshtastic_OEMStore_msg; /* Maximum encoded size of messages (where known) */ #define meshtastic_ChannelFile_size 638 #define meshtastic_DeviceState_size 22364 -#define meshtastic_OEMStore_size 3041 +#define meshtastic_OEMStore_size 3043 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/meshtastic/localonly.pb.h b/src/mesh/generated/meshtastic/localonly.pb.h index 0cfcb2491..15b7b2b43 100644 --- a/src/mesh/generated/meshtastic/localonly.pb.h +++ b/src/mesh/generated/meshtastic/localonly.pb.h @@ -156,7 +156,7 @@ extern const pb_msgdesc_t meshtastic_LocalModuleConfig_msg; #define meshtastic_LocalModuleConfig_fields &meshtastic_LocalModuleConfig_msg /* Maximum encoded size of messages (where known) */ -#define meshtastic_LocalConfig_size 456 +#define meshtastic_LocalConfig_size 458 #define meshtastic_LocalModuleConfig_size 439 #ifdef __cplusplus From 7711b03bd84360168b00ec388306e98512abeb9a Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 12 May 2023 08:38:53 -0500 Subject: [PATCH 07/19] Update nrf and esp32 platform versions (#2486) --- arch/esp32/esp32.ini | 2 +- arch/nrf52/nrf52.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/esp32/esp32.ini b/arch/esp32/esp32.ini index 45409ad7b..961b41852 100644 --- a/arch/esp32/esp32.ini +++ b/arch/esp32/esp32.ini @@ -1,7 +1,7 @@ ; Common settings for ESP targes, mixin with extends = esp32_base [esp32_base] extends = arduino_base -platform = platformio/espressif32@^6.1.0 +platform = platformio/espressif32@^6.2.0 build_src_filter = ${arduino_base.build_src_filter} - - - - diff --git a/arch/nrf52/nrf52.ini b/arch/nrf52/nrf52.ini index 3f1a77d08..d471e24c5 100644 --- a/arch/nrf52/nrf52.ini +++ b/arch/nrf52/nrf52.ini @@ -1,6 +1,6 @@ [nrf52_base] ; Instead of the standard nordicnrf52 platform, we use our fork which has our added variant files -platform = platformio/nordicnrf52@^9.5.0 +platform = platformio/nordicnrf52@^9.6.0 extends = arduino_base build_type = debug ; I'm debugging with ICE a lot now From cf07d2dbcdaa348cf6636de641c9246934bcd43d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 12 May 2023 20:48:26 -0500 Subject: [PATCH 08/19] [create-pull-request] automated change (#2488) Co-authored-by: thebentern --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 0e33ac38b..32b1f1a72 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 1 -build = 12 +build = 13 From 9c683f4c878d87bb7c961c22322b6c0ce5c19337 Mon Sep 17 00:00:00 2001 From: IhorNehrutsa <70886343+IhorNehrutsa@users.noreply.github.com> Date: Sat, 13 May 2023 13:33:14 +0300 Subject: [PATCH 09/19] Fix LOG_DEBUG messages when no DEBUG_PORT. (#2485) * Fix LOG_DEBUG messages when no DEBUG_PORT. * Fix LOG_DEBUG messages when no DEBUG_PORT. * Fix LOG_DEBUG messages when no DEBUG_PORT. * Fix LOG_DEBUG messages when no DEBUG_PORT. --- src/DebugConfiguration.h | 1 + src/GPSStatus.h | 3 ++- src/concurrency/NotifiedWorkerThread.cpp | 9 ++++++--- src/concurrency/OSThread.cpp | 9 ++++++--- src/graphics/Screen.cpp | 2 ++ src/main.cpp | 5 +++-- src/mesh/Channels.cpp | 3 ++- src/mesh/MeshModule.cpp | 3 ++- src/mesh/NodeDB.cpp | 14 +++++++++----- src/mesh/PhoneAPI.cpp | 3 ++- src/mesh/RadioInterface.cpp | 2 ++ src/mesh/RadioLibInterface.cpp | 10 ++++++---- src/mesh/ReliableRouter.cpp | 7 ++++--- src/mesh/Router.cpp | 6 ++++-- src/mesh/SX126xInterface.cpp | 3 ++- src/mesh/SX128xInterface.cpp | 3 ++- src/modules/PositionModule.cpp | 3 ++- src/modules/ReplyModule.cpp | 2 ++ src/modules/Telemetry/AirQualityTelemetry.cpp | 3 ++- src/modules/Telemetry/DeviceTelemetry.cpp | 3 ++- src/modules/Telemetry/EnvironmentTelemetry.cpp | 3 ++- src/modules/Telemetry/Sensor/BME680Sensor.cpp | 6 ++++-- src/modules/TextMessageModule.cpp | 2 ++ src/modules/TraceRouteModule.cpp | 2 ++ src/modules/WaypointModule.cpp | 2 ++ src/modules/esp32/AudioModule.cpp | 9 ++++++--- src/mqtt/MQTT.cpp | 6 ++++-- src/sleep.cpp | 14 ++++++++++---- 28 files changed, 95 insertions(+), 43 deletions(-) diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 36b009ff2..59ce043bc 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -28,6 +28,7 @@ #define DEBUG_PORT (*console) // Serial debug port #ifdef USE_SEGGER +#define DEBUG_PORT #define LOG_DEBUG(...) SEGGER_RTT_printf(0, __VA_ARGS__) #define LOG_INFO(...) SEGGER_RTT_printf(0, __VA_ARGS__) #define LOG_WARN(...) SEGGER_RTT_printf(0, __VA_ARGS__) diff --git a/src/GPSStatus.h b/src/GPSStatus.h index bdfce36ff..6b760385f 100644 --- a/src/GPSStatus.h +++ b/src/GPSStatus.h @@ -138,8 +138,9 @@ class GPSStatus : public Status LOG_DEBUG("New GPS pos@%x:3 lat=%f, lon=%f, alt=%d, pdop=%.2f, track=%.2f, speed=%.2f, sats=%d\n", p.timestamp, p.latitude_i * 1e-7, p.longitude_i * 1e-7, p.altitude, p.PDOP * 1e-2, p.ground_track * 1e-5, p.ground_speed * 1e-2, p.sats_in_view); - } else + } else { LOG_DEBUG("No GPS lock\n"); + } onNewStatus.notifyObservers(this); } return 0; diff --git a/src/concurrency/NotifiedWorkerThread.cpp b/src/concurrency/NotifiedWorkerThread.cpp index 39a594c5a..271e3e60d 100644 --- a/src/concurrency/NotifiedWorkerThread.cpp +++ b/src/concurrency/NotifiedWorkerThread.cpp @@ -31,12 +31,14 @@ IRAM_ATTR bool NotifiedWorkerThread::notifyCommon(uint32_t v, bool overwrite) runASAP = true; notification = v; - if (debugNotification) + if (debugNotification) { LOG_DEBUG("setting notification %d\n", v); + } return true; } else { - if (debugNotification) + if (debugNotification) { LOG_DEBUG("dropping notification %d\n", v); + } return false; } } @@ -64,8 +66,9 @@ bool NotifiedWorkerThread::notifyLater(uint32_t delay, uint32_t v, bool overwrit if (didIt) { // If we didn't already have something queued, override the delay to be larger setIntervalFromNow(delay); // a new version of setInterval relative to the current time - if (debugNotification) + if (debugNotification) { LOG_DEBUG("delaying notification %u\n", delay); + } } return didIt; diff --git a/src/concurrency/OSThread.cpp b/src/concurrency/OSThread.cpp index c71d3510e..f23cbe1dc 100644 --- a/src/concurrency/OSThread.cpp +++ b/src/concurrency/OSThread.cpp @@ -61,14 +61,17 @@ bool OSThread::shouldRun(unsigned long time) { bool r = Thread::shouldRun(time); - if (showRun && r) + if (showRun && r) { LOG_DEBUG("Thread %s: run\n", ThreadName.c_str()); + } - if (showWaiting && enabled && !r) + if (showWaiting && enabled && !r) { LOG_DEBUG("Thread %s: wait %lu\n", ThreadName.c_str(), interval); + } - if (showDisabled && !enabled) + if (showDisabled && !enabled) { LOG_DEBUG("Thread %s: disabled\n", ThreadName.c_str()); + } return r; } diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 219214091..072a9d14d 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1239,8 +1239,10 @@ void Screen::setFrames() moduleFrames = MeshModule::GetMeshModulesWithUIFrames(); LOG_DEBUG("Showing %d module frames\n", moduleFrames.size()); +#ifdef DEBUG_PORT int totalFrameCount = MAX_NUM_NODES + NUM_EXTRA_FRAMES + moduleFrames.size(); LOG_DEBUG("Total frame count: %d\n", totalFrameCount); +#endif // We don't show the node info our our node (if we have it yet - we should) size_t numnodes = nodeDB.getNumNodes(); diff --git a/src/main.cpp b/src/main.cpp index 324422a69..202dce549 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -462,10 +462,11 @@ void setup() gps = createGps(); - if (gps) + if (gps) { gpsStatus->observe(&gps->newStatus); - else + } else { LOG_WARN("No GPS found - running without GPS\n"); + } nodeStatus->observe(&nodeDB.newStatus); diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 5e2cb41ba..2a0b5ee39 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -108,8 +108,9 @@ CryptoKey Channels::getKey(ChannelIndex chIndex) if (ch.role == meshtastic_Channel_Role_SECONDARY) { LOG_DEBUG("Unset PSK for secondary channel %s. using primary key\n", ch.settings.name); k = getKey(primaryIndex); - } else + } else { LOG_WARN("User disabled encryption\n"); + } } else if (k.length == 1) { // Convert the short single byte variants of psk into variant that can be used more generally diff --git a/src/mesh/MeshModule.cpp b/src/mesh/MeshModule.cpp index d8dbf8a3a..55948b33f 100644 --- a/src/mesh/MeshModule.cpp +++ b/src/mesh/MeshModule.cpp @@ -179,9 +179,10 @@ void MeshModule::callPlugins(const meshtastic_MeshPacket &mp, RxSource src) } } - if (!moduleFound) + if (!moduleFound) { LOG_DEBUG("No modules interested in portnum=%d, src=%s\n", mp.decoded.portnum, (src == RX_SRC_LOCAL) ? "LOCAL" : "REMOTE"); + } } meshtastic_MeshPacket *MeshModule::allocReply() diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 5ee839b80..c64468d05 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -468,8 +468,9 @@ void NodeDB::loadFromDisk() } } - if (loadProto(oemConfigFile, meshtastic_OEMStore_size, sizeof(meshtastic_OEMStore), &meshtastic_OEMStore_msg, &oemStore)) + if (loadProto(oemConfigFile, meshtastic_OEMStore_size, sizeof(meshtastic_OEMStore), &meshtastic_OEMStore_msg, &oemStore)) { LOG_INFO("Loaded OEMStore\n"); + } } /** Save a protobuf from a file, return true for success */ @@ -494,10 +495,12 @@ bool NodeDB::saveProto(const char *filename, size_t protoSize, const pb_msgdesc_ f.close(); // brief window of risk here ;-) - if (FSCom.exists(filename) && !FSCom.remove(filename)) + if (FSCom.exists(filename) && !FSCom.remove(filename)) { LOG_WARN("Can't remove old pref file\n"); - if (!renameFile(filenameTmp.c_str(), filename)) + } + if (!renameFile(filenameTmp.c_str(), filename)) { LOG_ERROR("Error: can't rename new pref file\n"); + } } else { LOG_ERROR("Can't write prefs\n"); #ifdef ARCH_NRF52 @@ -802,10 +805,11 @@ void recordCriticalError(meshtastic_CriticalErrorCode code, uint32_t address, co // Print error to screen and serial port String lcd = String("Critical error ") + code + "!\n"; screen->print(lcd.c_str()); - if (filename) + if (filename) { LOG_ERROR("NOTE! Recording critical error %d at %s:%lu\n", code, filename, address); - else + } else { LOG_ERROR("NOTE! Recording critical error %d, address=0x%lx\n", code, address); + } // Record error to DB myNodeInfo.error_code = code; diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index cdda05913..559f7ed31 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -423,8 +423,9 @@ int PhoneAPI::onNotify(uint32_t newValue) if (state == STATE_SEND_PACKETS) { LOG_INFO("Telling client we have new packets %u\n", newValue); onNowHasData(newValue); - } else + } else { LOG_DEBUG("(Client not yet interested in packets)\n"); + } return 0; } diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 0d53dc887..1eee86c8e 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -241,6 +241,7 @@ uint32_t RadioInterface::getTxDelayMsecWeighted(float snr) void printPacket(const char *prefix, const meshtastic_MeshPacket *p) { +#ifdef DEBUG_PORT std::string out = DEBUG_PORT.mt_sprintf("%s (id=0x%08x fr=0x%02x to=0x%02x, WantAck=%d, HopLim=%d Ch=0x%x", prefix, p->id, p->from & 0xff, p->to & 0xff, p->want_ack, p->hop_limit, p->channel); if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { @@ -283,6 +284,7 @@ void printPacket(const char *prefix, const meshtastic_MeshPacket *p) out += ")"; LOG_DEBUG("%s\n", out.c_str()); +#endif } RadioInterface::RadioInterface() diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 8fd715718..bce6b8a97 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -78,8 +78,9 @@ bool RadioLibInterface::canSendImmediately() bool busyRx = isReceiving && isActivelyReceiving(); if (busyTx || busyRx) { - if (busyTx) + if (busyTx) { LOG_WARN("Can not send yet, busyTx\n"); + } // If we've been trying to send the same packet more than one minute and we haven't gotten a // TX IRQ from the radio, the radio is probably broken. if (busyTx && (millis() - lastTxStart > 60000)) { @@ -88,8 +89,9 @@ bool RadioLibInterface::canSendImmediately() // reboot in 5 seconds when this condition occurs. rebootAtMsec = lastTxStart + 65000; } - if (busyRx) + if (busyRx) { LOG_WARN("Can not send yet, busyRx\n"); + } return false; } else return true; @@ -164,9 +166,9 @@ meshtastic_QueueStatus RadioLibInterface::getQueueStatus() bool RadioLibInterface::canSleep() { bool res = txQueue.empty(); - if (!res) // only print debug messages if we are vetoing sleep + if (!res) { // only print debug messages if we are vetoing sleep LOG_DEBUG("radio wait to sleep, txEmpty=%d\n", res); - + } return res; } diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index 7f5c9b7fc..946a669cc 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -104,13 +104,14 @@ void ReliableRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtas if (p->to == ourNode) { // ignore ack/nak/want_ack packets that are not address to us (we only handle 0 hop reliability) if (p->want_ack) { - if (MeshModule::currentReply) + if (MeshModule::currentReply) { LOG_DEBUG("Some other module has replied to this message, no need for a 2nd ack\n"); - else if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) + } else if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { sendAckNak(meshtastic_Routing_Error_NONE, getFrom(p), p->id, p->channel); - else + } else { // Send a 'NO_CHANNEL' error on the primary channel if want_ack packet destined for us cannot be decoded sendAckNak(meshtastic_Routing_Error_NO_CHANNEL, getFrom(p), p->id, channels.getPrimaryIndex()); + } } // We consider an ack to be either a !routing packet with a request ID or a routing packet with !error diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index e85d85450..156b48209 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -211,8 +211,10 @@ ErrorCode Router::send(meshtastic_MeshPacket *p) if (!config.lora.override_duty_cycle && myRegion->dutyCycle < 100) { float hourlyTxPercent = airTime->utilizationTXPercent(); if (hourlyTxPercent > myRegion->dutyCycle) { +#ifdef DEBUG_PORT uint8_t silentMinutes = airTime->getSilentMinutes(hourlyTxPercent, myRegion->dutyCycle); LOG_WARN("Duty cycle limit exceeded. Aborting send for now, you can send again in %d minutes.\n", silentMinutes); +#endif meshtastic_Routing_Error err = meshtastic_Routing_Error_DUTY_CYCLE_LIMIT; if (getFrom(p) == nodeDB.getNodeNum()) { // only send NAK to API, not to the mesh abortSendAndNak(err, p); @@ -479,9 +481,9 @@ void Router::perhapsHandleReceived(meshtastic_MeshPacket *p) // assert(radioConfig.has_preferences); bool ignore = is_in_repeated(config.lora.ignore_incoming, p->from); - if (ignore) + if (ignore) { LOG_DEBUG("Ignoring incoming message, 0x%x is in our ignore list\n", p->from); - else if (ignore |= shouldFilterReceived(p)) { + } else if (ignore |= shouldFilterReceived(p)) { LOG_DEBUG("Incoming message was filtered 0x%x\n", p->from); } diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 5305adfe8..495840d50 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -179,8 +179,9 @@ template void SX126xInterface::setStandby() int err = lora.standby(); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_DEBUG("SX126x standby failed with error %d\n", err); + } assert(err == RADIOLIB_ERR_NONE); diff --git a/src/mesh/SX128xInterface.cpp b/src/mesh/SX128xInterface.cpp index 691d5dff0..9c3ec3e91 100644 --- a/src/mesh/SX128xInterface.cpp +++ b/src/mesh/SX128xInterface.cpp @@ -151,8 +151,9 @@ template void SX128xInterface::setStandby() int err = lora.standby(); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("SX128x standby failed with error %d\n", err); + } assert(err == RADIOLIB_ERR_NONE); diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index ade96fb8a..89503d2b9 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -112,8 +112,9 @@ meshtastic_MeshPacket *PositionModule::allocReply() if (getRTCQuality() < RTCQualityDevice) { LOG_INFO("Stripping time %u from position send\n", p.time); p.time = 0; - } else + } else { LOG_INFO("Providing time to mesh %u\n", p.time); + } LOG_INFO("Position reply: time=%i, latI=%i, lonI=-%i\n", p.time, p.latitude_i, p.longitude_i); diff --git a/src/modules/ReplyModule.cpp b/src/modules/ReplyModule.cpp index 3bfad28ad..439f6b7f7 100644 --- a/src/modules/ReplyModule.cpp +++ b/src/modules/ReplyModule.cpp @@ -8,10 +8,12 @@ meshtastic_MeshPacket *ReplyModule::allocReply() { assert(currentRequest); // should always be !NULL +#ifdef DEBUG_PORT auto req = *currentRequest; auto &p = req.decoded; // The incoming message is in p.payload LOG_INFO("Received message from=0x%0x, id=%d, msg=%.*s\n", req.from, req.id, p.payload.size, p.payload.bytes); +#endif screen->print("Sending reply\n"); diff --git a/src/modules/Telemetry/AirQualityTelemetry.cpp b/src/modules/Telemetry/AirQualityTelemetry.cpp index de74c0bf9..f87ea504b 100644 --- a/src/modules/Telemetry/AirQualityTelemetry.cpp +++ b/src/modules/Telemetry/AirQualityTelemetry.cpp @@ -59,6 +59,7 @@ int32_t AirQualityTelemetryModule::runOnce() bool AirQualityTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t) { if (t->which_variant == meshtastic_Telemetry_air_quality_metrics_tag) { +#ifdef DEBUG_PORT const char *sender = getSenderShortName(mp); LOG_INFO("(Received from %s): pm10_standard=%i, pm25_standard=%i, pm100_standard=%i\n", sender, @@ -68,7 +69,7 @@ bool AirQualityTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPack LOG_INFO(" | PM1.0(Environmental)=%i, PM2.5(Environmental)=%i, PM10.0(Environmental)=%i\n", t->variant.air_quality_metrics.pm10_environmental, t->variant.air_quality_metrics.pm25_environmental, t->variant.air_quality_metrics.pm100_environmental); - +#endif // release previous packet before occupying a new spot if (lastMeasurementPacket != nullptr) packetPool.release(lastMeasurementPacket); diff --git a/src/modules/Telemetry/DeviceTelemetry.cpp b/src/modules/Telemetry/DeviceTelemetry.cpp index 199a90209..696429aeb 100644 --- a/src/modules/Telemetry/DeviceTelemetry.cpp +++ b/src/modules/Telemetry/DeviceTelemetry.cpp @@ -31,12 +31,13 @@ int32_t DeviceTelemetryModule::runOnce() bool DeviceTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t) { if (t->which_variant == meshtastic_Telemetry_device_metrics_tag) { +#ifdef DEBUG_PORT const char *sender = getSenderShortName(mp); LOG_INFO("(Received from %s): air_util_tx=%f, channel_utilization=%f, battery_level=%i, voltage=%f\n", sender, t->variant.device_metrics.air_util_tx, t->variant.device_metrics.channel_utilization, t->variant.device_metrics.battery_level, t->variant.device_metrics.voltage); - +#endif nodeDB.updateTelemetry(getFrom(&mp), *t, RX_SRC_RADIO); } return false; // Let others look at this message also if they want diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 3b8a7dda1..bf0ca6182 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -183,6 +183,7 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t) { if (t->which_variant == meshtastic_Telemetry_environment_metrics_tag) { +#ifdef DEBUG_PORT const char *sender = getSenderShortName(mp); LOG_INFO("(Received from %s): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, " @@ -190,7 +191,7 @@ bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPac sender, t->variant.environment_metrics.barometric_pressure, t->variant.environment_metrics.current, t->variant.environment_metrics.gas_resistance, t->variant.environment_metrics.relative_humidity, t->variant.environment_metrics.temperature, t->variant.environment_metrics.voltage); - +#endif // release previous packet before occupying a new spot if (lastMeasurementPacket != nullptr) packetPool.release(lastMeasurementPacket); diff --git a/src/modules/Telemetry/Sensor/BME680Sensor.cpp b/src/modules/Telemetry/Sensor/BME680Sensor.cpp index 43e4c0386..6e28aac06 100644 --- a/src/modules/Telemetry/Sensor/BME680Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BME680Sensor.cpp @@ -92,10 +92,12 @@ void BME680Sensor::updateState() file.flush(); file.close(); // brief window of risk here ;-) - if (FSCom.exists(bsecConfigFileName) && !FSCom.remove(bsecConfigFileName)) + if (FSCom.exists(bsecConfigFileName) && !FSCom.remove(bsecConfigFileName)) { LOG_WARN("Can't remove old state file\n"); - if (!renameFile(filenameTmp.c_str(), bsecConfigFileName)) + } + if (!renameFile(filenameTmp.c_str(), bsecConfigFileName)) { LOG_ERROR("Error: can't rename new state file\n"); + } } else { LOG_INFO("Can't write %s state (File: %s).\n", sensorName, bsecConfigFileName); diff --git a/src/modules/TextMessageModule.cpp b/src/modules/TextMessageModule.cpp index 0fa175a14..8ff034fa9 100644 --- a/src/modules/TextMessageModule.cpp +++ b/src/modules/TextMessageModule.cpp @@ -7,8 +7,10 @@ TextMessageModule *textMessageModule; ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp) { +#ifdef DEBUG_PORT auto &p = mp.decoded; LOG_INFO("Received text msg from=0x%0x, id=0x%x, msg=%.*s\n", mp.from, mp.id, p.payload.size, p.payload.bytes); +#endif // We only store/display messages destined for us. // Keep a copy of the most recent text message. diff --git a/src/modules/TraceRouteModule.cpp b/src/modules/TraceRouteModule.cpp index 14396266d..f26c40d2f 100644 --- a/src/modules/TraceRouteModule.cpp +++ b/src/modules/TraceRouteModule.cpp @@ -47,6 +47,7 @@ void TraceRouteModule::appendMyID(meshtastic_RouteDiscovery *updated) void TraceRouteModule::printRoute(meshtastic_RouteDiscovery *r, uint32_t origin, uint32_t dest) { +#ifdef DEBUG_PORT LOG_INFO("Route traced:\n"); LOG_INFO("0x%x --> ", origin); for (uint8_t i = 0; i < r->route_count; i++) { @@ -56,6 +57,7 @@ void TraceRouteModule::printRoute(meshtastic_RouteDiscovery *r, uint32_t origin, LOG_INFO("0x%x\n", dest); else LOG_INFO("...\n"); +#endif } meshtastic_MeshPacket *TraceRouteModule::allocReply() diff --git a/src/modules/WaypointModule.cpp b/src/modules/WaypointModule.cpp index f95bdec34..83485c8ee 100644 --- a/src/modules/WaypointModule.cpp +++ b/src/modules/WaypointModule.cpp @@ -7,8 +7,10 @@ WaypointModule *waypointModule; ProcessMessage WaypointModule::handleReceived(const meshtastic_MeshPacket &mp) { +#ifdef DEBUG_PORT auto &p = mp.decoded; LOG_INFO("Received waypoint msg from=0x%0x, id=0x%x, msg=%.*s\n", mp.from, mp.id, p.payload.size, p.payload.bytes); +#endif // We only store/display messages destined for us. // Keep a copy of the most recent text message. diff --git a/src/modules/esp32/AudioModule.cpp b/src/modules/esp32/AudioModule.cpp index e6a975119..4a154878d 100644 --- a/src/modules/esp32/AudioModule.cpp +++ b/src/modules/esp32/AudioModule.cpp @@ -195,8 +195,9 @@ int32_t AudioModule::runOnce() .tx_desc_auto_clear = true, .fixed_mclk = 0}; res = i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL); - if (res != ESP_OK) + if (res != ESP_OK) { LOG_ERROR("Failed to install I2S driver: %d\n", res); + } const i2s_pin_config_t pin_config = { .bck_io_num = moduleConfig.audio.i2s_sck, @@ -204,12 +205,14 @@ int32_t AudioModule::runOnce() .data_out_num = moduleConfig.audio.i2s_din ? moduleConfig.audio.i2s_din : I2S_PIN_NO_CHANGE, .data_in_num = moduleConfig.audio.i2s_sd ? moduleConfig.audio.i2s_sd : I2S_PIN_NO_CHANGE}; res = i2s_set_pin(I2S_PORT, &pin_config); - if (res != ESP_OK) + if (res != ESP_OK) { LOG_ERROR("Failed to set I2S pin config: %d\n", res); + } res = i2s_start(I2S_PORT); - if (res != ESP_OK) + if (res != ESP_OK) { LOG_ERROR("Failed to start I2S: %d\n", res); + } radio_state = RadioState::rx; diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index bd1a85641..490543bf6 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -461,8 +461,9 @@ std::string MQTT::downstreamPacketToJson(meshtastic_MeshPacket *mp) msgPayload["current"] = new JSONValue(decoded->variant.environment_metrics.current); } jsonObj["payload"] = new JSONValue(msgPayload); - } else + } else { LOG_ERROR("Error decoding protobuf for telemetry message!\n"); + } }; break; } @@ -479,8 +480,9 @@ std::string MQTT::downstreamPacketToJson(meshtastic_MeshPacket *mp) msgPayload["shortname"] = new JSONValue(decoded->short_name); msgPayload["hardware"] = new JSONValue(decoded->hw_model); jsonObj["payload"] = new JSONValue(msgPayload); - } else + } else { LOG_ERROR("Error decoding protobuf for nodeinfo message!\n"); + } }; break; } diff --git a/src/sleep.cpp b/src/sleep.cpp index e612b0032..6dcf385b7 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -132,6 +132,7 @@ void initDeepSleep() support busted boards, assume button one was pressed wakeButtons = ((uint64_t)1) << buttons.gpios[0]; */ +#ifdef DEBUG_PORT // If we booted because our timer ran out or the user pressed reset, send those as fake events const char *reason = "reset"; // our best guess RESET_REASON hwReason = rtc_get_reset_reason(0); @@ -150,6 +151,7 @@ void initDeepSleep() LOG_INFO("Booted, wake cause %d (boot count %d), reset_reason=%s\n", wakeCause, bootCount, reason); #endif +#endif } bool doPreflightSleep() @@ -329,23 +331,27 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r gpio_wakeup_enable((gpio_num_t)PMU_IRQ, GPIO_INTR_LOW_LEVEL); // pmu irq #endif auto res = esp_sleep_enable_gpio_wakeup(); - if (res != ESP_OK) + if (res != ESP_OK) { LOG_DEBUG("esp_sleep_enable_gpio_wakeup result %d\n", res); + } assert(res == ESP_OK); res = esp_sleep_enable_timer_wakeup(sleepUsec); - if (res != ESP_OK) + if (res != ESP_OK) { LOG_DEBUG("esp_sleep_enable_timer_wakeup result %d\n", res); + } assert(res == ESP_OK); res = esp_light_sleep_start(); - if (res != ESP_OK) + if (res != ESP_OK) { LOG_DEBUG("esp_light_sleep_start result %d\n", res); + } assert(res == ESP_OK); esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); #ifdef BUTTON_PIN - if (cause == ESP_SLEEP_WAKEUP_GPIO) + if (cause == ESP_SLEEP_WAKEUP_GPIO) { LOG_INFO("Exit light sleep gpio: btn=%d\n", !digitalRead(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN)); + } #endif return cause; From f9b2556cd446e8aac9b28a7e97d6eb444388fc9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Mon, 15 May 2023 15:40:22 +0200 Subject: [PATCH 10/19] add optional GPS fields to JSON --- src/mqtt/MQTT.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 490543bf6..532a2d125 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -505,6 +505,15 @@ std::string MQTT::downstreamPacketToJson(meshtastic_MeshPacket *mp) if ((int)decoded->altitude) { msgPayload["altitude"] = new JSONValue((int)decoded->altitude); } + if ((int)decoded->ground_speed) { + msgPayload["ground_speed"] = new JSONValue((int)decoded->ground_speed); + } + if (int(decoded->ground_track)) { + msgPayload["ground_track"] = new JSONValue((int)decoded->ground_track); + } + if (int(decoded->sats_in_view)) { + msgPayload["sats_in_view"] = new JSONValue((int)decoded->sats_in_view); + } jsonObj["payload"] = new JSONValue(msgPayload); } else { LOG_ERROR("Error decoding protobuf for position message!\n"); From e02720b29bcc01c53915d12aad3413c6d4a2f626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Mon, 15 May 2023 15:47:10 +0200 Subject: [PATCH 11/19] fixes #2490 - hard coded 8 hour limit --- src/modules/esp32/RangeTestModule.cpp | 11 +++++++++-- src/modules/esp32/RangeTestModule.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/modules/esp32/RangeTestModule.cpp b/src/modules/esp32/RangeTestModule.cpp index e8821f9a0..a1d6cb5f2 100644 --- a/src/modules/esp32/RangeTestModule.cpp +++ b/src/modules/esp32/RangeTestModule.cpp @@ -53,7 +53,8 @@ int32_t RangeTestModule::runOnce() if (moduleConfig.range_test.sender) { LOG_INFO("Initializing Range Test Module -- Sender\n"); - return (5000); // Sending first message 5 seconds after initilization. + return (5000); // Sending first message 5 seconds after initilization. + started = millis(); // make a note of when we started } else { LOG_INFO("Initializing Range Test Module -- Receiver\n"); return disable(); @@ -77,7 +78,13 @@ int32_t RangeTestModule::runOnce() rangeTestModuleRadio->sendPayload(); } - return (senderHeartbeat); + // If we have been running for more than 8 hours, turn module back off + if (millis() - started > 28800000) { + LOG_INFO("Range Test Module - Disabling after 8 hours\n"); + return disable(); + } else { + return (senderHeartbeat); + } } else { return disable(); // This thread does not need to run as a receiver diff --git a/src/modules/esp32/RangeTestModule.h b/src/modules/esp32/RangeTestModule.h index 533621d47..ae2a8f182 100644 --- a/src/modules/esp32/RangeTestModule.h +++ b/src/modules/esp32/RangeTestModule.h @@ -9,6 +9,7 @@ class RangeTestModule : private concurrency::OSThread { bool firstTime = 1; + unsigned long started = 0; public: RangeTestModule(); From 77dace10438f0abbb8f10778bb583c5c200241e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Mon, 15 May 2023 16:05:25 +0200 Subject: [PATCH 12/19] derp --- src/modules/esp32/RangeTestModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/esp32/RangeTestModule.cpp b/src/modules/esp32/RangeTestModule.cpp index a1d6cb5f2..b3f03c04b 100644 --- a/src/modules/esp32/RangeTestModule.cpp +++ b/src/modules/esp32/RangeTestModule.cpp @@ -53,8 +53,8 @@ int32_t RangeTestModule::runOnce() if (moduleConfig.range_test.sender) { LOG_INFO("Initializing Range Test Module -- Sender\n"); - return (5000); // Sending first message 5 seconds after initilization. started = millis(); // make a note of when we started + return (5000); // Sending first message 5 seconds after initilization. } else { LOG_INFO("Initializing Range Test Module -- Receiver\n"); return disable(); From 508cdf6060282e214b1489b541764ec90dd36f77 Mon Sep 17 00:00:00 2001 From: IhorNehrutsa <70886343+IhorNehrutsa@users.noreply.github.com> Date: Tue, 16 May 2023 15:01:42 +0300 Subject: [PATCH 13/19] Up OneButton library version to 2.1.0 (#2480) * Up OneButton library version to 2.1.0 * Update ButtonThread.h --------- Co-authored-by: Ben Meadors --- arch/stm32/stm32wl5e.ini | 8 ++++---- platformio.ini | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/stm32/stm32wl5e.ini b/arch/stm32/stm32wl5e.ini index 4d5cee56d..b610bf40b 100644 --- a/arch/stm32/stm32wl5e.ini +++ b/arch/stm32/stm32wl5e.ini @@ -4,11 +4,11 @@ board = generic_wl5e framework = arduino build_type = debug -build_flags = +build_flags = ${arduino_base.build_flags} -Isrc/platform/stm32wl -g -build_src_filter = +build_src_filter = ${arduino_base.build_src_filter} - - - - - - - - - - - - - - lib_deps = @@ -16,5 +16,5 @@ lib_deps = jgromes/RadioLib@^6.0.0 https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b -lib_ignore = - mathertel/OneButton@^2.0.3 +lib_ignore = + https://github.com/mathertel/OneButton#2.1.0 diff --git a/platformio.ini b/platformio.ini index 2040b75ce..f7af9631c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -31,7 +31,7 @@ extra_configs = variants/*/platformio.ini [env] -extra_scripts = bin/platformio-custom.py +extra_scripts = bin/platformio-custom.py ; note: we add src to our include search path so that lmic_project_config can override ; note: TINYGPS_OPTION_NO_CUSTOM_FIELDS is VERY important. We don't use custom fields and somewhere in that pile @@ -39,8 +39,8 @@ extra_scripts = bin/platformio-custom.py ; FIXME: fix lib/BluetoothOTA dependency back on src/ so we can remove -Isrc ; The Radiolib stuff will speed up building considerably. Exclud all the stuff we dont need. build_flags = -Wno-missing-field-initializers - -Wno-format - -Isrc -Isrc/mesh -Isrc/mesh/generated -Isrc/gps -Isrc/buzz -Wl,-Map,.pio/build/output.map + -Wno-format + -Isrc -Isrc/mesh -Isrc/mesh/generated -Isrc/gps -Isrc/buzz -Wl,-Map,.pio/build/output.map -DUSE_THREAD_NAMES -DTINYGPS_OPTION_NO_CUSTOM_FIELDS -DPB_ENABLE_MALLOC=1 @@ -59,8 +59,8 @@ build_flags = -Wno-missing-field-initializers monitor_speed = 115200 lib_deps = - https://github.com/meshtastic/esp8266-oled-ssd1306.git#b38094e03dfa964fbc0e799bc374e91a605c1223 ; ESP8266_SSD1306 - mathertel/OneButton@^2.0.3 ; OneButton library for non-blocking button debounce + https://github.com/meshtastic/esp8266-oled-ssd1306.git#b38094e03dfa964fbc0e799bc374e91a605c1223 ; ESP8266_SSD1306 + https://github.com/mathertel/OneButton#2.1.0 ; OneButton library for non-blocking button debounce https://github.com/meshtastic/arduino-fsm.git#7db3702bf0cfe97b783d6c72595e3f38e0b19159 https://github.com/meshtastic/TinyGPSPlus.git#127ad674ef85f0201cb68a065879653ed94792c4 https://github.com/meshtastic/ArduinoThread.git#72921ac222eed6f526ba1682023cee290d9aa1b3 @@ -87,14 +87,14 @@ lib_deps = build_flags = ${env.build_flags} -Os -DRADIOLIB_SPI_PARANOID=0 build_src_filter = ${env.build_src_filter} - -; Common libs for communicating over TCP/IP networks such as MQTT +; Common libs for communicating over TCP/IP networks such as MQTT [networking_base] lib_deps = knolleary/PubSubClient@^2.8 arduino-libraries/NTPClient@^3.1.0 arcao/Syslog@^2.0.0 -; Common libs for environmental measurements in telemetry module +; Common libs for environmental measurements in telemetry module ; (not included in native / portduino) [environmental_base] lib_deps = From d11bcda2923d40159c6cc09fb99c7cb7339579ff Mon Sep 17 00:00:00 2001 From: code8buster Date: Sat, 13 May 2023 20:38:37 -0400 Subject: [PATCH 14/19] Implementing a calibrated ESP32 ADC reading --- src/Power.cpp | 98 ++++++++++++++++++++++++-------- src/power.h | 9 ++- variants/tlora_v2_1_16/variant.h | 10 +++- 3 files changed, 89 insertions(+), 28 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index b129fbcd0..1eb668f00 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -6,6 +6,7 @@ #include "main.h" #include "sleep.h" #include "utils.h" +static const char *TAG = "ADCmod"; #ifdef DEBUG_HEAP_MQTT #include "mqtt/MQTT.h" @@ -17,6 +18,22 @@ #define DELAY_FOREVER portMAX_DELAY #endif +#ifdef BATTERY_PIN + +#ifndef BAT_MEASURE_ADC_UNIT // ADC1 +static const adc1_channel_t adc_channel = ADC_CHANNEL; +#else // make adc1 default +static const adc2_channel_t adc_channel = ADC_CHANNEL; +RTC_NOINIT_ATTR uint64_t RTC_reg_b; +#include "soc/sens_reg.h" // needed for adc pin reset +#endif + +esp_adc_cal_characteristics_t *adc_characs = (esp_adc_cal_characteristics_t *)calloc(1, sizeof(esp_adc_cal_characteristics_t)); + +static const adc_atten_t atten = ADC_ATTEN_DB_11; +static const adc_unit_t unit = adc_unit_name; +#endif // BATTERY_PIN + #ifdef HAS_PMU #include "XPowersAXP192.tpp" #include "XPowersAXP2101.tpp" @@ -36,7 +53,7 @@ class HasBatteryLevel /** * The raw voltage of the battery or NAN if unknown */ - virtual uint16_t getBattVoltage() { return 0; } + virtual uint32_t getBattVoltage() { return 0; } /** * return true if there is a battery installed in this unit @@ -105,7 +122,7 @@ class AnalogBatteryLevel : public HasBatteryLevel /** * The raw voltage of the batteryin millivolts or NAN if unknown */ - virtual uint16_t getBattVoltage() override + virtual uint32_t getBattVoltage() override { #ifndef ADC_MULTIPLIER @@ -128,18 +145,27 @@ class AnalogBatteryLevel : public HasBatteryLevel // Set the number of samples, it has an effect of increasing sensitivity, especially in complex electromagnetic // environment. uint32_t raw = 0; - for (uint32_t i = 0; i < BATTERY_SENSE_SAMPLES; i++) { - raw += analogRead(BATTERY_PIN); +#ifndef BAT_MEASURE_ADC_UNIT // ADC1 + for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { + raw += adc1_get_raw(adc_channel); } +#else // ADC2 + uint32_t adc_buf = 0; + for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { + // ADC2 wifi bug workaround, see + // https://github.com/espressif/arduino-esp32/issues/102 + WRITE_PERI_REG(SENS_SAR_READ_CTRL2_REG, RTC_reg_b); + SET_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DATA_INV); + adc2_get_raw(adc_channel, ADC_WIDTH_BIT_12, &adc_buf); + raw += adc_buf; + } +#endif // BAT_MEASURE_ADC_UNIT raw = raw / BATTERY_SENSE_SAMPLES; - float scaled; -#ifndef VBAT_RAW_TO_SCALED - scaled = 1000.0 * operativeAdcMultiplier * (AREF_VOLTAGE / 1024.0) * raw; -#else - scaled = VBAT_RAW_TO_SCALED(raw); // defined in variant.h -#endif + scaled = esp_adc_cal_raw_to_voltage(raw, adc_characs); + scaled *= operativeAdcMultiplier; // LOG_DEBUG("battery gpio %d raw val=%u scaled=%u\n", BATTERY_PIN, raw, (uint32_t)(scaled)); + last_read_value = scaled; return scaled; } else { @@ -147,7 +173,7 @@ class AnalogBatteryLevel : public HasBatteryLevel } #else return 0; -#endif +#endif // BATTERY_PIN } /** @@ -222,36 +248,62 @@ bool Power::analogInit() pinMode(EXT_PWR_DETECT, INPUT); #endif +#ifndef HAS_PMU + #ifdef BATTERY_PIN LOG_DEBUG("Using analog input %d for battery level\n", BATTERY_PIN); // disable any internal pullups - pinMode(BATTERY_PIN, INPUT); + pinMode(35, INPUT); +#endif // BATTERY PIN + +#ifndef BATTERY_SENSE_RESOLUTION_BITS +#define BATTERY_SENSE_RESOLUTION_BITS 12 +#endif #ifdef ARCH_ESP32 - // ESP32 needs special analog stuff - adcAttachPin(BATTERY_PIN); +// ESP32 needs special analog stuff +// configure ADC +#ifndef BAT_MEASURE_ADC_UNIT // ADC1 + adc1_config_width(width); + adc1_config_channel_atten(adc_channel, atten); +#else // ADC2 + adc2_config_channel_atten(adc_channel, atten); + // ADC2 wifi bug workaround, see + // https://github.com/espressif/arduino-esp32/issues/102 + RTC_reg_b = READ_PERI_REG(SENS_SAR_READ_CTRL2_REG); #endif + + LOG_DEBUG("ADC using channel %s\n", adc_channel_name); + // calibrate ADC + esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, atten, width, DEFAULT_VREF, adc_characs); + // show ADC characterization base + if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) { + ESP_LOGI(TAG, "ADC characterization based on Two Point values stored in eFuse"); + } else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) { + ESP_LOGI(TAG, "ADC characterization based on reference voltage stored in eFuse"); + } else { + ESP_LOGI(TAG, "ADC characterization based on default reference voltage"); + } +#endif // ARCH_ESP32 + #ifdef ARCH_NRF52 #ifdef VBAT_AR_INTERNAL analogReference(VBAT_AR_INTERNAL); #else analogReference(AR_INTERNAL); // 3.6V #endif -#endif - -#ifndef BATTERY_SENSE_RESOLUTION_BITS -#define BATTERY_SENSE_RESOLUTION_BITS 10 -#endif - - // adcStart(BATTERY_PIN); + adcStart(BATTERY_PIN); analogReadResolution(BATTERY_SENSE_RESOLUTION_BITS); // Default of 12 is not very linear. Recommended to use 10 or 11 // depending on needed resolution. + +#endif // ARCH_NRF52 + batteryLevel = &analogLevel; return true; #else return false; -#endif +#endif // !HAS_PMU } bool Power::setup() @@ -302,7 +354,7 @@ void Power::readPowerStatus() { if (batteryLevel) { bool hasBattery = batteryLevel->isBatteryConnect(); - int batteryVoltageMv = 0; + uint32_t batteryVoltageMv = 0; int8_t batteryChargePercent = 0; if (hasBattery) { batteryVoltageMv = batteryLevel->getBattVoltage(); diff --git a/src/power.h b/src/power.h index 6b787d320..8c3cd92af 100644 --- a/src/power.h +++ b/src/power.h @@ -1,7 +1,8 @@ #pragma once #include "PowerStatus.h" #include "concurrency/OSThread.h" - +#include +#include /** * Per @spattinson * MIN_BAT_MILLIVOLTS seems high. Typical 18650 are different chemistry to LiPo, even for LiPos that chart seems a bit off, other @@ -14,6 +15,10 @@ #define BAT_MILLIVOLTS_FULL 4100 #define BAT_MILLIVOLTS_EMPTY 3500 +#ifdef BAT_MEASURE_ADC_UNIT +extern RTC_NOINIT_ATTR uint64_t RTC_reg_b; +#include "soc/sens_reg.h" // needed for adc pin reset +#endif class Power : private concurrency::OSThread { @@ -45,4 +50,4 @@ class Power : private concurrency::OSThread #endif }; -extern Power *power; +extern Power *power; \ No newline at end of file diff --git a/variants/tlora_v2_1_16/variant.h b/variants/tlora_v2_1_16/variant.h index 11c5921ba..42f3a0d52 100644 --- a/variants/tlora_v2_1_16/variant.h +++ b/variants/tlora_v2_1_16/variant.h @@ -3,9 +3,13 @@ #define GPS_RX_PIN 15 // per @der_bear on the forum, 36 is incorrect for this board type and 15 is a better pick #define GPS_TX_PIN 13 -#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define BATTERY_PIN 35 +#define ADC_CHANNEL ADC_GPIO35_CHANNEL +#define BATTERY_SENSE_SAMPLES 30 +#define DEFAULT_VREF 1100 + // ratio of voltage divider = 2.0 (R42=100k, R43=100k) -#define ADC_MULTIPLIER 2.11 // 2.0 + 10% for correction of display undervoltage. +#define ADC_MULTIPLIER 2 #define I2C_SDA 21 // I2C pins for this board #define I2C_SCL 22 @@ -19,4 +23,4 @@ #define LORA_DIO0 26 // a No connect on the SX1262 module #define LORA_RESET 23 #define LORA_DIO1 33 // https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-3/18436 -#define LORA_DIO2 32 // Not really used +#define LORA_DIO2 32 // Not really used \ No newline at end of file From 6113a1fb702000695a34ce70e319519760952e06 Mon Sep 17 00:00:00 2001 From: code8buster Date: Sun, 14 May 2023 19:49:08 -0400 Subject: [PATCH 15/19] Tryfix heltec v2 adc issues being on SAR2 --- src/Power.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 1eb668f00..d4ea10b23 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -20,18 +20,19 @@ static const char *TAG = "ADCmod"; #ifdef BATTERY_PIN -#ifndef BAT_MEASURE_ADC_UNIT // ADC1 +#ifndef BAT_MEASURE_ADC_UNIT // ADC1 is default static const adc1_channel_t adc_channel = ADC_CHANNEL; -#else // make adc1 default +static const adc_unit_t unit = ADC_UNIT_1; +#else // ADC2 static const adc2_channel_t adc_channel = ADC_CHANNEL; +static const adc_unit_t unit = ADC_UNIT_2; RTC_NOINIT_ATTR uint64_t RTC_reg_b; -#include "soc/sens_reg.h" // needed for adc pin reset + #endif esp_adc_cal_characteristics_t *adc_characs = (esp_adc_cal_characteristics_t *)calloc(1, sizeof(esp_adc_cal_characteristics_t)); static const adc_atten_t atten = ADC_ATTEN_DB_11; -static const adc_unit_t unit = adc_unit_name; #endif // BATTERY_PIN #ifdef HAS_PMU @@ -269,12 +270,9 @@ bool Power::analogInit() adc1_config_channel_atten(adc_channel, atten); #else // ADC2 adc2_config_channel_atten(adc_channel, atten); - // ADC2 wifi bug workaround, see - // https://github.com/espressif/arduino-esp32/issues/102 + // ADC2 wifi bug workaround RTC_reg_b = READ_PERI_REG(SENS_SAR_READ_CTRL2_REG); #endif - - LOG_DEBUG("ADC using channel %s\n", adc_channel_name); // calibrate ADC esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, atten, width, DEFAULT_VREF, adc_characs); // show ADC characterization base From 3219ad33ef9dee4899bbf35d59a6112914da4646 Mon Sep 17 00:00:00 2001 From: code8buster Date: Tue, 16 May 2023 01:40:42 -0400 Subject: [PATCH 16/19] Add ADC channels to esp variants, plug code back in to make sure other archs work --- src/Power.cpp | 56 +++++++++++++++++++---------- src/platform/esp32/architecture.h | 5 ++- src/power.h | 2 ++ variants/diy/dr-dev/variant.h | 4 ++- variants/diy/v1/variant.h | 7 ++-- variants/heltec_v1/variant.h | 2 ++ variants/heltec_v2.1/variant.h | 5 +-- variants/heltec_v2/variant.h | 2 ++ variants/heltec_v3/variant.h | 5 +-- variants/heltec_wsl_v3/variant.h | 3 +- variants/nano-g1-explorer/variant.h | 5 +-- variants/station-g1/variant.h | 5 +-- variants/tbeam_v07/variant.h | 1 + variants/tlora_t3s3_v1/variant.h | 1 + variants/tlora_v1_3/variant.h | 1 + variants/tlora_v2/variant.h | 3 +- variants/tlora_v2_1_16/variant.h | 3 +- variants/tlora_v2_1_18/variant.h | 1 + 18 files changed, 75 insertions(+), 36 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index d4ea10b23..14ef2e951 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -18,7 +18,7 @@ static const char *TAG = "ADCmod"; #define DELAY_FOREVER portMAX_DELAY #endif -#ifdef BATTERY_PIN +#if defined(BATTERY_PIN) && defined(ARCH_ESP32) #ifndef BAT_MEASURE_ADC_UNIT // ADC1 is default static const adc1_channel_t adc_channel = ADC_CHANNEL; @@ -28,12 +28,12 @@ static const adc2_channel_t adc_channel = ADC_CHANNEL; static const adc_unit_t unit = ADC_UNIT_2; RTC_NOINIT_ATTR uint64_t RTC_reg_b; -#endif +#endif // BAT_MEASURE_ADC_UNIT esp_adc_cal_characteristics_t *adc_characs = (esp_adc_cal_characteristics_t *)calloc(1, sizeof(esp_adc_cal_characteristics_t)); static const adc_atten_t atten = ADC_ATTEN_DB_11; -#endif // BATTERY_PIN +#endif // BATTERY_PIN && ARCH_ESP32 #ifdef HAS_PMU #include "XPowersAXP192.tpp" @@ -146,12 +146,13 @@ class AnalogBatteryLevel : public HasBatteryLevel // Set the number of samples, it has an effect of increasing sensitivity, especially in complex electromagnetic // environment. uint32_t raw = 0; +#ifdef ARCH_ESP32 #ifndef BAT_MEASURE_ADC_UNIT // ADC1 for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { raw += adc1_get_raw(adc_channel); } #else // ADC2 - uint32_t adc_buf = 0; + int32_t adc_buf = 0; for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { // ADC2 wifi bug workaround, see // https://github.com/espressif/arduino-esp32/issues/102 @@ -161,11 +162,24 @@ class AnalogBatteryLevel : public HasBatteryLevel raw += adc_buf; } #endif // BAT_MEASURE_ADC_UNIT +#else // !ARCH_ESP32 + for (uint32_t i = 0; i < BATTERY_SENSE_SAMPLES; i++) { + raw += analogRead(BATTERY_PIN); + } +#endif raw = raw / BATTERY_SENSE_SAMPLES; float scaled; +#ifdef ARCH_ESP32 scaled = esp_adc_cal_raw_to_voltage(raw, adc_characs); scaled *= operativeAdcMultiplier; - // LOG_DEBUG("battery gpio %d raw val=%u scaled=%u\n", BATTERY_PIN, raw, (uint32_t)(scaled)); +#else +#ifndef VBAT_RAW_TO_SCALED + scaled = 1000.0 * operativeAdcMultiplier * (AREF_VOLTAGE / 1024.0) * raw; +#else + scaled = VBAT_RAW_TO_SCALED(raw); // defined in variant.h +#endif // VBAT RAW TO SCALED +#endif // ARCH_ESP32 + // LOG_DEBUG("battery gpio %d raw val=%u scaled=%u\n", BATTERY_PIN, raw, (uint32_t)(scaled)); last_read_value = scaled; return scaled; @@ -255,16 +269,19 @@ bool Power::analogInit() LOG_DEBUG("Using analog input %d for battery level\n", BATTERY_PIN); // disable any internal pullups - pinMode(35, INPUT); -#endif // BATTERY PIN + pinMode(BATTERY_PIN, INPUT); #ifndef BATTERY_SENSE_RESOLUTION_BITS -#define BATTERY_SENSE_RESOLUTION_BITS 12 +#define BATTERY_SENSE_RESOLUTION_BITS 10 #endif -#ifdef ARCH_ESP32 -// ESP32 needs special analog stuff -// configure ADC +#ifdef ARCH_ESP32 // ESP32 needs special analog stuff + +#ifndef ADC_WIDTH // max resolution by default + static const adc_bits_width_t width = ADC_WIDTH_BIT_12; +#else + static const adc_bits_width_t width = ADC_WIDTH; +#endif #ifndef BAT_MEASURE_ADC_UNIT // ADC1 adc1_config_width(width); adc1_config_channel_atten(adc_channel, atten); @@ -291,7 +308,6 @@ bool Power::analogInit() #else analogReference(AR_INTERNAL); // 3.6V #endif - adcStart(BATTERY_PIN); analogReadResolution(BATTERY_SENSE_RESOLUTION_BITS); // Default of 12 is not very linear. Recommended to use 10 or 11 // depending on needed resolution. @@ -301,6 +317,7 @@ bool Power::analogInit() return true; #else return false; +#endif // BATTERY_PIN #endif // !HAS_PMU } @@ -415,8 +432,8 @@ void Power::readPowerStatus() #endif - // If we have a battery at all and it is less than 10% full, force deep sleep if we have more than 10 low readings in a - // row + // If we have a battery at all and it is less than 10% full, force deep sleep if we have more than 10 low readings in + // a row if (powerStatus2.getHasBattery() && !powerStatus2.getHasUSB()) { if (batteryLevel->getBattVoltage() < MIN_BAT_MILLIVOLTS) { low_voltage_counter++; @@ -494,10 +511,10 @@ int32_t Power::runOnce() * Init the power manager chip * * axp192 power - DCDC1 0.7-3.5V @ 1200mA max -> OLED // If you turn this off you'll lose comms to the axp192 because the OLED and the axp192 - share the same i2c bus, instead use ssd1306 sleep mode DCDC2 -> unused DCDC3 0.7-3.5V @ 700mA max -> ESP32 (keep this on!) LDO1 - 30mA -> charges GPS backup battery // charges the tiny J13 battery by the GPS to power the GPS ram (for a couple of days), can - not be turned off LDO2 200mA -> LORA LDO3 200mA -> GPS + DCDC1 0.7-3.5V @ 1200mA max -> OLED // If you turn this off you'll lose comms to the axp192 because the OLED and the + axp192 share the same i2c bus, instead use ssd1306 sleep mode DCDC2 -> unused DCDC3 0.7-3.5V @ 700mA max -> ESP32 (keep this + on!) LDO1 30mA -> charges GPS backup battery // charges the tiny J13 battery by the GPS to power the GPS ram (for a couple of + days), can not be turned off LDO2 200mA -> LORA LDO3 200mA -> GPS * */ bool Power::axpChipInit() @@ -624,7 +641,8 @@ bool Power::axpChipInit() // t-beam s3 core /** * gnss module power channel - * The default ALDO4 is off, you need to turn on the GNSS power first, otherwise it will be invalid during initialization + * The default ALDO4 is off, you need to turn on the GNSS power first, otherwise it will be invalid during + * initialization */ PMU->setPowerChannelVoltage(XPOWERS_ALDO4, 3300); PMU->enablePowerOutput(XPOWERS_ALDO4); diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index da2d9d905..7a1e9ba49 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -39,6 +39,9 @@ #ifndef HAS_CPU_SHUTDOWN #define HAS_CPU_SHUTDOWN 1 #endif +#ifndef DEFAULT_VREF +#define DEFAULT_VREF 1100 +#endif #if defined(HAS_AXP192) || defined(HAS_AXP2101) #define HAS_PMU @@ -132,4 +135,4 @@ #define RF95_NSS 18 #endif -#define SERIAL0_RX_GPIO 3 // Always GPIO3 on ESP32 +#define SERIAL0_RX_GPIO 3 // Always GPIO3 on ESP32 \ No newline at end of file diff --git a/src/power.h b/src/power.h index 8c3cd92af..c47e78466 100644 --- a/src/power.h +++ b/src/power.h @@ -1,8 +1,10 @@ #pragma once #include "PowerStatus.h" #include "concurrency/OSThread.h" +#ifdef ARCH_ESP32 #include #include +#endif /** * Per @spattinson * MIN_BAT_MILLIVOLTS seems high. Typical 18650 are different chemistry to LiPo, even for LiPos that chart seems a bit off, other diff --git a/variants/diy/dr-dev/variant.h b/variants/diy/dr-dev/variant.h index 122a617b6..113fe5e3f 100644 --- a/variants/diy/dr-dev/variant.h +++ b/variants/diy/dr-dev/variant.h @@ -2,6 +2,8 @@ #define HAS_SCREEN 0 #define I2C_SDA 4 #define I2C_SCL 5 +#define BATTERY_PIN 34 +#define ADC1_GPIO34_CHANNEL // GPS #undef GPS_RX_PIN @@ -67,4 +69,4 @@ #define USE_SX1262 //#define USE_SX1268 //#define USE_LLCC68 -#define SX126X_E22 +#define SX126X_E22 \ No newline at end of file diff --git a/variants/diy/v1/variant.h b/variants/diy/v1/variant.h index c47437643..a1083f9bb 100644 --- a/variants/diy/v1/variant.h +++ b/variants/diy/v1/variant.h @@ -9,8 +9,9 @@ #define GPS_TX_PIN 15 #define GPS_UBLOX -#define BUTTON_PIN 39 // The middle button GPIO on the T-Beam -#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define BUTTON_PIN 39 // The middle button GPIO on the T-Beam +#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define ADC_CHANNEL ADC1_GPIO35_CHANNEL #define ADC_MULTIPLIER 1.85 // (R1 = 470k, R2 = 680k) #define EXT_PWR_DETECT 4 // Pin to detect connected external power source for LILYGO® TTGO T-Energy T18 and other DIY boards #define EXT_NOTIFY_OUT 12 // Overridden default pin to use for Ext Notify Module (#975). @@ -52,4 +53,4 @@ // Internally the TTGO module hooks the SX126x-DIO2 in to control the TX/RX switch // (which is the default for the sx1262interface code) #define SX126X_E22 -#endif +#endif \ No newline at end of file diff --git a/variants/heltec_v1/variant.h b/variants/heltec_v1/variant.h index 948f6ff1e..d1338a28e 100644 --- a/variants/heltec_v1/variant.h +++ b/variants/heltec_v1/variant.h @@ -27,3 +27,5 @@ #define ADC_MULTIPLIER 3.2 #define BATTERY_PIN 13 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define ADC_CHANNEL ADC2_GPIO13_CHANNEL +#define BAT_MEASURE_ADC_UNIT 2 \ No newline at end of file diff --git a/variants/heltec_v2.1/variant.h b/variants/heltec_v2.1/variant.h index 39a0e677f..e7cfd5b34 100644 --- a/variants/heltec_v2.1/variant.h +++ b/variants/heltec_v2.1/variant.h @@ -29,5 +29,6 @@ #define ADC_MULTIPLIER 3.8 -#define BATTERY_PIN 37 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage -#define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. +#define BATTERY_PIN 37 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define ADC_CHANNEL ADC1_GPIO37_CHANNEL +#define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. \ No newline at end of file diff --git a/variants/heltec_v2/variant.h b/variants/heltec_v2/variant.h index 59e0c76e6..5c183818b 100644 --- a/variants/heltec_v2/variant.h +++ b/variants/heltec_v2/variant.h @@ -27,3 +27,5 @@ // ratio of voltage divider = 3.20 (R12=100k, R10=220k) #define ADC_MULTIPLIER 3.2 #define BATTERY_PIN 13 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define ADC_CHANNEL ADC2_GPIO13_CHANNEL +#define BAT_MEASURE_ADC_UNIT 2 \ No newline at end of file diff --git a/variants/heltec_v3/variant.h b/variants/heltec_v3/variant.h index a2e8bde8e..16ee6d712 100644 --- a/variants/heltec_v3/variant.h +++ b/variants/heltec_v3/variant.h @@ -8,7 +8,8 @@ #define BUTTON_PIN 0 #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage -#define ADC_MULTIPLIER 5.22 +#define ADC_CHANNEL ADC1_GPIO1_CHANNEL +#define ADC_MULTIPLIER 4.9 #define USE_SX1262 @@ -27,4 +28,4 @@ #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET -#define SX126X_E22 +#define SX126X_E22 \ No newline at end of file diff --git a/variants/heltec_wsl_v3/variant.h b/variants/heltec_wsl_v3/variant.h index 66415741b..38b38e759 100644 --- a/variants/heltec_wsl_v3/variant.h +++ b/variants/heltec_wsl_v3/variant.h @@ -9,7 +9,8 @@ #define BUTTON_PIN 0 #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage -#define ADC_MULTIPLIER 5.22 +#define ADC_CHANNEL ADC1_GPIO1_CHANNEL +#define ADC_MULTIPLIER 4.9 #define USE_SX1262 diff --git a/variants/nano-g1-explorer/variant.h b/variants/nano-g1-explorer/variant.h index ad8957a51..fb3fc72d1 100644 --- a/variants/nano-g1-explorer/variant.h +++ b/variants/nano-g1-explorer/variant.h @@ -29,8 +29,9 @@ // code) #endif -#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define ADC_CHANNEL ADC1_GPIO35_CHANNEL #define BATTERY_SENSE_SAMPLES 15 // Set the number of samples, It has an effect of increasing sensitivity. #define ADC_MULTIPLIER 2 -#define USE_SH1107_128_64 +#define USE_SH1107_128_64 \ No newline at end of file diff --git a/variants/station-g1/variant.h b/variants/station-g1/variant.h index 4572d47a6..3439cb125 100644 --- a/variants/station-g1/variant.h +++ b/variants/station-g1/variant.h @@ -32,7 +32,8 @@ // Info:https://uniteng.com/wiki/doku.php?id=meshtastic:station#rf_design_-_lora_station_edition_g1 #endif -#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define ADC_CHANNEL ADC1_GPIO35_CHANNEL #define BATTERY_SENSE_SAMPLES 30 // Set the number of samples, It has an effect of increasing sensitivity. #define ADC_MULTIPLIER 6.45 #define BAT_FULLVOLT 12600 @@ -41,4 +42,4 @@ #define BAT_NOBATVOLT 6690 // different screen -#define USE_SH1106 +#define USE_SH1106 \ No newline at end of file diff --git a/variants/tbeam_v07/variant.h b/variants/tbeam_v07/variant.h index 2c8008688..898705ce2 100644 --- a/variants/tbeam_v07/variant.h +++ b/variants/tbeam_v07/variant.h @@ -6,6 +6,7 @@ #define BUTTON_PIN 39 #define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. +#define ADC_CHANNEL ADC1_GPIO35_CHANNEL #define USE_RF95 #define LORA_DIO0 26 // a No connect on the SX1262 module diff --git a/variants/tlora_t3s3_v1/variant.h b/variants/tlora_t3s3_v1/variant.h index 768a7c2da..313b08e6d 100644 --- a/variants/tlora_t3s3_v1/variant.h +++ b/variants/tlora_t3s3_v1/variant.h @@ -9,6 +9,7 @@ #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage // ratio of voltage divider = 2.0 (R42=100k, R43=100k) #define ADC_MULTIPLIER 2.11 // 2.0 + 10% for correction of display undervoltage. +#define ADC_CHANNEL ADC1_GPIO1_CHANNEL #define I2C_SDA 18 // I2C pins for this board #define I2C_SCL 17 diff --git a/variants/tlora_v1_3/variant.h b/variants/tlora_v1_3/variant.h index 7e8aec0c4..50041f296 100644 --- a/variants/tlora_v1_3/variant.h +++ b/variants/tlora_v1_3/variant.h @@ -4,6 +4,7 @@ #define GPS_TX_PIN 13 // per @eugene #define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define ADC_CHANNEL ADC1_GPIO35_CHANNEL #define I2C_SDA 21 // I2C pins for this board #define I2C_SCL 22 diff --git a/variants/tlora_v2/variant.h b/variants/tlora_v2/variant.h index f18503139..b9b521771 100644 --- a/variants/tlora_v2/variant.h +++ b/variants/tlora_v2/variant.h @@ -4,6 +4,7 @@ #define GPS_TX_PIN 13 // per @eugene #define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define ADC_CHANNEL ADC1_GPIO35_CHANNEL #define I2C_SDA 21 // I2C pins for this board #define I2C_SCL 22 @@ -19,4 +20,4 @@ #define LORA_DIO0 26 // a No connect on the SX1262 module #define LORA_RESET 14 #define LORA_DIO1 33 // Must be manually wired: https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-3/18436 -#define LORA_DIO2 32 // Not really used +#define LORA_DIO2 32 // Not really used \ No newline at end of file diff --git a/variants/tlora_v2_1_16/variant.h b/variants/tlora_v2_1_16/variant.h index 42f3a0d52..adb5af898 100644 --- a/variants/tlora_v2_1_16/variant.h +++ b/variants/tlora_v2_1_16/variant.h @@ -4,9 +4,8 @@ #define GPS_TX_PIN 13 #define BATTERY_PIN 35 -#define ADC_CHANNEL ADC_GPIO35_CHANNEL +#define ADC_CHANNEL ADC1_GPIO35_CHANNEL #define BATTERY_SENSE_SAMPLES 30 -#define DEFAULT_VREF 1100 // ratio of voltage divider = 2.0 (R42=100k, R43=100k) #define ADC_MULTIPLIER 2 diff --git a/variants/tlora_v2_1_18/variant.h b/variants/tlora_v2_1_18/variant.h index 0262f0122..e8f0a9659 100644 --- a/variants/tlora_v2_1_18/variant.h +++ b/variants/tlora_v2_1_18/variant.h @@ -4,6 +4,7 @@ #define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage // ratio of voltage divider = 2.0 (R42=100k, R43=100k) #define ADC_MULTIPLIER 2.11 // 2.0 + 10% for correction of display undervoltage. +#define ADC_CHANNEL ADC1_GPIO35_CHANNEL #define I2C_SDA 21 // I2C pins for this board #define I2C_SCL 22 From 9878ff38364938c6e14ce1c283c52e80ae54bf74 Mon Sep 17 00:00:00 2001 From: code8buster Date: Tue, 16 May 2023 02:43:00 -0400 Subject: [PATCH 17/19] Tryfix datatype errors --- src/Power.cpp | 4 ++-- variants/diy/dr-dev/variant.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 14ef2e951..29c14ee73 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -54,7 +54,7 @@ class HasBatteryLevel /** * The raw voltage of the battery or NAN if unknown */ - virtual uint32_t getBattVoltage() { return 0; } + virtual uint16_t getBattVoltage() { return 0; } /** * return true if there is a battery installed in this unit @@ -123,7 +123,7 @@ class AnalogBatteryLevel : public HasBatteryLevel /** * The raw voltage of the batteryin millivolts or NAN if unknown */ - virtual uint32_t getBattVoltage() override + virtual uint16_t getBattVoltage() override { #ifndef ADC_MULTIPLIER diff --git a/variants/diy/dr-dev/variant.h b/variants/diy/dr-dev/variant.h index 113fe5e3f..b9c82a9c8 100644 --- a/variants/diy/dr-dev/variant.h +++ b/variants/diy/dr-dev/variant.h @@ -3,7 +3,7 @@ #define I2C_SDA 4 #define I2C_SCL 5 #define BATTERY_PIN 34 -#define ADC1_GPIO34_CHANNEL +#define ADC_CHANNEL ADC1_GPIO34_CHANNEL // GPS #undef GPS_RX_PIN From c0979e29ff539ca0ea7a8035a43dc88bdf34e5a3 Mon Sep 17 00:00:00 2001 From: code8buster Date: Tue, 16 May 2023 12:47:30 -0400 Subject: [PATCH 18/19] Fix a few platformio envs, maybe make cppcheck happy --- platformio.ini | 10 +++++----- src/Power.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/platformio.ini b/platformio.ini index f7af9631c..498a05b97 100644 --- a/platformio.ini +++ b/platformio.ini @@ -7,12 +7,12 @@ default_envs = tbeam ;default_envs = tbeam-s3-core ;default_envs = tbeam0.7 ;default_envs = heltec-v1 -;default_envs = heltec-v2.0 -;default_envs = heltec-v2.1 +;default_envs = heltec-v2_0 +;default_envs = heltec-v2_1 ;default_envs = tlora-v1 ;default_envs = tlora_v1_3 ;default_envs = tlora-v2 -;default_envs = tlora-v2-1-1.6 +;default_envs = tlora-v2-1-1_6 ;default_envs = tlora-t3s3-v1 ;default_envs = lora-relay-v1 # nrf board ;default_envs = t-echo @@ -21,7 +21,7 @@ default_envs = tbeam ;default_envs = nano-g1 ;default_envs = pca10059_diy_eink ;default_envs = meshtastic-diy-v1 -;default_envs = meshtastic-diy-v1.1 +;default_envs = meshtastic-diy-v1_1 ;default_envs = meshtastic-dr-dev ;default_envs = m5stack-coreink ;default_envs = rak4631 @@ -112,4 +112,4 @@ lib_deps = adafruit/Adafruit SHT31 Library@^2.2.0 adafruit/Adafruit PM25 AQI Sensor@^1.0.6 adafruit/Adafruit MPU6050@^2.2.4 - adafruit/Adafruit LIS3DH@^1.2.4 + adafruit/Adafruit LIS3DH@^1.2.4 \ No newline at end of file diff --git a/src/Power.cpp b/src/Power.cpp index 29c14ee73..4937e04f7 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -315,9 +315,9 @@ bool Power::analogInit() batteryLevel = &analogLevel; return true; +#endif // BATTERY_PIN #else return false; -#endif // BATTERY_PIN #endif // !HAS_PMU } From a9fed83d9ab106419d673951f40436434885328c Mon Sep 17 00:00:00 2001 From: code8buster Date: Tue, 16 May 2023 13:05:45 -0400 Subject: [PATCH 19/19] Make pull request targets happy --- src/Power.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 4937e04f7..c3a34d620 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -263,8 +263,6 @@ bool Power::analogInit() pinMode(EXT_PWR_DETECT, INPUT); #endif -#ifndef HAS_PMU - #ifdef BATTERY_PIN LOG_DEBUG("Using analog input %d for battery level\n", BATTERY_PIN); @@ -315,10 +313,9 @@ bool Power::analogInit() batteryLevel = &analogLevel; return true; -#endif // BATTERY_PIN #else return false; -#endif // !HAS_PMU +#endif } bool Power::setup()