From 9650adb6162475d046f47daaf506b937a84852be Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 24 Feb 2023 11:25:50 -0600 Subject: [PATCH 01/14] Set reasonable defaults for sensor role and adjust packet priority (#2305) --- protobufs | 2 +- src/mesh/NodeDB.cpp | 3 +++ src/mesh/generated/meshtastic/config.pb.h | 9 ++++++--- src/modules/Telemetry/AirQualityTelemetry.cpp | 5 ++++- src/modules/Telemetry/EnvironmentTelemetry.cpp | 6 ++++-- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/protobufs b/protobufs index 275ddfd2d..9825eadc8 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 275ddfd2d017c5a806f2de2975892d197e404c27 +Subproject commit 9825eadc84d3af5ffe8b3432b7b2072f03e3de23 diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index ebf214316..aef156fed 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -239,6 +239,9 @@ void NodeDB::installRoleDefaults(meshtastic_Config_DeviceConfig_Role role) config.position.position_broadcast_smart_enabled = false; config.position.position_broadcast_secs = 120; config.position.gps_update_interval = 60; + } else if (role == meshtastic_Config_DeviceConfig_Role_SENSOR) { + moduleConfig.telemetry.environment_measurement_enabled = true; + moduleConfig.telemetry.environment_update_interval = 450; } } diff --git a/src/mesh/generated/meshtastic/config.pb.h b/src/mesh/generated/meshtastic/config.pb.h index 0ffb4ccec..fcb129bef 100644 --- a/src/mesh/generated/meshtastic/config.pb.h +++ b/src/mesh/generated/meshtastic/config.pb.h @@ -31,7 +31,10 @@ typedef enum _meshtastic_Config_DeviceConfig_Role { meshtastic_Config_DeviceConfig_Role_REPEATER = 4, /* Tracker device role Position Mesh packets will be prioritized higher and sent more frequently by default. */ - meshtastic_Config_DeviceConfig_Role_TRACKER = 5 + meshtastic_Config_DeviceConfig_Role_TRACKER = 5, + /* Sensor device role + Telemetry Mesh packets will be prioritized higher and sent more frequently by default. */ + meshtastic_Config_DeviceConfig_Role_SENSOR = 6 } meshtastic_Config_DeviceConfig_Role; /* Defines the device's behavior for how messages are rebroadcast */ @@ -453,8 +456,8 @@ extern "C" { /* Helper constants for enums */ #define _meshtastic_Config_DeviceConfig_Role_MIN meshtastic_Config_DeviceConfig_Role_CLIENT -#define _meshtastic_Config_DeviceConfig_Role_MAX meshtastic_Config_DeviceConfig_Role_TRACKER -#define _meshtastic_Config_DeviceConfig_Role_ARRAYSIZE ((meshtastic_Config_DeviceConfig_Role)(meshtastic_Config_DeviceConfig_Role_TRACKER+1)) +#define _meshtastic_Config_DeviceConfig_Role_MAX meshtastic_Config_DeviceConfig_Role_SENSOR +#define _meshtastic_Config_DeviceConfig_Role_ARRAYSIZE ((meshtastic_Config_DeviceConfig_Role)(meshtastic_Config_DeviceConfig_Role_SENSOR+1)) #define _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN meshtastic_Config_DeviceConfig_RebroadcastMode_ALL #define _meshtastic_Config_DeviceConfig_RebroadcastMode_MAX meshtastic_Config_DeviceConfig_RebroadcastMode_LOCAL_ONLY diff --git a/src/modules/Telemetry/AirQualityTelemetry.cpp b/src/modules/Telemetry/AirQualityTelemetry.cpp index c300e1f96..de74c0bf9 100644 --- a/src/modules/Telemetry/AirQualityTelemetry.cpp +++ b/src/modules/Telemetry/AirQualityTelemetry.cpp @@ -108,7 +108,10 @@ bool AirQualityTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) meshtastic_MeshPacket *p = allocDataProtobuf(m); p->to = dest; p->decoded.want_response = false; - p->priority = meshtastic_MeshPacket_Priority_MIN; + if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR) + p->priority = meshtastic_MeshPacket_Priority_RELIABLE; + else + p->priority = meshtastic_MeshPacket_Priority_MIN; // release previous packet before occupying a new spot if (lastMeasurementPacket != nullptr) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index bd7ed539a..3b8a7dda1 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -244,8 +244,10 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) meshtastic_MeshPacket *p = allocDataProtobuf(m); p->to = dest; p->decoded.want_response = false; - p->priority = meshtastic_MeshPacket_Priority_MIN; - + if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR) + p->priority = meshtastic_MeshPacket_Priority_RELIABLE; + else + p->priority = meshtastic_MeshPacket_Priority_MIN; // release previous packet before occupying a new spot if (lastMeasurementPacket != nullptr) packetPool.release(lastMeasurementPacket); From fbfd0f12b5b0ef1086966b9bbaba08d538f164d9 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 24 Feb 2023 12:49:10 -0600 Subject: [PATCH 02/14] Change to 5 minutes for Garth's sanity --- src/mesh/NodeDB.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index aef156fed..0748f50aa 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -241,7 +241,7 @@ void NodeDB::installRoleDefaults(meshtastic_Config_DeviceConfig_Role role) config.position.gps_update_interval = 60; } else if (role == meshtastic_Config_DeviceConfig_Role_SENSOR) { moduleConfig.telemetry.environment_measurement_enabled = true; - moduleConfig.telemetry.environment_update_interval = 450; + moduleConfig.telemetry.environment_update_interval = 300; } } From c9ae90f03cd90b09a917e72a3aa8090ee556bbd3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 24 Feb 2023 15:07:39 -0600 Subject: [PATCH 03/14] [create-pull-request] automated change (#2306) Co-authored-by: thebentern --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index d0805fbbf..202cb0780 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 0 -build = 22 +build = 23 From 408c555f0f4c30f2ad6668ced6342554e9e98dc6 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Sun, 26 Feb 2023 02:51:38 +0100 Subject: [PATCH 04/14] Add airtime of current received/transmitted packet to nextTx time of all pending retransmissions (#2309) To avoid unnecessary retransmissions when sending them too early Co-authored-by: Ben Meadors --- src/mesh/RadioInterface.cpp | 2 +- src/mesh/RadioInterface.h | 2 +- src/mesh/ReliableRouter.cpp | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 94dab0bcd..118aab5a6 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -175,7 +175,7 @@ uint32_t RadioInterface::getPacketTime(uint32_t pl) return msecs; } -uint32_t RadioInterface::getPacketTime(meshtastic_MeshPacket *p) +uint32_t RadioInterface::getPacketTime(const meshtastic_MeshPacket *p) { uint32_t pl = 0; if (p->which_payload_variant == meshtastic_MeshPacket_encrypted_tag) { diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index b9511fd5d..68dbf3522 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -154,7 +154,7 @@ class RadioInterface * * @return num msecs for the packet */ - uint32_t getPacketTime(meshtastic_MeshPacket *p); + uint32_t getPacketTime(const meshtastic_MeshPacket *p); uint32_t getPacketTime(uint32_t totalPacketLen); /** diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index 3d07ff77e..774be9c17 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -24,6 +24,15 @@ ErrorCode ReliableRouter::send(meshtastic_MeshPacket *p) startRetransmission(copy); } + /* If we have pending retransmissions, add the airtime of this packet to it, because during that time we cannot receive an + (implicit) ACK. Otherwise, we might retransmit too early. + */ + for (auto i = pending.begin(); i != pending.end(); i++) { + if (i->first.id != p->id) { + i->second.nextTxMsec += iface->getPacketTime(p); + } + } + return FloodingRouter::send(p); } @@ -53,6 +62,15 @@ bool ReliableRouter::shouldFilterReceived(const meshtastic_MeshPacket *p) } } + /* At this point we have already deleted the pending retransmission if this packet was an (implicit) ACK to it. + Now for all other pending retransmissions, we have to add the airtime of this received packet to the retransmission timer, + because while receiving this packet, we could not have received an (implicit) ACK for it. + If we don't add this, we will likely retransmit too early. + */ + for (auto i = pending.begin(); i != pending.end(); i++) { + i->second.nextTxMsec += iface->getPacketTime(p); + } + /* Resend implicit ACKs for repeated packets (assuming the original packet was sent with HOP_RELIABLE) * this way if an implicit ACK is dropped and a packet is resent we'll rebroadcast again. * Resending real ACKs is omitted, as you might receive a packet multiple times due to flooding and From 9008c755176b9e11da22816ca0e5fa2dac2a0d9c Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Tue, 28 Feb 2023 14:45:10 +0100 Subject: [PATCH 05/14] Fixed: Tlora-t3s3-v1 SX1262 firmware reboots continuously (#2308) (#2315) --- boards/tlora-t3s3-v1.json | 2 +- platformio.ini | 1 + src/main.cpp | 26 +++++++++++++------------- variants/tlora_t3s3_v1/platformio.ini | 1 + variants/tlora_t3s3_v1/variant.h | 9 +++++---- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/boards/tlora-t3s3-v1.json b/boards/tlora-t3s3-v1.json index 5af53084f..d073fc7c1 100644 --- a/boards/tlora-t3s3-v1.json +++ b/boards/tlora-t3s3-v1.json @@ -14,7 +14,7 @@ "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "dio", - "hwids": [["0X303A", "0x1001"]], + "hwids": [["0x303A", "0x1001"]], "mcu": "esp32s3", "variant": "tlora-t3s3-v1" }, diff --git a/platformio.ini b/platformio.ini index 4f8f53d0c..af18a6f8b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,6 +13,7 @@ default_envs = tbeam ;default_envs = tlora_v1_3 ;default_envs = tlora-v2 ;default_envs = tlora-v2-1-1.6 +;default_envs = tlora-t3s3-v1 ;default_envs = lora-relay-v1 # nrf board ;default_envs = t-echo ;default_envs = nrf52840dk-geeksville diff --git a/src/main.cpp b/src/main.cpp index e2e39ebd2..c1afb5c18 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -420,19 +420,6 @@ void setup() } #endif -#if defined(USE_SX1280) - if (!rIf) { - rIf = new SX1280Interface(SX128X_CS, SX128X_DIO1, SX128X_RESET, SX128X_BUSY, SPI); - if (!rIf->init()) { - LOG_WARN("Failed to find SX1280 radio\n"); - delete rIf; - rIf = NULL; - } else { - LOG_INFO("SX1280 Radio init succeeded, using SX1280 radio\n"); - } - } -#endif - #if defined(USE_SX1262) if (!rIf) { rIf = new SX1262Interface(SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY, SPI); @@ -472,6 +459,19 @@ void setup() } #endif +#if defined(USE_SX1280) + if (!rIf) { + rIf = new SX1280Interface(SX128X_CS, SX128X_DIO1, SX128X_RESET, SX128X_BUSY, SPI); + if (!rIf->init()) { + LOG_WARN("Failed to find SX1280 radio\n"); + delete rIf; + rIf = NULL; + } else { + LOG_INFO("SX1280 Radio init succeeded, using SX1280 radio\n"); + } + } +#endif + // check if the radio chip matches the selected region if ((config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_LORA_24) && (!rIf->wideLora())) { diff --git a/variants/tlora_t3s3_v1/platformio.ini b/variants/tlora_t3s3_v1/platformio.ini index aa8189199..568e8af42 100644 --- a/variants/tlora_t3s3_v1/platformio.ini +++ b/variants/tlora_t3s3_v1/platformio.ini @@ -1,6 +1,7 @@ [env:tlora-t3s3-v1] extends = esp32s3_base board = tlora-t3s3-v1 +upload_protocol = esp-builtin lib_deps = ${esp32_base.lib_deps} caveman99/ESP32 Codec2@^1.0.1 diff --git a/variants/tlora_t3s3_v1/variant.h b/variants/tlora_t3s3_v1/variant.h index 116911ae0..68eb18e31 100644 --- a/variants/tlora_t3s3_v1/variant.h +++ b/variants/tlora_t3s3_v1/variant.h @@ -37,11 +37,12 @@ #ifdef USE_SX1262 #define SX126X_CS RF95_NSS // FIXME - we really should define LORA_CS instead -#define SX126X_DIO1 LORA_DIO1 -#define SX126X_BUSY 36 +#define SX126X_DIO1 33 +#define SX126X_BUSY 34 #define SX126X_RESET LORA_RESET -#define SX126X_RXEN 21 -#define SX126X_TXEN 10 +//#define SX126X_RXEN 21 +//#define SX126X_TXEN 10 +#define SX126X_E22 #endif #ifdef USE_SX1280 From 2fe5eae183dabb83c3a9aa3e18d57e61d13e2ec3 Mon Sep 17 00:00:00 2001 From: code8buster Date: Wed, 1 Mar 2023 14:34:07 +0000 Subject: [PATCH 06/14] Fix overlapping of GPS message on screen carousel #1 (#2314) * Fix overlapping of GPS message on screen carousel #1 * Any reason we shouldn't display this on a RAK w/ E-ink or similar non-PMU equipped boards? --------- Co-authored-by: Ben Meadors --- src/graphics/Screen.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index c935c354f..12d08cd17 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -518,18 +518,12 @@ static void drawGPS(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus // Draw status when gps is disabled by PMU static void drawGPSpowerstat(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus *gps) { -#ifdef HAS_PMU String displayLine = "GPS disabled"; int16_t xPos = display->getStringWidth(displayLine); if (!config.position.gps_enabled) { display->drawString(x + xPos, y, displayLine); -#ifdef GPS_POWER_TOGGLE - display->drawString(x + xPos, y - 2 + FONT_HEIGHT_SMALL, " by button"); -#endif - // display->drawString(x + xPos, y + 2, displayLine); } -#endif } static void drawGPSAltitude(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus *gps) @@ -1440,11 +1434,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 } // Display GPS status if (!config.position.gps_enabled) { - int16_t yPos = y + 2; -#ifdef GPS_POWER_TOGGLE - yPos = (y + 10 + FONT_HEIGHT_SMALL); -#endif - drawGPSpowerstat(display, x, yPos, gpsStatus); + drawGPSpowerstat(display, x, y + 2, gpsStatus); } else { if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_DEFAULT) { drawGPS(display, x + (SCREEN_WIDTH * 0.63), y + 2, gpsStatus); @@ -1761,6 +1751,9 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat drawGPScoordinates(display, x, y + FONT_HEIGHT_SMALL * 3, gpsStatus); } else { drawGPSpowerstat(display, x - (SCREEN_WIDTH / 4), y + FONT_HEIGHT_SMALL * 2, gpsStatus); +#ifdef GPS_POWER_TOGGLE + display->drawString(x + 30, (y + FONT_HEIGHT_SMALL * 3), " by button"); +#endif } /* Display a heartbeat pixel that blinks every time the frame is redrawn */ #ifdef SHOW_REDRAWS From d17aafa91a2475d5c3d7efaa4d22250f775f32eb Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 1 Mar 2023 08:35:52 -0600 Subject: [PATCH 07/14] Trying to debug transient "disconnects" in iOS (#2312) * Add back lines from original Adafruit example sketch * Stop advertising debug message * Yank it --- src/platform/nrf52/NRF52Bluetooth.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/nrf52/NRF52Bluetooth.cpp b/src/platform/nrf52/NRF52Bluetooth.cpp index 044b57ae6..59d11717a 100644 --- a/src/platform/nrf52/NRF52Bluetooth.cpp +++ b/src/platform/nrf52/NRF52Bluetooth.cpp @@ -92,12 +92,12 @@ void startAdv(void) Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); // IncludeService UUID - // Bluefruit.ScanResponse.addService(meshBleService); + Bluefruit.ScanResponse.addService(meshBleService); Bluefruit.ScanResponse.addTxPower(); Bluefruit.ScanResponse.addName(); // Include Name - // Bluefruit.Advertising.addName(); + Bluefruit.Advertising.addName(); Bluefruit.Advertising.addService(meshBleService); /* Start Advertising From 214feb1f21a9fd7ec45b14908ad04d96528521ee Mon Sep 17 00:00:00 2001 From: "A. Rager" Date: Wed, 1 Mar 2023 06:36:25 -0800 Subject: [PATCH 08/14] Add Hardware: BetaFPV 900 Nano TX (#2249) Co-authored-by: Ben Meadors --- src/platform/esp32/architecture.h | 2 ++ variants/betafpv_900_tx_nano/platformio.ini | 16 ++++++++++++ variants/betafpv_900_tx_nano/variant.h | 28 +++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 variants/betafpv_900_tx_nano/platformio.ini create mode 100644 variants/betafpv_900_tx_nano/variant.h diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index edd16ebbd..45ee7e6d4 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -97,6 +97,8 @@ #define HW_VENDOR meshtastic_HardwareModel_BETAFPV_2400_TX #elif defined(NANO_G1_EXPLORER) #define HW_VENDOR meshtastic_HardwareModel_NANO_G1_EXPLORER +#elif defined(BETAFPV_900_TX_NANO) +#define HW_VENDOR meshtastic_HardwareModel_BETAFPV_900_NANO_TX #endif // diff --git a/variants/betafpv_900_tx_nano/platformio.ini b/variants/betafpv_900_tx_nano/platformio.ini new file mode 100644 index 000000000..e4c945cab --- /dev/null +++ b/variants/betafpv_900_tx_nano/platformio.ini @@ -0,0 +1,16 @@ +[env:betafpv_900_tx_nano] +extends = esp32_base +board = esp32doit-devkit-v1 +build_flags = + ${esp32_base.build_flags} + -D BETAFPV_900_TX_NANO + -D VTABLES_IN_FLASH=1 + -D CONFIG_DISABLE_HAL_LOCKS=1 + -O2 + -I variants/betafpv_900_tx_nano +board_build.f_cpu = 240000000L +upload_protocol = esptool +upload_port = /dev/ttyUSB0 +upload_speed = 460800 +lib_deps = + ${esp32_base.lib_deps} diff --git a/variants/betafpv_900_tx_nano/variant.h b/variants/betafpv_900_tx_nano/variant.h new file mode 100644 index 000000000..01961d92d --- /dev/null +++ b/variants/betafpv_900_tx_nano/variant.h @@ -0,0 +1,28 @@ +// https://betafpv.com/products/elrs-nano-tx-module + +// no screen +#define HAS_SCREEN 0 + +// NO GPS +#undef GPS_RX_PIN +#undef GPS_TX_PIN + +#define USE_RF95 + +#define RF95_SCK 18 +#define RF95_MISO 19 +#define RF95_MOSI 23 +#define RF95_NSS 5 + +#define LORA_DIO0 4 +#define LORA_RESET 14 +#define LORA_DIO1 2 +#define LORA_DIO2 +#define LORA_DIO3 + +#define LED_PIN 16 // green - blue is at 17 + +#define BUTTON_PIN 25 +#define BUTTON_NEED_PULLUP + +#undef EXT_NOTIFY_OUT From 7bb281d5c569870c27cdd65bcd14507148e4ca9b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 1 Mar 2023 12:31:58 -0600 Subject: [PATCH 09/14] [create-pull-request] automated change (#2316) Co-authored-by: thebentern --- protobufs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 9825eadc8..b3d05ec99 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 9825eadc84d3af5ffe8b3432b7b2072f03e3de23 +Subproject commit b3d05ec995844ae888e1d43d6e5c770b7d654309 From 8c059a8a9efad5e22f03a9d191f622e5a0307104 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 2 Mar 2023 08:34:00 -0600 Subject: [PATCH 10/14] [create-pull-request] automated change (#2317) Co-authored-by: thebentern --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 202cb0780..dca62c699 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 0 -build = 23 +build = 24 From eb4ab26e1f8e292666a1c05309147f0c3ad6eeb6 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Thu, 2 Mar 2023 20:22:14 +0100 Subject: [PATCH 11/14] Check if packet is decrypted before searching node in DB (#2320) * Check whether TraceRouteModule exists In case in the future we don't enable it * Check whether packet is decrypted before searching node in DB --- src/mesh/FloodingRouter.cpp | 3 ++- src/mesh/MeshService.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index d0925d0a1..d8861943e 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -44,7 +44,8 @@ void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtas tosend->hop_limit--; // bump down the hop count // If it is a traceRoute request, update the route that it went via me - if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag && traceRouteModule->wantPacket(p)) { + if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag && traceRouteModule && + traceRouteModule->wantPacket(p)) { traceRouteModule->updateRoute(tosend); } diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 80fea011b..650f6882b 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -76,7 +76,7 @@ int MeshService::handleFromRadio(const meshtastic_MeshPacket *mp) powerFSM.trigger(EVENT_PACKET_FOR_PHONE); // Possibly keep the node from sleeping nodeDB.updateFrom(*mp); // update our DB state based off sniffing every RX packet from the radio - if (!nodeDB.getNode(mp->from)->has_user && nodeInfoModule) { + if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && !nodeDB.getNode(mp->from)->has_user && nodeInfoModule) { LOG_INFO("Heard a node we don't know, sending NodeInfo and asking for a response.\n"); nodeInfoModule->sendOurNodeInfo(mp->from, true); } From 0940c6462b18a7bc5986bf310d4858f9c52d966c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 23 Feb 2023 22:54:07 +0100 Subject: [PATCH 12/14] Leaving this here in case someone ever needs int :-) --- arch/esp32/esp32c3.ini | 46 +++++++++++++++++++++++++++++++ src/mesh/http/ContentHandler.cpp | 2 +- src/modules/Modules.cpp | 2 +- src/modules/SerialModule.cpp | 2 +- src/modules/SerialModule.h | 2 +- src/platform/esp32/main-esp32.cpp | 7 +++++ src/sleep.cpp | 2 ++ 7 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 arch/esp32/esp32c3.ini diff --git a/arch/esp32/esp32c3.ini b/arch/esp32/esp32c3.ini new file mode 100644 index 000000000..08ab377df --- /dev/null +++ b/arch/esp32/esp32c3.ini @@ -0,0 +1,46 @@ +[esp32c3_base] +extends = arduino_base +platform = platformio/espressif32@^6.0.0 +build_src_filter = + ${arduino_base.build_src_filter} - - - - +upload_speed = 961200 +monitor_speed = 115200 +debug_init_break = tbreak setup +monitor_filters = esp32_exception_decoder +board_build.filesystem = littlefs + +# Remove -DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL for low level BLE logging. +# See library directory for BLE logging possible values: .pio/libdeps/tbeam/NimBLE-Arduino/src/log_common/log_common.h +# This overrides the BLE logging default of LOG_LEVEL_INFO (1) from: .pio/libdeps/tbeam/NimBLE-Arduino/src/esp_nimble_cfg.h +build_flags = + ${arduino_base.build_flags} + -Wall + -Wextra + -Isrc/platform/esp32 + -std=c++11 + -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG + -DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL + -DAXP_DEBUG_PORT=Serial + -DCONFIG_BT_NIMBLE_ENABLED + -DCONFIG_NIMBLE_CPP_LOG_LEVEL=2 + -DCONFIG_BT_NIMBLE_MAX_CCCDS=20 + -DESP_OPENSSL_SUPPRESS_LEGACY_WARNING + ;-DDEBUG_HEAP + +lib_deps = + ${arduino_base.lib_deps} + ${networking_base.lib_deps} + ${environmental_base.lib_deps} + https://github.com/meshtastic/esp32_https_server.git#23665b3adc080a311dcbb586ed5941b5f94d6ea2 + h2zero/NimBLE-Arduino@^1.4.0 + https://github.com/lewisxhe/XPowersLib.git#84b7373faea3118b6c37954d52f98b8a337148d6 + caveman99/ESP32 Codec2@^1.0.1 + +lib_ignore = + segger_rtt + ESP32 BLE Arduino + +; customize the partition table +; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables +board_build.partitions = partition-table.csv \ No newline at end of file diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index 8683f9cb1..0a93298b9 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -833,7 +833,7 @@ void handleScanNetworks(HTTPRequest *req, HTTPResponse *res) if (WiFi.encryptionType(i) != WIFI_AUTH_OPEN) { JSONObject thisNetwork; thisNetwork["ssid"] = new JSONValue(ssidArray); - thisNetwork["rssi"] = new JSONValue(WiFi.RSSI(i)); + thisNetwork["rssi"] = new JSONValue(int(WiFi.RSSI(i))); networkObjs.push_back(new JSONValue(thisNetwork)); } // Yield some cpu cycles to IP stack. diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index 3247d02c1..30034b788 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -72,7 +72,7 @@ void setupModules() new AirQualityTelemetryModule(); } #endif -#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) +#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) &&!defined(CONFIG_IDF_TARGET_ESP32C3) new SerialModule(); #endif #ifdef ARCH_ESP32 diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 5637f7eb1..b13e80015 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -44,7 +44,7 @@ */ -#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) +#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #define RX_BUFFER 128 #define TIMEOUT 250 diff --git a/src/modules/SerialModule.h b/src/modules/SerialModule.h index 8c53d2064..5aa0f97b2 100644 --- a/src/modules/SerialModule.h +++ b/src/modules/SerialModule.h @@ -8,7 +8,7 @@ #include #include -#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) +#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) class SerialModule : public StreamAPI, private concurrency::OSThread { diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index f6bd4f50e..4f627d270 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -178,6 +178,7 @@ void cpuDeepSleep(uint64_t msecToWake) Note: we don't isolate pins that are used for the LORA, LED, i2c, spi or the wake button */ +#if SOC_RTCIO_HOLD_SUPPORTED static const uint8_t rtcGpios[] = {/* 0, */ 2, /* 4, */ #ifndef USE_JTAG @@ -189,8 +190,10 @@ void cpuDeepSleep(uint64_t msecToWake) 36, 37 /* 38, 39 */}; + for (int i = 0; i < sizeof(rtcGpios); i++) rtc_gpio_isolate((gpio_num_t)rtcGpios[i]); +#endif // FIXME, disable internal rtc pullups/pulldowns on the non isolated pins. for inputs that we aren't using // to detect wake and in normal operation the external part drives them hard. @@ -200,7 +203,9 @@ void cpuDeepSleep(uint64_t msecToWake) #ifdef BUTTON_PIN // Only GPIOs which are have RTC functionality can be used in this bit map: 0,2,4,12-15,25-27,32-39. +#if SOC_RTCIO_HOLD_SUPPORTED uint64_t gpioMask = (1ULL << BUTTON_PIN); +#endif #ifdef BUTTON_NEED_PULLUP gpio_pullup_en((gpio_num_t)BUTTON_PIN); @@ -210,7 +215,9 @@ void cpuDeepSleep(uint64_t msecToWake) // FIXME change polarity in hw so we can wake on ANY_HIGH instead - that would allow us to use all three buttons (instead of // just the first) gpio_pullup_en((gpio_num_t)BUTTON_PIN); +#if SOC_PM_SUPPORT_EXT_WAKEUP esp_sleep_enable_ext1_wakeup(gpioMask, ESP_EXT1_WAKEUP_ALL_LOW); +#endif #endif esp_sleep_enable_timer_wakeup(msecToWake * 1000ULL); // call expects usecs diff --git a/src/sleep.cpp b/src/sleep.cpp index 77c8d7119..72d4974af 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -337,6 +337,8 @@ void enableModemSleep() esp32_config.max_freq_mhz = CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ; #elif CONFIG_IDF_TARGET_ESP32S2 esp32_config.max_freq_mhz = CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ; +#elif CONFIG_IDF_TARGET_ESP32C3 + esp32_config.max_freq_mhz = CONFIG_ESP32C3_DEFAULT_CPU_FREQ_MHZ; #else esp32_config.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ; #endif From ecd67f0a859fc6932b667637c3c6d84b6aca5aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 24 Feb 2023 09:32:31 +0100 Subject: [PATCH 13/14] disable the frequency switcher for the C3 CPU... --- src/sleep.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sleep.cpp b/src/sleep.cpp index 72d4974af..9bdd52cb3 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -61,13 +61,15 @@ void setCPUFast(bool on) * all WiFi use cases. * (Added: Dec 23, 2021 by Jm Casler) */ +#ifndef CONFIG_IDF_TARGET_ESP32C3 LOG_DEBUG("Setting CPU to 240mhz because WiFi is in use.\n"); setCpuFrequencyMhz(240); +#endif return; } // The Heltec LORA32 V1 runs at 26 MHz base frequency and doesn't react well to switching to 80 MHz... -#ifndef ARDUINO_HELTEC_WIFI_LORA_32 +#if !defined(ARDUINO_HELTEC_WIFI_LORA_32) && !defined(CONFIG_IDF_TARGET_ESP32C3) setCpuFrequencyMhz(on ? 240 : 80); #endif From 4355f51a90642015347ab74a0ee8f6fb950c15bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 24 Feb 2023 09:53:25 +0100 Subject: [PATCH 14/14] fmt --- src/modules/Modules.cpp | 3 ++- src/modules/SerialModule.cpp | 3 ++- src/modules/SerialModule.h | 3 ++- src/platform/esp32/main-esp32.cpp | 3 +-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index 30034b788..5d49a213e 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -72,7 +72,8 @@ void setupModules() new AirQualityTelemetryModule(); } #endif -#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) &&!defined(CONFIG_IDF_TARGET_ESP32C3) +#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) && \ + !defined(CONFIG_IDF_TARGET_ESP32C3) new SerialModule(); #endif #ifdef ARCH_ESP32 diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index b13e80015..35b83e6c6 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -44,7 +44,8 @@ */ -#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) && \ + !defined(CONFIG_IDF_TARGET_ESP32C3) #define RX_BUFFER 128 #define TIMEOUT 250 diff --git a/src/modules/SerialModule.h b/src/modules/SerialModule.h index 5aa0f97b2..cc696316d 100644 --- a/src/modules/SerialModule.h +++ b/src/modules/SerialModule.h @@ -8,7 +8,8 @@ #include #include -#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) && \ + !defined(CONFIG_IDF_TARGET_ESP32C3) class SerialModule : public StreamAPI, private concurrency::OSThread { diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index 4f627d270..95e899a71 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -178,7 +178,7 @@ void cpuDeepSleep(uint64_t msecToWake) Note: we don't isolate pins that are used for the LORA, LED, i2c, spi or the wake button */ -#if SOC_RTCIO_HOLD_SUPPORTED +#if SOC_RTCIO_HOLD_SUPPORTED static const uint8_t rtcGpios[] = {/* 0, */ 2, /* 4, */ #ifndef USE_JTAG @@ -190,7 +190,6 @@ void cpuDeepSleep(uint64_t msecToWake) 36, 37 /* 38, 39 */}; - for (int i = 0; i < sizeof(rtcGpios); i++) rtc_gpio_isolate((gpio_num_t)rtcGpios[i]); #endif