From 9b4c260a92fba177896bb3ea53b1b2f001a023c6 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:22:22 +0100 Subject: [PATCH 01/29] Fix memory leak in MQTT (#5311) --- src/mqtt/MQTT.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 76607f6d2..0e2710940 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -580,6 +580,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp_encrypted, const meshtastic_Me LOG_DEBUG("portnum %i message", env->packet->decoded.portnum); } else { LOG_DEBUG("nothing, pkt not decrypted"); + mqttPool.release(env); return; // Don't upload a still-encrypted PKI packet if not encryption_enabled } @@ -768,4 +769,4 @@ bool MQTT::isPrivateIpAddress(const char address[]) int octet2Num = atoi(octet2); return octet2Num >= 16 && octet2Num <= 31; -} +} \ No newline at end of file From 6eba2789d06e15a989529c3c53182bd8680f09fc Mon Sep 17 00:00:00 2001 From: "Daniel.Cao" <144674500+DanielCao0@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:37:43 +0800 Subject: [PATCH 02/29] rak10701 (rak wismeshtap) optimization (#5280) * Improve the processing speed of virtual keyboards * Remove the disable GPS feature, as it would interfere with the normal use of TFT * Changed the default screen sleep time to 30s * Rename platform rak10701 -> rak wismeshtap * Fixed rak wismeshtap turned off gps caused the screen not to display * Reduce the size of the flash, otherwise uf2 will not work Co-authored-by: Daniel Cao Co-authored-by: Ben Meadors Co-authored-by: Tom Fifield --- platformio.ini | 2 +- src/input/TouchScreenBase.cpp | 22 +++++++++++++++++++ src/mesh/NodeDB.cpp | 2 +- src/modules/CannedMessageModule.cpp | 11 ++++++++++ src/modules/CannedMessageModule.h | 4 ++++ .../platformio.ini | 9 +++++--- .../{rak10701 => rak_wismeshtap}/variant.cpp | 0 .../{rak10701 => rak_wismeshtap}/variant.h | 2 +- 8 files changed, 46 insertions(+), 6 deletions(-) rename variants/{rak10701 => rak_wismeshtap}/platformio.ini (80%) rename variants/{rak10701 => rak_wismeshtap}/variant.cpp (100%) rename variants/{rak10701 => rak_wismeshtap}/variant.h (99%) diff --git a/platformio.ini b/platformio.ini index 7057d574f..6df9f4724 100644 --- a/platformio.ini +++ b/platformio.ini @@ -29,7 +29,7 @@ default_envs = tbeam ;default_envs = rak4631 ;default_envs = rak4631_eth_gw ;default_envs = rak2560 -;default_envs = rak10701 +;default_envs = rak_wismeshtap ;default_envs = wio-e5 ;default_envs = radiomaster_900_bandit_nano ;default_envs = radiomaster_900_bandit_micro diff --git a/src/input/TouchScreenBase.cpp b/src/input/TouchScreenBase.cpp index 03618b338..a63203362 100644 --- a/src/input/TouchScreenBase.cpp +++ b/src/input/TouchScreenBase.cpp @@ -1,6 +1,10 @@ #include "TouchScreenBase.h" #include "main.h" +#if defined(RAK14014) && !defined(MESHTASTIC_EXCLUDE_CANNEDMESSAGES) +#include "modules/CannedMessageModule.h" +#endif + #ifndef TIME_LONG_PRESS #define TIME_LONG_PRESS 400 #endif @@ -102,12 +106,30 @@ int32_t TouchScreenBase::runOnce() } _touchedOld = touched; +#if defined RAK14014 + // Speed up the processing speed of the keyboard in virtual keyboard mode + auto state = cannedMessageModule->getRunState(); + if (state == CANNED_MESSAGE_RUN_STATE_FREETEXT) { + if (_tapped) { + _tapped = false; + e.touchEvent = static_cast(TOUCH_ACTION_TAP); + LOG_DEBUG("action TAP(%d/%d)\n", _last_x, _last_y); + } + } else { + if (_tapped && (time_t(millis()) - _start) > TIME_LONG_PRESS - 50) { + _tapped = false; + e.touchEvent = static_cast(TOUCH_ACTION_TAP); + LOG_DEBUG("action TAP(%d/%d)\n", _last_x, _last_y); + } + } +#else // fire TAP event when no 2nd tap occured within time if (_tapped && (time_t(millis()) - _start) > TIME_LONG_PRESS - 50) { _tapped = false; e.touchEvent = static_cast(TOUCH_ACTION_TAP); LOG_DEBUG("action TAP(%d/%d)", _last_x, _last_y); } +#endif // fire LONG_PRESS event without the need for release if (touched && (time_t(millis()) - _start) > TIME_LONG_PRESS) { diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 632f03456..c105d9ef3 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -473,7 +473,7 @@ void NodeDB::initConfigIntervals() config.display.screen_on_secs = default_screen_on_secs; -#if defined(T_WATCH_S3) || defined(T_DECK) +#if defined(T_WATCH_S3) || defined(T_DECK) || defined(RAK14014) config.power.is_power_saving = true; config.display.screen_on_secs = 30; config.power.wait_bluetooth_secs = 30; diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index bb3a314a2..37409b43b 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -325,7 +325,9 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event) this->shift = !this->shift; } else if (keyTapped == "⌫") { +#ifndef RAK14014 this->highlight = keyTapped[0]; +#endif this->payload = 0x08; @@ -341,7 +343,9 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event) validEvent = true; } else if (keyTapped == " ") { +#ifndef RAK14014 this->highlight = keyTapped[0]; +#endif this->payload = keyTapped[0]; @@ -361,7 +365,9 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event) this->shift = false; } else if (keyTapped != "") { +#ifndef RAK14014 this->highlight = keyTapped[0]; +#endif this->payload = this->shift ? keyTapped[0] : std::tolower(keyTapped[0]); @@ -830,6 +836,11 @@ void CannedMessageModule::drawKeyboard(OLEDDisplay *display, OLEDDisplayUiState Letter updatedLetter = {letter.character, letter.width, xOffset, yOffset, cellWidth, cellHeight}; +#ifdef RAK14014 // Optimize the touch range of the virtual keyboard in the bottom row + if (outerIndex == outerSize - 1) { + updatedLetter.rectHeight = 240 - yOffset; + } +#endif this->keyboard[this->charSet][outerIndex][innerIndex] = updatedLetter; float characterOffset = ((cellWidth / 2) - (letter.width / 2)); diff --git a/src/modules/CannedMessageModule.h b/src/modules/CannedMessageModule.h index e9dc2bda0..4427be144 100644 --- a/src/modules/CannedMessageModule.h +++ b/src/modules/CannedMessageModule.h @@ -68,6 +68,10 @@ class CannedMessageModule : public SinglePortModule, public Observable + + + + -DMESHTASTIC_EXCLUDE_WIFI=1 + -DMESHTASTIC_EXCLUDE_EXTERNALNOTIFICATION=1 + -DMESHTASTIC_EXCLUDE_WAYPOINT=1 +build_src_filter = ${nrf52_base.build_src_filter} +<../variants/rak_wismeshtap> + + + lib_deps = ${nrf52840_base.lib_deps} ${networking_base.lib_deps} diff --git a/variants/rak10701/variant.cpp b/variants/rak_wismeshtap/variant.cpp similarity index 100% rename from variants/rak10701/variant.cpp rename to variants/rak_wismeshtap/variant.cpp diff --git a/variants/rak10701/variant.h b/variants/rak_wismeshtap/variant.h similarity index 99% rename from variants/rak10701/variant.h rename to variants/rak_wismeshtap/variant.h index c263796ee..19eb841fe 100644 --- a/variants/rak10701/variant.h +++ b/variants/rak_wismeshtap/variant.h @@ -243,7 +243,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG // Therefore must be 1 to keep peripherals powered // Power is on the controllable 3V3_S rail // #define PIN_GPS_RESET (34) -#define PIN_GPS_EN PIN_3V3_EN +// #define PIN_GPS_EN PIN_3V3_EN #define PIN_GPS_PPS (17) // Pulse per second input from the GPS #define GPS_RX_PIN PIN_SERIAL1_RX From 3a9a4bbb92b02e83fbca5137819bb63efa0031e3 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Mon, 11 Nov 2024 07:00:56 -0600 Subject: [PATCH 03/29] Coerce minimum neighborinfo interval on startup (#5314) --- src/mesh/NodeDB.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index c105d9ef3..ed6e59ac1 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -231,6 +231,9 @@ NodeDB::NodeDB() moduleConfig.telemetry.health_update_interval = Default::getConfiguredOrMinimumValue( moduleConfig.telemetry.health_update_interval, min_default_telemetry_interval_secs); } + // Ensure that the neighbor info update interval is coerced to the minimum + moduleConfig.neighbor_info.update_interval = + Default::getConfiguredOrMinimumValue(moduleConfig.neighbor_info.update_interval, min_neighbor_info_broadcast_secs); if (devicestateCRC != crc32Buffer(&devicestate, sizeof(devicestate))) saveWhat |= SEGMENT_DEVICESTATE; From 3d5eb34c5caf61e657216633bea0b89e24eb9614 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Mon, 11 Nov 2024 07:01:29 -0600 Subject: [PATCH 04/29] Add back some details to the PhoneAPI logs (#5313) --- src/mesh/PhoneAPI.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index edcc04736..20421e73e 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -218,62 +218,70 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) } case STATE_SEND_METADATA: - LOG_DEBUG("Send Metadata"); + LOG_DEBUG("Send device metadata"); fromRadioScratch.which_payload_variant = meshtastic_FromRadio_metadata_tag; fromRadioScratch.metadata = getDeviceMetadata(); state = STATE_SEND_CHANNELS; break; case STATE_SEND_CHANNELS: - LOG_DEBUG("Send Channels"); fromRadioScratch.which_payload_variant = meshtastic_FromRadio_channel_tag; fromRadioScratch.channel = channels.getByIndex(config_state); config_state++; // Advance when we have sent all of our Channels if (config_state >= MAX_NUM_CHANNELS) { + LOG_DEBUG("Send channels %d", config_state); state = STATE_SEND_CONFIG; config_state = _meshtastic_AdminMessage_ConfigType_MIN + 1; } break; case STATE_SEND_CONFIG: - LOG_DEBUG("Send Radio config"); fromRadioScratch.which_payload_variant = meshtastic_FromRadio_config_tag; switch (config_state) { case meshtastic_Config_device_tag: + LOG_DEBUG("Send config: device"); fromRadioScratch.config.which_payload_variant = meshtastic_Config_device_tag; fromRadioScratch.config.payload_variant.device = config.device; break; case meshtastic_Config_position_tag: + LOG_DEBUG("Send config: position"); fromRadioScratch.config.which_payload_variant = meshtastic_Config_position_tag; fromRadioScratch.config.payload_variant.position = config.position; break; case meshtastic_Config_power_tag: + LOG_DEBUG("Send config: power"); fromRadioScratch.config.which_payload_variant = meshtastic_Config_power_tag; fromRadioScratch.config.payload_variant.power = config.power; fromRadioScratch.config.payload_variant.power.ls_secs = default_ls_secs; break; case meshtastic_Config_network_tag: + LOG_DEBUG("Send config: network"); fromRadioScratch.config.which_payload_variant = meshtastic_Config_network_tag; fromRadioScratch.config.payload_variant.network = config.network; break; case meshtastic_Config_display_tag: + LOG_DEBUG("Send config: display"); fromRadioScratch.config.which_payload_variant = meshtastic_Config_display_tag; fromRadioScratch.config.payload_variant.display = config.display; break; case meshtastic_Config_lora_tag: + LOG_DEBUG("Send config: lora"); fromRadioScratch.config.which_payload_variant = meshtastic_Config_lora_tag; fromRadioScratch.config.payload_variant.lora = config.lora; break; case meshtastic_Config_bluetooth_tag: + LOG_DEBUG("Send config: bluetooth"); fromRadioScratch.config.which_payload_variant = meshtastic_Config_bluetooth_tag; fromRadioScratch.config.payload_variant.bluetooth = config.bluetooth; break; case meshtastic_Config_security_tag: + LOG_DEBUG("Send config: security"); fromRadioScratch.config.which_payload_variant = meshtastic_Config_security_tag; fromRadioScratch.config.payload_variant.security = config.security; break; case meshtastic_Config_sessionkey_tag: + LOG_DEBUG("Send config: sessionkey"); fromRadioScratch.config.which_payload_variant = meshtastic_Config_sessionkey_tag; break; default: @@ -292,58 +300,70 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) break; case STATE_SEND_MODULECONFIG: - LOG_DEBUG("Send Module Config"); fromRadioScratch.which_payload_variant = meshtastic_FromRadio_moduleConfig_tag; switch (config_state) { case meshtastic_ModuleConfig_mqtt_tag: + LOG_DEBUG("Send module config: mqtt"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_mqtt_tag; fromRadioScratch.moduleConfig.payload_variant.mqtt = moduleConfig.mqtt; break; case meshtastic_ModuleConfig_serial_tag: + LOG_DEBUG("Send module config: serial"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_serial_tag; fromRadioScratch.moduleConfig.payload_variant.serial = moduleConfig.serial; break; case meshtastic_ModuleConfig_external_notification_tag: + LOG_DEBUG("Send module config: ext notification"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_external_notification_tag; fromRadioScratch.moduleConfig.payload_variant.external_notification = moduleConfig.external_notification; break; case meshtastic_ModuleConfig_store_forward_tag: + LOG_DEBUG("Send module config: store forward"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_store_forward_tag; fromRadioScratch.moduleConfig.payload_variant.store_forward = moduleConfig.store_forward; break; case meshtastic_ModuleConfig_range_test_tag: + LOG_DEBUG("Send module config: range test"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_range_test_tag; fromRadioScratch.moduleConfig.payload_variant.range_test = moduleConfig.range_test; break; case meshtastic_ModuleConfig_telemetry_tag: + LOG_DEBUG("Send module config: telemetry"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_telemetry_tag; fromRadioScratch.moduleConfig.payload_variant.telemetry = moduleConfig.telemetry; break; case meshtastic_ModuleConfig_canned_message_tag: + LOG_DEBUG("Send module config: canned message"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_canned_message_tag; fromRadioScratch.moduleConfig.payload_variant.canned_message = moduleConfig.canned_message; break; case meshtastic_ModuleConfig_audio_tag: + LOG_DEBUG("Send module config: audio"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_audio_tag; fromRadioScratch.moduleConfig.payload_variant.audio = moduleConfig.audio; break; case meshtastic_ModuleConfig_remote_hardware_tag: + LOG_DEBUG("Send module config: remote hardware"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_remote_hardware_tag; fromRadioScratch.moduleConfig.payload_variant.remote_hardware = moduleConfig.remote_hardware; break; case meshtastic_ModuleConfig_neighbor_info_tag: + LOG_DEBUG("Send module config: neighbor info"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_neighbor_info_tag; fromRadioScratch.moduleConfig.payload_variant.neighbor_info = moduleConfig.neighbor_info; break; case meshtastic_ModuleConfig_detection_sensor_tag: + LOG_DEBUG("Send module config: detection sensor"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_detection_sensor_tag; fromRadioScratch.moduleConfig.payload_variant.detection_sensor = moduleConfig.detection_sensor; break; case meshtastic_ModuleConfig_ambient_lighting_tag: + LOG_DEBUG("Send module config: ambient lighting"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_ambient_lighting_tag; fromRadioScratch.moduleConfig.payload_variant.ambient_lighting = moduleConfig.ambient_lighting; break; case meshtastic_ModuleConfig_paxcounter_tag: + LOG_DEBUG("Send module config: paxcounter"); fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_paxcounter_tag; fromRadioScratch.moduleConfig.payload_variant.paxcounter = moduleConfig.paxcounter; break; @@ -443,7 +463,7 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) return numbytes; } - LOG_DEBUG("no FromRadio packet available"); + LOG_DEBUG("No FromRadio packet available"); return 0; } From eb8d38a7e9b497e5c3fc6b6c1209ff1d3f80d628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Mon, 11 Nov 2024 16:05:48 +0100 Subject: [PATCH 05/29] radiolib update (#5246) * update radiolib to 7.1.0 * stay at 7.0.2 for STM32, also remove unused board from ESP32 arch --------- Co-authored-by: Ben Meadors --- arch/esp32/esp32.ini | 1 + arch/esp32/esp32c6.ini | 1 + arch/nrf52/nrf52.ini | 1 + arch/portduino/portduino.ini | 1 + arch/rp2xx0/rp2040.ini | 1 + arch/rp2xx0/rp2350.ini | 1 + arch/stm32/stm32.ini | 3 ++- platformio.ini | 6 +++++- src/platform/esp32/architecture.h | 2 -- 9 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/esp32/esp32.ini b/arch/esp32/esp32.ini index 382975e9f..1f17bc691 100644 --- a/arch/esp32/esp32.ini +++ b/arch/esp32/esp32.ini @@ -43,6 +43,7 @@ lib_deps = ${arduino_base.lib_deps} ${networking_base.lib_deps} ${environmental_base.lib_deps} + ${radiolib_base.lib_deps} https://github.com/meshtastic/esp32_https_server.git#23665b3adc080a311dcbb586ed5941b5f94d6ea2 h2zero/NimBLE-Arduino@^1.4.2 https://github.com/dbSuS/libpax.git#7bcd3fcab75037505be9b122ab2b24cc5176b587 diff --git a/arch/esp32/esp32c6.ini b/arch/esp32/esp32c6.ini index 53d7f92ec..3f8b1bdbe 100644 --- a/arch/esp32/esp32c6.ini +++ b/arch/esp32/esp32c6.ini @@ -23,6 +23,7 @@ lib_deps = ${arduino_base.lib_deps} ${networking_base.lib_deps} ${environmental_base.lib_deps} + ${radiolib_base.lib_deps} lewisxhe/XPowersLib@^0.2.6 https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f rweather/Crypto@^0.4.0 diff --git a/arch/nrf52/nrf52.ini b/arch/nrf52/nrf52.ini index 99b38900b..ff0cfcbf5 100644 --- a/arch/nrf52/nrf52.ini +++ b/arch/nrf52/nrf52.ini @@ -21,6 +21,7 @@ build_src_filter = lib_deps= ${arduino_base.lib_deps} + ${radiolib_base.lib_deps} rweather/Crypto@^0.4.0 lib_ignore = diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index 39d1c0b8c..04fd6db09 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -23,6 +23,7 @@ build_src_filter = lib_deps = ${env.lib_deps} ${networking_base.lib_deps} + ${radiolib_base.lib_deps} rweather/Crypto@^0.4.0 https://github.com/lovyan03/LovyanGFX.git#1401c28a47646fe00538d487adcb2eb3c72de805 diff --git a/arch/rp2xx0/rp2040.ini b/arch/rp2xx0/rp2040.ini index c004a3bec..17b5df618 100644 --- a/arch/rp2xx0/rp2040.ini +++ b/arch/rp2xx0/rp2040.ini @@ -22,4 +22,5 @@ lib_ignore = lib_deps = ${arduino_base.lib_deps} ${environmental_base.lib_deps} + ${radiolib_base.lib_deps} rweather/Crypto \ No newline at end of file diff --git a/arch/rp2xx0/rp2350.ini b/arch/rp2xx0/rp2350.ini index 7ef6332e3..33bb36ad1 100644 --- a/arch/rp2xx0/rp2350.ini +++ b/arch/rp2xx0/rp2350.ini @@ -21,4 +21,5 @@ lib_ignore = lib_deps = ${arduino_base.lib_deps} ${environmental_base.lib_deps} + ${radiolib_base.lib_deps} rweather/Crypto diff --git a/arch/stm32/stm32.ini b/arch/stm32/stm32.ini index 715e8aa73..7e211496d 100644 --- a/arch/stm32/stm32.ini +++ b/arch/stm32/stm32.ini @@ -30,8 +30,9 @@ upload_protocol = stlink lib_deps = ${env.lib_deps} charlesbaynham/OSFS@^1.2.3 + jgromes/RadioLib@7.0.2 https://github.com/caveman99/Crypto.git#f61ae26a53f7a2d0ba5511625b8bf8eff3a35d5e lib_ignore = - mathertel/OneButton@~2.6.1 + mathertel/OneButton@2.6.1 Wire \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 6df9f4724..f7c73c190 100644 --- a/platformio.ini +++ b/platformio.ini @@ -88,7 +88,6 @@ build_flags = -Wno-missing-field-initializers monitor_speed = 115200 monitor_filters = direct lib_deps = - jgromes/RadioLib@7.0.2 https://github.com/meshtastic/esp8266-oled-ssd1306.git#e16cee124fe26490cb14880c679321ad8ac89c95 mathertel/OneButton@2.6.1 https://github.com/meshtastic/arduino-fsm.git#7db3702bf0cfe97b783d6c72595e3f38e0b19159 @@ -96,6 +95,7 @@ lib_deps = https://github.com/meshtastic/ArduinoThread.git#1ae8778c85d0a2a729f989e0b1e7d7c4dc84eef0 nanopb/Nanopb@0.4.9 erriez/ErriezCRC32@1.0.1 + ; Used for the code analysis in PIO Home / Inspect check_tool = cppcheck check_skip_packages = yes @@ -121,6 +121,10 @@ lib_deps = arduino-libraries/NTPClient@3.1.0 arcao/Syslog@2.0.0 +[radiolib_base] +lib_deps = + jgromes/RadioLib@7.1.0 + ; Common libs for environmental measurements in telemetry module ; (not included in native / portduino) [environmental_base] diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index ba3050e9a..1a274aa28 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -170,8 +170,6 @@ #define HW_VENDOR meshtastic_HardwareModel_HELTEC_VISION_MASTER_E213 #elif defined(HELTEC_VISION_MASTER_E290) #define HW_VENDOR meshtastic_HardwareModel_HELTEC_VISION_MASTER_E290 -#elif defined(HELTEC_MESH_NODE_T114) -#define HW_VENDOR meshtastic_HardwareModel_HELTEC_MESH_NODE_T114 #elif defined(SENSECAP_INDICATOR) #define HW_VENDOR meshtastic_HardwareModel_SENSECAP_INDICATOR #elif defined(SEEED_XIAO_S3) From 40bc04b521d889e932bcb0d828e44516514e302a Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Tue, 12 Nov 2024 00:54:05 +0100 Subject: [PATCH 06/29] Fix sending duplicate packets to PhoneAPI/MQTT (#5315) * Fix potential duplicate packets to PhoneAPI/MQTT * Fix include error for STM32 * Fix cppcheck error --- src/mesh/FloodingRouter.h | 3 +-- src/mesh/PacketHistory.cpp | 11 ++++++++--- src/mesh/PacketHistory.h | 6 +++--- src/mesh/PhoneAPI.cpp | 3 ++- src/mesh/Router.cpp | 12 ++++++++++-- src/mesh/Router.h | 3 ++- src/modules/RoutingModule.cpp | 10 ++++++++-- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/mesh/FloodingRouter.h b/src/mesh/FloodingRouter.h index 0ed2b5582..e398f8d58 100644 --- a/src/mesh/FloodingRouter.h +++ b/src/mesh/FloodingRouter.h @@ -1,6 +1,5 @@ #pragma once -#include "PacketHistory.h" #include "Router.h" /** @@ -26,7 +25,7 @@ Any entries in recentBroadcasts that are older than X seconds (longer than the max time a flood can take) will be discarded. */ -class FloodingRouter : public Router, protected PacketHistory +class FloodingRouter : public Router { private: bool isRebroadcaster(); diff --git a/src/mesh/PacketHistory.cpp b/src/mesh/PacketHistory.cpp index 94337d092..b29d67d66 100644 --- a/src/mesh/PacketHistory.cpp +++ b/src/mesh/PacketHistory.cpp @@ -16,7 +16,7 @@ PacketHistory::PacketHistory() /** * Update recentBroadcasts and return true if we have already seen this packet */ -bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpdate) +bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpdate, bool *isRepeated) { if (p->id == 0) { LOG_DEBUG("Ignore message with zero id"); @@ -41,7 +41,12 @@ bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpd /* If the original transmitter is doing retransmissions (hopStart equals hopLimit) for a reliable transmission, e.g., when the ACK got lost, we will handle the packet again to make sure it gets an ACK/response to its packet. */ if (seenRecently && p->hop_start > 0 && p->hop_start == p->hop_limit) { - LOG_DEBUG("Repeated reliable tx"); + if (withUpdate) + LOG_DEBUG("Repeated reliable tx"); + + if (isRepeated) + *isRepeated = true; + seenRecently = false; } @@ -54,7 +59,7 @@ bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpd recentPackets.erase(found); // as unsorted_set::iterator is const (can't update timestamp - so re-insert..) } recentPackets.insert(r); - printPacket("Add packet record", p); + LOG_DEBUG("Add packet record fr=0x%x, id=0x%x", p->from, p->id); } // Capacity is reerved, so only purge expired packets if recentPackets fills past 90% capacity diff --git a/src/mesh/PacketHistory.h b/src/mesh/PacketHistory.h index 89d237a02..1f29155fd 100644 --- a/src/mesh/PacketHistory.h +++ b/src/mesh/PacketHistory.h @@ -1,6 +1,6 @@ #pragma once -#include "Router.h" +#include "NodeDB.h" #include /// We clear our old flood record 10 minutes after we see the last of it @@ -41,5 +41,5 @@ class PacketHistory * * @param withUpdate if true and not found we add an entry to recentPackets */ - bool wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpdate = true); -}; + bool wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpdate = true, bool *isRepeated = nullptr); +}; \ No newline at end of file diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 20421e73e..f42c0b59f 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -12,6 +12,7 @@ #include "PhoneAPI.h" #include "PowerFSM.h" #include "RadioInterface.h" +#include "Router.h" #include "TypeConversions.h" #include "main.h" #include "xmodem.h" @@ -656,4 +657,4 @@ int PhoneAPI::onNotify(uint32_t newValue) } return timeout ? -1 : 0; // If we timed out, MeshService should stop iterating through observers as we just removed one -} +} \ No newline at end of file diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 0b46ca3b9..d2017c257 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -622,9 +622,17 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) // us (because we would be able to decrypt it) if (!decoded && moduleConfig.mqtt.encryption_enabled && p->channel == 0x00 && !isBroadcast(p->to) && !isToUs(p)) p_encrypted->pki_encrypted = true; + // After potentially altering it, publish received message to MQTT if we're not the original transmitter of the packet - if ((decoded || p_encrypted->pki_encrypted) && moduleConfig.mqtt.enabled && !isFromUs(p) && mqtt) - mqtt->onSend(*p_encrypted, *p, p->channel); + if ((decoded || p_encrypted->pki_encrypted) && moduleConfig.mqtt.enabled && !isFromUs(p) && mqtt) { + // Check if it wasn't already seen, then we don't need to handle it again + bool isRepeated = false; + bool *rptr = &isRepeated; + wasSeenRecently(p, false, rptr); + if (!isRepeated) { + mqtt->onSend(*p_encrypted, *p, p->channel); + } + } #endif } diff --git a/src/mesh/Router.h b/src/mesh/Router.h index da44d67df..14ce4810b 100644 --- a/src/mesh/Router.h +++ b/src/mesh/Router.h @@ -4,6 +4,7 @@ #include "MemoryPool.h" #include "MeshTypes.h" #include "Observer.h" +#include "PacketHistory.h" #include "PointerQueue.h" #include "RadioInterface.h" #include "concurrency/OSThread.h" @@ -11,7 +12,7 @@ /** * A mesh aware router that supports multiple interfaces. */ -class Router : protected concurrency::OSThread +class Router : protected concurrency::OSThread, protected PacketHistory { private: /// Packets which have just arrived from the radio, ready to be processed by this service and possibly diff --git a/src/modules/RoutingModule.cpp b/src/modules/RoutingModule.cpp index a501e319b..5423318a4 100644 --- a/src/modules/RoutingModule.cpp +++ b/src/modules/RoutingModule.cpp @@ -28,8 +28,14 @@ bool RoutingModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mesh // FIXME - move this to a non promsicious PhoneAPI module? // Note: we are careful not to send back packets that started with the phone back to the phone if ((isBroadcast(mp.to) || isToUs(&mp)) && (mp.from != 0)) { - printPacket("Delivering rx packet", &mp); - service->handleFromRadio(&mp); + // Check if it wasn't already seen, then we don't need to handle it again + bool isRepeated = false; + bool *rptr = &isRepeated; + router->wasSeenRecently(&mp, false, rptr); + if (!isRepeated) { + printPacket("Delivering rx packet", &mp); + service->handleFromRadio(&mp); + } } return false; // Let others look at this message also if they want From 0e4f7003c788b8ce17c02bb21196c3c982b752cc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:55:02 -0600 Subject: [PATCH 07/29] [create-pull-request] automated change (#5320) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> --- protobufs | 2 +- src/mesh/generated/meshtastic/admin.pb.h | 8 ++++++++ src/mesh/generated/meshtastic/deviceonly.pb.h | 13 +++++++++---- src/mesh/generated/meshtastic/mesh.pb.h | 13 +++++++++---- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/protobufs b/protobufs index 04f21f5c7..af2fea10f 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 04f21f5c7238b8e02f794d9282c4786752634b3c +Subproject commit af2fea10fe2eba5857fb8e27975bbcea9c10af8e diff --git a/src/mesh/generated/meshtastic/admin.pb.h b/src/mesh/generated/meshtastic/admin.pb.h index d802eb3da..bbf633ef5 100644 --- a/src/mesh/generated/meshtastic/admin.pb.h +++ b/src/mesh/generated/meshtastic/admin.pb.h @@ -180,6 +180,10 @@ typedef struct _meshtastic_AdminMessage { meshtastic_DeviceUIConfig get_ui_config_response; /* Tell the node to store UI data persistently. */ meshtastic_DeviceUIConfig store_ui_config; + /* Set specified node-num to be ignored on the NodeDB on the device */ + uint32_t set_ignored_node; + /* Set specified node-num to be un-ignored on the NodeDB on the device */ + uint32_t remove_ignored_node; /* Begins an edit transaction for config, module config, owner, and channel settings changes This will delay the standard *implicit* save to the file system and subsequent reboot behavior until committed (commit_edit_settings) */ bool begin_edit_settings; @@ -279,6 +283,8 @@ extern "C" { #define meshtastic_AdminMessage_get_ui_config_request_tag 44 #define meshtastic_AdminMessage_get_ui_config_response_tag 45 #define meshtastic_AdminMessage_store_ui_config_tag 46 +#define meshtastic_AdminMessage_set_ignored_node_tag 47 +#define meshtastic_AdminMessage_remove_ignored_node_tag 48 #define meshtastic_AdminMessage_begin_edit_settings_tag 64 #define meshtastic_AdminMessage_commit_edit_settings_tag 65 #define meshtastic_AdminMessage_factory_reset_device_tag 94 @@ -329,6 +335,8 @@ X(a, STATIC, ONEOF, FIXED32, (payload_variant,set_time_only,set_time_only) X(a, STATIC, ONEOF, BOOL, (payload_variant,get_ui_config_request,get_ui_config_request), 44) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,get_ui_config_response,get_ui_config_response), 45) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,store_ui_config,store_ui_config), 46) \ +X(a, STATIC, ONEOF, UINT32, (payload_variant,set_ignored_node,set_ignored_node), 47) \ +X(a, STATIC, ONEOF, UINT32, (payload_variant,remove_ignored_node,remove_ignored_node), 48) \ X(a, STATIC, ONEOF, BOOL, (payload_variant,begin_edit_settings,begin_edit_settings), 64) \ X(a, STATIC, ONEOF, BOOL, (payload_variant,commit_edit_settings,commit_edit_settings), 65) \ X(a, STATIC, ONEOF, INT32, (payload_variant,factory_reset_device,factory_reset_device), 94) \ diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index 39d056061..d9e291175 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -87,6 +87,9 @@ typedef struct _meshtastic_NodeInfoLite { /* True if node is in our favorites list Persists between NodeDB internal clean ups */ bool is_favorite; + /* True if node is in our ignored list + Persists between NodeDB internal clean ups */ + bool is_ignored; } meshtastic_NodeInfoLite; /* This message is never sent over the wire, but it is used for serializing DB @@ -150,12 +153,12 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_PositionLite_init_default {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN} #define meshtastic_UserLite_init_default {{0}, "", "", _meshtastic_HardwareModel_MIN, 0, _meshtastic_Config_DeviceConfig_Role_MIN, {0, {0}}} -#define meshtastic_NodeInfoLite_init_default {0, false, meshtastic_UserLite_init_default, false, meshtastic_PositionLite_init_default, 0, 0, false, meshtastic_DeviceMetrics_init_default, 0, 0, false, 0, 0} +#define meshtastic_NodeInfoLite_init_default {0, false, meshtastic_UserLite_init_default, false, meshtastic_PositionLite_init_default, 0, 0, false, meshtastic_DeviceMetrics_init_default, 0, 0, false, 0, 0, 0} #define meshtastic_DeviceState_init_default {false, meshtastic_MyNodeInfo_init_default, false, meshtastic_User_init_default, 0, {meshtastic_MeshPacket_init_default}, false, meshtastic_MeshPacket_init_default, 0, 0, 0, false, meshtastic_MeshPacket_init_default, 0, {meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default}, {0}} #define meshtastic_ChannelFile_init_default {0, {meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default}, 0} #define meshtastic_PositionLite_init_zero {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN} #define meshtastic_UserLite_init_zero {{0}, "", "", _meshtastic_HardwareModel_MIN, 0, _meshtastic_Config_DeviceConfig_Role_MIN, {0, {0}}} -#define meshtastic_NodeInfoLite_init_zero {0, false, meshtastic_UserLite_init_zero, false, meshtastic_PositionLite_init_zero, 0, 0, false, meshtastic_DeviceMetrics_init_zero, 0, 0, false, 0, 0} +#define meshtastic_NodeInfoLite_init_zero {0, false, meshtastic_UserLite_init_zero, false, meshtastic_PositionLite_init_zero, 0, 0, false, meshtastic_DeviceMetrics_init_zero, 0, 0, false, 0, 0, 0} #define meshtastic_DeviceState_init_zero {false, meshtastic_MyNodeInfo_init_zero, false, meshtastic_User_init_zero, 0, {meshtastic_MeshPacket_init_zero}, false, meshtastic_MeshPacket_init_zero, 0, 0, 0, false, meshtastic_MeshPacket_init_zero, 0, {meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero}, {0}} #define meshtastic_ChannelFile_init_zero {0, {meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero}, 0} @@ -182,6 +185,7 @@ extern "C" { #define meshtastic_NodeInfoLite_via_mqtt_tag 8 #define meshtastic_NodeInfoLite_hops_away_tag 9 #define meshtastic_NodeInfoLite_is_favorite_tag 10 +#define meshtastic_NodeInfoLite_is_ignored_tag 11 #define meshtastic_DeviceState_my_node_tag 2 #define meshtastic_DeviceState_owner_tag 3 #define meshtastic_DeviceState_receive_queue_tag 5 @@ -226,7 +230,8 @@ X(a, STATIC, OPTIONAL, MESSAGE, device_metrics, 6) \ X(a, STATIC, SINGULAR, UINT32, channel, 7) \ X(a, STATIC, SINGULAR, BOOL, via_mqtt, 8) \ X(a, STATIC, OPTIONAL, UINT32, hops_away, 9) \ -X(a, STATIC, SINGULAR, BOOL, is_favorite, 10) +X(a, STATIC, SINGULAR, BOOL, is_favorite, 10) \ +X(a, STATIC, SINGULAR, BOOL, is_ignored, 11) #define meshtastic_NodeInfoLite_CALLBACK NULL #define meshtastic_NodeInfoLite_DEFAULT NULL #define meshtastic_NodeInfoLite_user_MSGTYPE meshtastic_UserLite @@ -279,7 +284,7 @@ extern const pb_msgdesc_t meshtastic_ChannelFile_msg; /* meshtastic_DeviceState_size depends on runtime parameters */ #define MESHTASTIC_MESHTASTIC_DEVICEONLY_PB_H_MAX_SIZE meshtastic_ChannelFile_size #define meshtastic_ChannelFile_size 718 -#define meshtastic_NodeInfoLite_size 183 +#define meshtastic_NodeInfoLite_size 185 #define meshtastic_PositionLite_size 28 #define meshtastic_UserLite_size 96 diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index e45d60a19..0d37efd54 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -797,6 +797,9 @@ typedef struct _meshtastic_NodeInfo { /* True if node is in our favorites list Persists between NodeDB internal clean ups */ bool is_favorite; + /* True if node is in our ignored list + Persists between NodeDB internal clean ups */ + bool is_ignored; } meshtastic_NodeInfo; typedef PB_BYTES_ARRAY_T(16) meshtastic_MyNodeInfo_device_id_t; @@ -1157,7 +1160,7 @@ extern "C" { #define meshtastic_Waypoint_init_default {0, false, 0, false, 0, 0, 0, "", "", 0} #define meshtastic_MqttClientProxyMessage_init_default {"", 0, {{0, {0}}}, 0} #define meshtastic_MeshPacket_init_default {0, 0, 0, 0, {meshtastic_Data_init_default}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN, 0, 0, {0, {0}}, 0} -#define meshtastic_NodeInfo_init_default {0, false, meshtastic_User_init_default, false, meshtastic_Position_init_default, 0, 0, false, meshtastic_DeviceMetrics_init_default, 0, 0, false, 0, 0} +#define meshtastic_NodeInfo_init_default {0, false, meshtastic_User_init_default, false, meshtastic_Position_init_default, 0, 0, false, meshtastic_DeviceMetrics_init_default, 0, 0, false, 0, 0, 0} #define meshtastic_MyNodeInfo_init_default {0, 0, 0, {0, {0}}, ""} #define meshtastic_LogRecord_init_default {"", 0, "", _meshtastic_LogRecord_Level_MIN} #define meshtastic_QueueStatus_init_default {0, 0, 0, 0} @@ -1182,7 +1185,7 @@ extern "C" { #define meshtastic_Waypoint_init_zero {0, false, 0, false, 0, 0, 0, "", "", 0} #define meshtastic_MqttClientProxyMessage_init_zero {"", 0, {{0, {0}}}, 0} #define meshtastic_MeshPacket_init_zero {0, 0, 0, 0, {meshtastic_Data_init_zero}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN, 0, 0, {0, {0}}, 0} -#define meshtastic_NodeInfo_init_zero {0, false, meshtastic_User_init_zero, false, meshtastic_Position_init_zero, 0, 0, false, meshtastic_DeviceMetrics_init_zero, 0, 0, false, 0, 0} +#define meshtastic_NodeInfo_init_zero {0, false, meshtastic_User_init_zero, false, meshtastic_Position_init_zero, 0, 0, false, meshtastic_DeviceMetrics_init_zero, 0, 0, false, 0, 0, 0} #define meshtastic_MyNodeInfo_init_zero {0, 0, 0, {0, {0}}, ""} #define meshtastic_LogRecord_init_zero {"", 0, "", _meshtastic_LogRecord_Level_MIN} #define meshtastic_QueueStatus_init_zero {0, 0, 0, 0} @@ -1287,6 +1290,7 @@ extern "C" { #define meshtastic_NodeInfo_via_mqtt_tag 8 #define meshtastic_NodeInfo_hops_away_tag 9 #define meshtastic_NodeInfo_is_favorite_tag 10 +#define meshtastic_NodeInfo_is_ignored_tag 11 #define meshtastic_MyNodeInfo_my_node_num_tag 1 #define meshtastic_MyNodeInfo_reboot_count_tag 8 #define meshtastic_MyNodeInfo_min_app_version_tag 11 @@ -1485,7 +1489,8 @@ X(a, STATIC, OPTIONAL, MESSAGE, device_metrics, 6) \ X(a, STATIC, SINGULAR, UINT32, channel, 7) \ X(a, STATIC, SINGULAR, BOOL, via_mqtt, 8) \ X(a, STATIC, OPTIONAL, UINT32, hops_away, 9) \ -X(a, STATIC, SINGULAR, BOOL, is_favorite, 10) +X(a, STATIC, SINGULAR, BOOL, is_favorite, 10) \ +X(a, STATIC, SINGULAR, BOOL, is_ignored, 11) #define meshtastic_NodeInfo_CALLBACK NULL #define meshtastic_NodeInfo_DEFAULT NULL #define meshtastic_NodeInfo_user_MSGTYPE meshtastic_User @@ -1724,7 +1729,7 @@ extern const pb_msgdesc_t meshtastic_ChunkedPayloadResponse_msg; #define meshtastic_MyNodeInfo_size 77 #define meshtastic_NeighborInfo_size 258 #define meshtastic_Neighbor_size 22 -#define meshtastic_NodeInfo_size 317 +#define meshtastic_NodeInfo_size 319 #define meshtastic_NodeRemoteHardwarePin_size 29 #define meshtastic_Position_size 144 #define meshtastic_QueueStatus_size 23 From 0acccdfe2d09c45a29e75dd0061a7cfdd05656c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gjels=C3=B8?= <36234524+gjelsoe@users.noreply.github.com> Date: Tue, 12 Nov 2024 02:11:54 +0100 Subject: [PATCH 08/29] Don't send to public channel (#5310) * Don't send to public channel `p->to` wasn't set and had the same value as broadcast, it's now set to our own NodeNum. * Trunk * Update DetectionSensorModule.cpp Take 3 * Revert NodeNum() --- src/modules/DetectionSensorModule.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/modules/DetectionSensorModule.cpp b/src/modules/DetectionSensorModule.cpp index cb27cbd48..c479867fc 100644 --- a/src/modules/DetectionSensorModule.cpp +++ b/src/modules/DetectionSensorModule.cpp @@ -58,7 +58,7 @@ int32_t DetectionSensorModule::runOnce() // moduleConfig.detection_sensor.minimum_broadcast_secs = 30; // moduleConfig.detection_sensor.state_broadcast_secs = 120; // moduleConfig.detection_sensor.detection_trigger_type = - // meshtastic_ModuleConfig_DetectionSensorConfig_TriggerType_LOGIC_HIGH; + // meshtastic_ModuleConfig_DetectionSensorConfig_TriggerType_LOGIC_HIGH; // strcpy(moduleConfig.detection_sensor.name, "Motion"); if (moduleConfig.detection_sensor.enabled == false) @@ -130,9 +130,12 @@ void DetectionSensorModule::sendDetectionMessage() p->decoded.payload.bytes[p->decoded.payload.size + 1] = '\0'; // Bell character p->decoded.payload.size++; } - LOG_INFO("Send message id=%d, dest=%x, msg=%.*s", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes); lastSentToMesh = millis(); - service->sendToMesh(p); + if (!channels.isDefaultChannel(0)) { + LOG_INFO("Send message id=%d, dest=%x, msg=%.*s", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes); + service->sendToMesh(p); + } else + LOG_ERROR("Message not allow on Public channel"); delete[] message; } @@ -140,14 +143,16 @@ void DetectionSensorModule::sendCurrentStateMessage(bool state) { char *message = new char[40]; sprintf(message, "%s state: %i", moduleConfig.detection_sensor.name, state); - meshtastic_MeshPacket *p = allocDataPacket(); p->want_ack = false; p->decoded.payload.size = strlen(message); memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size); - LOG_INFO("Send message id=%d, dest=%x, msg=%.*s", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes); lastSentToMesh = millis(); - service->sendToMesh(p); + if (!channels.isDefaultChannel(0)) { + LOG_INFO("Send message id=%d, dest=%x, msg=%.*s", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes); + service->sendToMesh(p); + } else + LOG_ERROR("Message not allow on Public channel"); delete[] message; } @@ -156,4 +161,4 @@ bool DetectionSensorModule::hasDetectionEvent() bool currentState = digitalRead(moduleConfig.detection_sensor.monitor_pin); // LOG_DEBUG("Detection Sensor Module: Current state: %i", currentState); return (moduleConfig.detection_sensor.detection_trigger_type & 1) ? currentState : !currentState; -} \ No newline at end of file +} From 762ccdc1b93d09ef0e30465a9a13d29c014bc244 Mon Sep 17 00:00:00 2001 From: Austin Date: Tue, 12 Nov 2024 03:14:12 -0500 Subject: [PATCH 09/29] Portduino packaging: Move meshtastic/web out of `/usr/share/doc` (#5323) * Portduino: Move meshtastic/web out of `doc` * Remove /usr/share/doc/meshtasticd before linking --- .github/workflows/package_amd64.yml | 14 ++++++++------ .github/workflows/package_raspbian.yml | 14 ++++++++------ .github/workflows/package_raspbian_armv7l.yml | 14 ++++++++------ bin/config-dist.yaml | 2 +- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.github/workflows/package_amd64.yml b/.github/workflows/package_amd64.yml index 4f6636712..9d48e8d28 100644 --- a/.github/workflows/package_amd64.yml +++ b/.github/workflows/package_amd64.yml @@ -47,18 +47,18 @@ jobs: - name: build .debpkg run: | mkdir -p .debpkg/DEBIAN - mkdir -p .debpkg/usr/share/doc/meshtasticd/web + mkdir -p .debpkg/usr/share/meshtasticd/web mkdir -p .debpkg/usr/sbin mkdir -p .debpkg/etc/meshtasticd mkdir -p .debpkg/etc/meshtasticd/config.d mkdir -p .debpkg/etc/meshtasticd/available.d mkdir -p .debpkg/usr/lib/systemd/system/ - tar -xf build.tar -C .debpkg/usr/share/doc/meshtasticd/web + tar -xf build.tar -C .debpkg/usr/share/meshtasticd/web shopt -s dotglob nullglob - if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then mv .debpkg/usr/share/doc/meshtasticd/web/build/* .debpkg/usr/share/doc/meshtasticd/web/; fi - if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/doc/meshtasticd/web/build; fi - if [ -d .debpkg/usr/share/doc/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/doc/meshtasticd/web/.DS_Store; fi - gunzip .debpkg/usr/share/doc/meshtasticd/web/*.gz + if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then mv .debpkg/usr/share/meshtasticd/web/build/* .debpkg/usr/share/meshtasticd/web/; fi + if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/meshtasticd/web/build; fi + if [ -d .debpkg/usr/share/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/meshtasticd/web/.DS_Store; fi + gunzip .debpkg/usr/share/meshtasticd/web/*.gz cp release/meshtasticd_linux_x86_64 .debpkg/usr/sbin/meshtasticd cp bin/config-dist.yaml .debpkg/etc/meshtasticd/config.yaml cp bin/config.d/* .debpkg/etc/meshtasticd/available.d/ @@ -66,6 +66,8 @@ jobs: cp bin/meshtasticd.service .debpkg/usr/lib/systemd/system/meshtasticd.service echo "/etc/meshtasticd/config.yaml" > .debpkg/DEBIAN/conffiles chmod +x .debpkg/DEBIAN/conffiles + echo "rm -rf /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/preinst + echo "/usr/share/meshtasticd /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/meshtasticd.links - uses: jiro4989/build-deb-action@v3 with: diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index d9b12d6da..341443273 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -47,18 +47,18 @@ jobs: - name: build .debpkg run: | mkdir -p .debpkg/DEBIAN - mkdir -p .debpkg/usr/share/doc/meshtasticd/web + mkdir -p .debpkg/usr/share/meshtasticd/web mkdir -p .debpkg/usr/sbin mkdir -p .debpkg/etc/meshtasticd mkdir -p .debpkg/etc/meshtasticd/config.d mkdir -p .debpkg/etc/meshtasticd/available.d mkdir -p .debpkg/usr/lib/systemd/system/ - tar -xf build.tar -C .debpkg/usr/share/doc/meshtasticd/web + tar -xf build.tar -C .debpkg/usr/share/meshtasticd/web shopt -s dotglob nullglob - if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then mv .debpkg/usr/share/doc/meshtasticd/web/build/* .debpkg/usr/share/doc/meshtasticd/web/; fi - if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/doc/meshtasticd/web/build; fi - if [ -d .debpkg/usr/share/doc/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/doc/meshtasticd/web/.DS_Store; fi - gunzip .debpkg/usr/share/doc/meshtasticd/web/*.gz + if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then mv .debpkg/usr/share/meshtasticd/web/build/* .debpkg/usr/share/meshtasticd/web/; fi + if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/meshtasticd/web/build; fi + if [ -d .debpkg/usr/share/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/meshtasticd/web/.DS_Store; fi + gunzip .debpkg/usr/share/meshtasticd/web/*.gz cp release/meshtasticd_linux_aarch64 .debpkg/usr/sbin/meshtasticd cp bin/config-dist.yaml .debpkg/etc/meshtasticd/config.yaml cp bin/config.d/* .debpkg/etc/meshtasticd/available.d/ @@ -66,6 +66,8 @@ jobs: cp bin/meshtasticd.service .debpkg/usr/lib/systemd/system/meshtasticd.service echo "/etc/meshtasticd/config.yaml" > .debpkg/DEBIAN/conffiles chmod +x .debpkg/DEBIAN/conffiles + echo "rm -rf /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/preinst + echo "/usr/share/meshtasticd /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/meshtasticd.links - uses: jiro4989/build-deb-action@v3 with: diff --git a/.github/workflows/package_raspbian_armv7l.yml b/.github/workflows/package_raspbian_armv7l.yml index e19df9d17..73471c662 100644 --- a/.github/workflows/package_raspbian_armv7l.yml +++ b/.github/workflows/package_raspbian_armv7l.yml @@ -47,18 +47,18 @@ jobs: - name: build .debpkg run: | mkdir -p .debpkg/DEBIAN - mkdir -p .debpkg/usr/share/doc/meshtasticd/web + mkdir -p .debpkg/usr/share/meshtasticd/web mkdir -p .debpkg/usr/sbin mkdir -p .debpkg/etc/meshtasticd mkdir -p .debpkg/etc/meshtasticd/config.d mkdir -p .debpkg/etc/meshtasticd/available.d mkdir -p .debpkg/usr/lib/systemd/system/ - tar -xf build.tar -C .debpkg/usr/share/doc/meshtasticd/web + tar -xf build.tar -C .debpkg/usr/share/meshtasticd/web shopt -s dotglob nullglob - if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then mv .debpkg/usr/share/doc/meshtasticd/web/build/* .debpkg/usr/share/doc/meshtasticd/web/; fi - if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/doc/meshtasticd/web/build; fi - if [ -d .debpkg/usr/share/doc/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/doc/meshtasticd/web/.DS_Store; fi - gunzip .debpkg/usr/share/doc/meshtasticd/web/*.gz + if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then mv .debpkg/usr/share/meshtasticd/web/build/* .debpkg/usr/share/meshtasticd/web/; fi + if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/meshtasticd/web/build; fi + if [ -d .debpkg/usr/share/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/meshtasticd/web/.DS_Store; fi + gunzip .debpkg/usr/share/meshtasticd/web/*.gz cp release/meshtasticd_linux_armv7l .debpkg/usr/sbin/meshtasticd cp bin/config-dist.yaml .debpkg/etc/meshtasticd/config.yaml cp bin/config.d/* .debpkg/etc/meshtasticd/available.d/ @@ -66,6 +66,8 @@ jobs: cp bin/meshtasticd.service .debpkg/usr/lib/systemd/system/meshtasticd.service echo "/etc/meshtasticd/config.yaml" > .debpkg/DEBIAN/conffiles chmod +x .debpkg/DEBIAN/conffiles + echo "rm -rf /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/preinst + echo "/usr/share/meshtasticd /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/meshtasticd.links - uses: jiro4989/build-deb-action@v3 with: diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 77680cc63..2a5c6b310 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -155,7 +155,7 @@ Logging: Webserver: # Port: 443 # Port for Webserver & Webservices -# RootPath: /usr/share/doc/meshtasticd/web # Root Dir of WebServer +# RootPath: /usr/share/meshtasticd/web # Root Dir of WebServer General: MaxNodes: 200 From 606c2e8eb0909b4bf316de9ab2a6490a70182c95 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 12 Nov 2024 05:50:30 -0600 Subject: [PATCH 10/29] Exclude paxcounter --- arch/nrf52/nrf52.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/nrf52/nrf52.ini b/arch/nrf52/nrf52.ini index ff0cfcbf5..99e8693dc 100644 --- a/arch/nrf52/nrf52.ini +++ b/arch/nrf52/nrf52.ini @@ -15,6 +15,7 @@ build_flags = -Isrc/platform/nrf52 -DLFS_NO_ASSERT ; Disable LFS assertions , see https://github.com/meshtastic/firmware/pull/3818 -DMESHTASTIC_EXCLUDE_AUDIO=1 + -DMESHTASTIC_EXCLUDE_PAXCOUNTER=1 build_src_filter = ${arduino_base.build_src_filter} - - - - - - - - - - From 51ea7ac627a3ac0a99cc84ad2c6bd802af695d71 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 12 Nov 2024 06:12:09 -0600 Subject: [PATCH 11/29] Trunk toolchain versions --- .trunk/trunk.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 75b4bd6ea..040712e1d 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,6 +1,6 @@ version: 0.1 cli: - version: 1.22.7 + version: 1.22.8 plugins: sources: - id: trunk @@ -8,20 +8,20 @@ plugins: uri: https://github.com/trunk-io/plugins lint: enabled: - - trufflehog@3.83.2 + - trufflehog@3.83.6 - yamllint@1.35.1 - bandit@1.7.10 - - checkov@3.2.277 + - checkov@3.2.287 - terrascan@1.19.9 - trivy@0.56.2 #- trufflehog@3.63.2-rc0 - taplo@0.9.3 - - ruff@0.7.2 + - ruff@0.7.3 - isort@5.13.2 - markdownlint@0.42.0 - oxipng@9.1.2 - svgo@3.3.2 - - actionlint@1.7.3 + - actionlint@1.7.4 - flake8@7.1.1 - hadolint@2.12.0 - shfmt@3.6.0 From ff33a27789ea17fd67ff60a7785bbd42861eb0e2 Mon Sep 17 00:00:00 2001 From: "Daniel.Cao" <144674500+DanielCao0@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:16:40 +0800 Subject: [PATCH 12/29] Reduce the flash usage of wismeshtap platform (#5322) * Reduce the flash usage of wismeshtap platform * fix STOREFORWARD twice * Reduce the flash usage of wismeshtap platform * fix STOREFORWARD twice * add range test * Update platformio.ini remove -DMESHTASTIC_EXCLUDE_PAXCOUNTER=1 -DMESHTASTIC_EXCLUDE_AUDIO=1 * Update platformio.ini --------- Co-authored-by: Ben Meadors --- variants/rak_wismeshtap/platformio.ini | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/variants/rak_wismeshtap/platformio.ini b/variants/rak_wismeshtap/platformio.ini index 38b988dff..eb58b08c0 100644 --- a/variants/rak_wismeshtap/platformio.ini +++ b/variants/rak_wismeshtap/platformio.ini @@ -10,8 +10,11 @@ build_flags = ${nrf52840_base.build_flags} -Ivariants/rak_wismeshtap -D RAK_4631 -DEINK_WIDTH=250 -DEINK_HEIGHT=122 -DMESHTASTIC_EXCLUDE_WIFI=1 - -DMESHTASTIC_EXCLUDE_EXTERNALNOTIFICATION=1 -DMESHTASTIC_EXCLUDE_WAYPOINT=1 + -DMESHTASTIC_EXCLUDE_DETECTIONSENSOR=1 + -DMESHTASTIC_EXCLUDE_STOREFORWARD=1 + -DMESHTASTIC_EXCLUDE_POWER_TELEMETRY=1 + -DMESHTASTIC_EXCLUDE_ATAK=1 build_src_filter = ${nrf52_base.build_src_filter} +<../variants/rak_wismeshtap> + + + lib_deps = ${nrf52840_base.lib_deps} @@ -24,4 +27,4 @@ lib_deps = beegee-tokyo/RAK14014-FT6336U @ 1.0.1 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) -;upload_protocol = jlink \ No newline at end of file +;upload_protocol = jlink From a84324c4fa8ff32b4d1bb075b0e8c8444fc9c41e Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 12 Nov 2024 06:17:26 -0600 Subject: [PATCH 13/29] Don't attempt to save NodeDB on low-batt shutdown to prevent FS corruption (#5312) --- src/Power.cpp | 2 +- src/PowerFSM.cpp | 20 ++++++++++++------- src/modules/PositionModule.cpp | 2 +- src/modules/PowerStressModule.cpp | 2 +- .../Telemetry/EnvironmentTelemetry.cpp | 2 +- src/modules/Telemetry/HealthTelemetry.cpp | 2 +- src/modules/Telemetry/PowerTelemetry.cpp | 2 +- src/sleep.cpp | 6 ++++-- src/sleep.h | 2 +- 9 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index ab09cd08c..4e5cf0f2c 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -614,7 +614,7 @@ void Power::shutdown() #ifdef PIN_LED3 ledOff(PIN_LED3); #endif - doDeepSleep(DELAY_FOREVER, false); + doDeepSleep(DELAY_FOREVER, false, false); #endif } diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 7aa454d34..00dd6c942 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -55,9 +55,14 @@ static void sdsEnter() { LOG_DEBUG("State: SDS"); // FIXME - make sure GPS and LORA radio are off first - because we want close to zero current draw - doDeepSleep(Default::getConfiguredOrDefaultMs(config.power.sds_secs), false); + doDeepSleep(Default::getConfiguredOrDefaultMs(config.power.sds_secs), false, false); } +static void lowBattSDSEnter() +{ + LOG_DEBUG("State: Lower batt SDS"); + doDeepSleep(Default::getConfiguredOrDefaultMs(config.power.sds_secs), false, true); +} extern Power *power; static void shutdownEnter() @@ -247,6 +252,7 @@ static void bootEnter() State stateSHUTDOWN(shutdownEnter, NULL, NULL, "SHUTDOWN"); State stateSDS(sdsEnter, NULL, NULL, "SDS"); +State stateLowBattSDS(lowBattSDSEnter, NULL, NULL, "SDS"); State stateLS(lsEnter, lsIdle, lsExit, "LS"); State stateNB(nbEnter, NULL, NULL, "NB"); State stateDARK(darkEnter, NULL, NULL, "DARK"); @@ -291,12 +297,12 @@ void PowerFSM_setup() "Press"); // Allow button to work while in serial API // Handle critically low power battery by forcing deep sleep - powerFSM.add_transition(&stateBOOT, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); - powerFSM.add_transition(&stateLS, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); - powerFSM.add_transition(&stateNB, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); - powerFSM.add_transition(&stateDARK, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); - powerFSM.add_transition(&stateON, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); - powerFSM.add_transition(&stateSERIAL, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); + powerFSM.add_transition(&stateBOOT, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); + powerFSM.add_transition(&stateLS, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); + powerFSM.add_transition(&stateNB, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); + powerFSM.add_transition(&stateDARK, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); + powerFSM.add_transition(&stateON, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); + powerFSM.add_transition(&stateSERIAL, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat"); // Handle being told to power off powerFSM.add_transition(&stateBOOT, &stateSHUTDOWN, EVENT_SHUTDOWN, NULL, "Shutdown"); diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index f80d3eb67..fc15aabb6 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -364,7 +364,7 @@ int32_t PositionModule::runOnce() sleepOnNextExecution = false; uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(config.position.position_broadcast_secs); LOG_DEBUG("Sleep for %ims, then awaking to send position again", nightyNightMs); - doDeepSleep(nightyNightMs, false); + doDeepSleep(nightyNightMs, false, false); } meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum()); diff --git a/src/modules/PowerStressModule.cpp b/src/modules/PowerStressModule.cpp index 80b14c756..d487fe6fc 100644 --- a/src/modules/PowerStressModule.cpp +++ b/src/modules/PowerStressModule.cpp @@ -111,7 +111,7 @@ int32_t PowerStressModule::runOnce() setBluetoothEnable(true); break; case meshtastic_PowerStressMessage_Opcode_CPU_DEEPSLEEP: - doDeepSleep(sleep_msec, true); + doDeepSleep(sleep_msec, true, true); break; case meshtastic_PowerStressMessage_Opcode_CPU_FULLON: { uint32_t start_msec = millis(); diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index c18944ebd..4ef68d4b7 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -74,7 +74,7 @@ int32_t EnvironmentTelemetryModule::runOnce() uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval, default_telemetry_broadcast_interval_secs); LOG_DEBUG("Sleep for %ims, then awake to send metrics again", nightyNightMs); - doDeepSleep(nightyNightMs, true); + doDeepSleep(nightyNightMs, true, false); } uint32_t result = UINT32_MAX; diff --git a/src/modules/Telemetry/HealthTelemetry.cpp b/src/modules/Telemetry/HealthTelemetry.cpp index 7cacdc6c1..22534e9f5 100644 --- a/src/modules/Telemetry/HealthTelemetry.cpp +++ b/src/modules/Telemetry/HealthTelemetry.cpp @@ -40,7 +40,7 @@ int32_t HealthTelemetryModule::runOnce() uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.health_update_interval, default_telemetry_broadcast_interval_secs); LOG_DEBUG("Sleep for %ims, then awake to send metrics again", nightyNightMs); - doDeepSleep(nightyNightMs, true); + doDeepSleep(nightyNightMs, true, false); } uint32_t result = UINT32_MAX; diff --git a/src/modules/Telemetry/PowerTelemetry.cpp b/src/modules/Telemetry/PowerTelemetry.cpp index 409585f44..367643849 100644 --- a/src/modules/Telemetry/PowerTelemetry.cpp +++ b/src/modules/Telemetry/PowerTelemetry.cpp @@ -28,7 +28,7 @@ int32_t PowerTelemetryModule::runOnce() uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.power_update_interval, default_telemetry_broadcast_interval_secs); LOG_DEBUG("Sleep for %ims, then awake to send metrics again", nightyNightMs); - doDeepSleep(nightyNightMs, true); + doDeepSleep(nightyNightMs, true, false); } uint32_t result = UINT32_MAX; diff --git a/src/sleep.cpp b/src/sleep.cpp index a50f7aac3..05597cdfa 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -187,7 +187,7 @@ static void waitEnterSleep(bool skipPreflight = false) notifySleep.notifyObservers(NULL); } -void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) +void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false, bool skipSaveNodeDb = false) { if (INCLUDE_vTaskSuspend && (msecToWake == portMAX_DELAY)) { LOG_INFO("Enter deep sleep forever"); @@ -219,7 +219,9 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) screen->doDeepSleep(); // datasheet says this will draw only 10ua - nodeDB->saveToDisk(); + if (!skipSaveNodeDb) { + nodeDB->saveToDisk(); + } #ifdef PIN_POWER_EN pinMode(PIN_POWER_EN, INPUT); // power off peripherals diff --git a/src/sleep.h b/src/sleep.h index 6ac420769..8d3cb17e8 100644 --- a/src/sleep.h +++ b/src/sleep.h @@ -4,7 +4,7 @@ #include "Observer.h" #include "configuration.h" -void doDeepSleep(uint32_t msecToWake, bool skipPreflight), cpuDeepSleep(uint32_t msecToWake); +void doDeepSleep(uint32_t msecToWake, bool skipPreflight, bool skipSaveNodeDb), cpuDeepSleep(uint32_t msecToWake); #ifdef ARCH_ESP32 #include "esp_sleep.h" From e65a754430cfe9b067089ec1d9f1ba9a7d976f4e Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 12 Nov 2024 06:20:42 -0600 Subject: [PATCH 14/29] Remove board level extra from wismesh tap --- variants/rak_wismeshtap/platformio.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/variants/rak_wismeshtap/platformio.ini b/variants/rak_wismeshtap/platformio.ini index eb58b08c0..461696d29 100644 --- a/variants/rak_wismeshtap/platformio.ini +++ b/variants/rak_wismeshtap/platformio.ini @@ -1,7 +1,6 @@ ; The very slick RAK wireless RAK10701 Field Tester device. Note you will have to flash to Arduino bootloader to use this firmware. Be aware touch is not currently working. [env:rak_wismeshtap] extends = nrf52840_base -board_level = extra board = wiscore_rak4631 build_flags = ${nrf52840_base.build_flags} -Ivariants/rak_wismeshtap -D RAK_4631 -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m4/fpv4-sp-d16-hard" From a49f080bd2d08bb2a5bb196966b78565ce05a06a Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 12 Nov 2024 06:40:46 -0600 Subject: [PATCH 15/29] Revert "Portduino packaging: Move meshtastic/web out of `/usr/share/doc` (#5323)" (#5325) This reverts commit 762ccdc1b93d09ef0e30465a9a13d29c014bc244. --- .github/workflows/package_amd64.yml | 14 ++++++-------- .github/workflows/package_raspbian.yml | 14 ++++++-------- .github/workflows/package_raspbian_armv7l.yml | 14 ++++++-------- bin/config-dist.yaml | 2 +- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/.github/workflows/package_amd64.yml b/.github/workflows/package_amd64.yml index 9d48e8d28..4f6636712 100644 --- a/.github/workflows/package_amd64.yml +++ b/.github/workflows/package_amd64.yml @@ -47,18 +47,18 @@ jobs: - name: build .debpkg run: | mkdir -p .debpkg/DEBIAN - mkdir -p .debpkg/usr/share/meshtasticd/web + mkdir -p .debpkg/usr/share/doc/meshtasticd/web mkdir -p .debpkg/usr/sbin mkdir -p .debpkg/etc/meshtasticd mkdir -p .debpkg/etc/meshtasticd/config.d mkdir -p .debpkg/etc/meshtasticd/available.d mkdir -p .debpkg/usr/lib/systemd/system/ - tar -xf build.tar -C .debpkg/usr/share/meshtasticd/web + tar -xf build.tar -C .debpkg/usr/share/doc/meshtasticd/web shopt -s dotglob nullglob - if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then mv .debpkg/usr/share/meshtasticd/web/build/* .debpkg/usr/share/meshtasticd/web/; fi - if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/meshtasticd/web/build; fi - if [ -d .debpkg/usr/share/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/meshtasticd/web/.DS_Store; fi - gunzip .debpkg/usr/share/meshtasticd/web/*.gz + if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then mv .debpkg/usr/share/doc/meshtasticd/web/build/* .debpkg/usr/share/doc/meshtasticd/web/; fi + if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/doc/meshtasticd/web/build; fi + if [ -d .debpkg/usr/share/doc/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/doc/meshtasticd/web/.DS_Store; fi + gunzip .debpkg/usr/share/doc/meshtasticd/web/*.gz cp release/meshtasticd_linux_x86_64 .debpkg/usr/sbin/meshtasticd cp bin/config-dist.yaml .debpkg/etc/meshtasticd/config.yaml cp bin/config.d/* .debpkg/etc/meshtasticd/available.d/ @@ -66,8 +66,6 @@ jobs: cp bin/meshtasticd.service .debpkg/usr/lib/systemd/system/meshtasticd.service echo "/etc/meshtasticd/config.yaml" > .debpkg/DEBIAN/conffiles chmod +x .debpkg/DEBIAN/conffiles - echo "rm -rf /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/preinst - echo "/usr/share/meshtasticd /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/meshtasticd.links - uses: jiro4989/build-deb-action@v3 with: diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 341443273..d9b12d6da 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -47,18 +47,18 @@ jobs: - name: build .debpkg run: | mkdir -p .debpkg/DEBIAN - mkdir -p .debpkg/usr/share/meshtasticd/web + mkdir -p .debpkg/usr/share/doc/meshtasticd/web mkdir -p .debpkg/usr/sbin mkdir -p .debpkg/etc/meshtasticd mkdir -p .debpkg/etc/meshtasticd/config.d mkdir -p .debpkg/etc/meshtasticd/available.d mkdir -p .debpkg/usr/lib/systemd/system/ - tar -xf build.tar -C .debpkg/usr/share/meshtasticd/web + tar -xf build.tar -C .debpkg/usr/share/doc/meshtasticd/web shopt -s dotglob nullglob - if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then mv .debpkg/usr/share/meshtasticd/web/build/* .debpkg/usr/share/meshtasticd/web/; fi - if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/meshtasticd/web/build; fi - if [ -d .debpkg/usr/share/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/meshtasticd/web/.DS_Store; fi - gunzip .debpkg/usr/share/meshtasticd/web/*.gz + if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then mv .debpkg/usr/share/doc/meshtasticd/web/build/* .debpkg/usr/share/doc/meshtasticd/web/; fi + if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/doc/meshtasticd/web/build; fi + if [ -d .debpkg/usr/share/doc/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/doc/meshtasticd/web/.DS_Store; fi + gunzip .debpkg/usr/share/doc/meshtasticd/web/*.gz cp release/meshtasticd_linux_aarch64 .debpkg/usr/sbin/meshtasticd cp bin/config-dist.yaml .debpkg/etc/meshtasticd/config.yaml cp bin/config.d/* .debpkg/etc/meshtasticd/available.d/ @@ -66,8 +66,6 @@ jobs: cp bin/meshtasticd.service .debpkg/usr/lib/systemd/system/meshtasticd.service echo "/etc/meshtasticd/config.yaml" > .debpkg/DEBIAN/conffiles chmod +x .debpkg/DEBIAN/conffiles - echo "rm -rf /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/preinst - echo "/usr/share/meshtasticd /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/meshtasticd.links - uses: jiro4989/build-deb-action@v3 with: diff --git a/.github/workflows/package_raspbian_armv7l.yml b/.github/workflows/package_raspbian_armv7l.yml index 73471c662..e19df9d17 100644 --- a/.github/workflows/package_raspbian_armv7l.yml +++ b/.github/workflows/package_raspbian_armv7l.yml @@ -47,18 +47,18 @@ jobs: - name: build .debpkg run: | mkdir -p .debpkg/DEBIAN - mkdir -p .debpkg/usr/share/meshtasticd/web + mkdir -p .debpkg/usr/share/doc/meshtasticd/web mkdir -p .debpkg/usr/sbin mkdir -p .debpkg/etc/meshtasticd mkdir -p .debpkg/etc/meshtasticd/config.d mkdir -p .debpkg/etc/meshtasticd/available.d mkdir -p .debpkg/usr/lib/systemd/system/ - tar -xf build.tar -C .debpkg/usr/share/meshtasticd/web + tar -xf build.tar -C .debpkg/usr/share/doc/meshtasticd/web shopt -s dotglob nullglob - if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then mv .debpkg/usr/share/meshtasticd/web/build/* .debpkg/usr/share/meshtasticd/web/; fi - if [ -d .debpkg/usr/share/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/meshtasticd/web/build; fi - if [ -d .debpkg/usr/share/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/meshtasticd/web/.DS_Store; fi - gunzip .debpkg/usr/share/meshtasticd/web/*.gz + if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then mv .debpkg/usr/share/doc/meshtasticd/web/build/* .debpkg/usr/share/doc/meshtasticd/web/; fi + if [ -d .debpkg/usr/share/doc/meshtasticd/web/build ]; then rmdir .debpkg/usr/share/doc/meshtasticd/web/build; fi + if [ -d .debpkg/usr/share/doc/meshtasticd/web/.DS_Store]; then rm -f .debpkg/usr/share/doc/meshtasticd/web/.DS_Store; fi + gunzip .debpkg/usr/share/doc/meshtasticd/web/*.gz cp release/meshtasticd_linux_armv7l .debpkg/usr/sbin/meshtasticd cp bin/config-dist.yaml .debpkg/etc/meshtasticd/config.yaml cp bin/config.d/* .debpkg/etc/meshtasticd/available.d/ @@ -66,8 +66,6 @@ jobs: cp bin/meshtasticd.service .debpkg/usr/lib/systemd/system/meshtasticd.service echo "/etc/meshtasticd/config.yaml" > .debpkg/DEBIAN/conffiles chmod +x .debpkg/DEBIAN/conffiles - echo "rm -rf /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/preinst - echo "/usr/share/meshtasticd /usr/share/doc/meshtasticd" > .debpkg/DEBIAN/meshtasticd.links - uses: jiro4989/build-deb-action@v3 with: diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 2a5c6b310..77680cc63 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -155,7 +155,7 @@ Logging: Webserver: # Port: 443 # Port for Webserver & Webservices -# RootPath: /usr/share/meshtasticd/web # Root Dir of WebServer +# RootPath: /usr/share/doc/meshtasticd/web # Root Dir of WebServer General: MaxNodes: 200 From f4b0e19a659314ebb86253264270611de5e95549 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:59:29 +0100 Subject: [PATCH 16/29] Fix another heap leak (#5328) --- src/mesh/ReliableRouter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index a5fa3e585..3e2850bcf 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -176,9 +176,9 @@ bool ReliableRouter::stopRetransmission(GlobalPacketId key) if (old->numRetransmissions < NUM_RETRANSMISSIONS - 1) { // remove the 'original' (identified by originator and packet->id) from the txqueue and free it cancelSending(getFrom(p), p->id); - // now free the pooled copy for retransmission too - packetPool.release(p); } + // now free the pooled copy for retransmission too + packetPool.release(p); auto numErased = pending.erase(key); assert(numErased == 1); return true; From 2ec3958cd868ce405fa4391da35399825d6ee8de Mon Sep 17 00:00:00 2001 From: Matthijs De Smedt <73319561+mdesmedt@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:27:44 -0800 Subject: [PATCH 17/29] Add support for ignoring nodes with `is_ignored` field in NodeInfo (#5319) * Add support for is_ignored bool in NodeInfo * is_ignored is not a boring node either * Clean out metrics and position * Clear the key too --------- Co-authored-by: Ben Meadors --- src/mesh/NodeDB.cpp | 4 ++-- src/mesh/Router.cpp | 7 +++++++ src/mesh/TypeConversions.cpp | 1 + src/modules/AdminModule.cpp | 22 ++++++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index ed6e59ac1..51469ddc0 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1231,12 +1231,12 @@ meshtastic_NodeInfoLite *NodeDB::getOrCreateMeshNode(NodeNum n) int oldestBoringIndex = -1; for (int i = 1; i < numMeshNodes; i++) { // Simply the oldest non-favorite node - if (!meshNodes->at(i).is_favorite && meshNodes->at(i).last_heard < oldest) { + if (!meshNodes->at(i).is_favorite && !meshNodes->at(i).is_ignored && meshNodes->at(i).last_heard < oldest) { oldest = meshNodes->at(i).last_heard; oldestIndex = i; } // The oldest "boring" node - if (!meshNodes->at(i).is_favorite && meshNodes->at(i).user.public_key.size == 0 && + if (!meshNodes->at(i).is_favorite && !meshNodes->at(i).is_ignored && meshNodes->at(i).user.public_key.size == 0 && meshNodes->at(i).last_heard < oldestBoring) { oldestBoring = meshNodes->at(i).last_heard; oldestBoringIndex = i; diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index d2017c257..0663eec98 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -659,6 +659,13 @@ void Router::perhapsHandleReceived(meshtastic_MeshPacket *p) return; } + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(p->from); + if (node != NULL && node->is_ignored) { + LOG_DEBUG("Ignore msg, 0x%x is ignored", p->from); + packetPool.release(p); + return; + } + if (p->from == NODENUM_BROADCAST) { LOG_DEBUG("Ignore msg from broadcast address"); packetPool.release(p); diff --git a/src/mesh/TypeConversions.cpp b/src/mesh/TypeConversions.cpp index 550f87021..5fc6b8a64 100644 --- a/src/mesh/TypeConversions.cpp +++ b/src/mesh/TypeConversions.cpp @@ -12,6 +12,7 @@ meshtastic_NodeInfo TypeConversions::ConvertToNodeInfo(const meshtastic_NodeInfo info.channel = lite->channel; info.via_mqtt = lite->via_mqtt; info.is_favorite = lite->is_favorite; + info.is_ignored = lite->is_ignored; if (lite->has_hops_away) { info.has_hops_away = true; diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 5401e1fdb..2ed053bae 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -283,6 +283,28 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } break; } + case meshtastic_AdminMessage_set_ignored_node_tag: { + LOG_INFO("Client received set_ignored_node command"); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(r->set_ignored_node); + if (node != NULL) { + node->is_ignored = true; + node->has_device_metrics = false; + node->has_position = false; + node->user.public_key.size = 0; + node->user.public_key.bytes[0] = 0; + saveChanges(SEGMENT_DEVICESTATE, false); + } + break; + } + case meshtastic_AdminMessage_remove_ignored_node_tag: { + LOG_INFO("Client received remove_ignored_node command"); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(r->remove_ignored_node); + if (node != NULL) { + node->is_ignored = false; + saveChanges(SEGMENT_DEVICESTATE, false); + } + break; + } case meshtastic_AdminMessage_set_fixed_position_tag: { LOG_INFO("Client received set_fixed_position command"); meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum()); From e866734a25fe811bdb87253da8c8e0879be512f9 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Tue, 12 Nov 2024 22:23:32 +0100 Subject: [PATCH 18/29] Handle repeated packet after potentially canceling previous Tx (#5330) * Revert "Fix sending duplicate packets to PhoneAPI/MQTT (#5315)" This reverts commit 40bc04b521d889e932bcb0d828e44516514e302a. * Handle repeated packet after potentially canceling previous Tx --- src/mesh/FloodingRouter.cpp | 38 +++++++++++++++++++++++++++-------- src/mesh/FloodingRouter.h | 7 ++++++- src/mesh/PacketHistory.cpp | 16 ++------------- src/mesh/PacketHistory.h | 6 +++--- src/mesh/PhoneAPI.cpp | 3 +-- src/mesh/Router.cpp | 12 ++--------- src/mesh/Router.h | 3 +-- src/modules/RoutingModule.cpp | 10 ++------- 8 files changed, 47 insertions(+), 48 deletions(-) diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index d5e00b837..81ea72381 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -29,6 +29,17 @@ bool FloodingRouter::shouldFilterReceived(const meshtastic_MeshPacket *p) if (Router::cancelSending(p->from, p->id)) txRelayCanceled++; } + + /* If the original transmitter is doing retransmissions (hopStart equals hopLimit) for a reliable transmission, e.g., when + the ACK got lost, we will handle the packet again to make sure it gets an ACK to its packet. */ + bool isRepeated = p->hop_start > 0 && p->hop_start == p->hop_limit; + if (isRepeated) { + LOG_DEBUG("Repeated reliable tx"); + if (!perhapsRebroadcast(p) && isToUs(p) && p->want_ack) { + sendAckNak(meshtastic_Routing_Error_NONE, getFrom(p), p->id, p->channel, 0); + } + } + return true; } @@ -41,14 +52,8 @@ bool FloodingRouter::isRebroadcaster() config.device.rebroadcast_mode != meshtastic_Config_DeviceConfig_RebroadcastMode_NONE; } -void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtastic_Routing *c) +bool FloodingRouter::perhapsRebroadcast(const meshtastic_MeshPacket *p) { - bool isAckorReply = (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) && (p->decoded.request_id != 0); - if (isAckorReply && !isToUs(p) && !isBroadcast(p->to)) { - // do not flood direct message that is ACKed or replied to - LOG_DEBUG("Rxd an ACK/reply not for me, cancel rebroadcast"); - Router::cancelSending(p->to, p->decoded.request_id); // cancel rebroadcast for this DM - } if (!isToUs(p) && (p->hop_limit > 0) && !isFromUs(p)) { if (p->id != 0) { if (isRebroadcaster()) { @@ -67,6 +72,8 @@ void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtas // Note: we are careful to resend using the original senders node id // We are careful not to call our hooked version of send() - because we don't want to check this again Router::send(tosend); + + return true; } else { LOG_DEBUG("No rebroadcast: Role = CLIENT_MUTE or Rebroadcast Mode = NONE"); } @@ -74,6 +81,21 @@ void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtas LOG_DEBUG("Ignore 0 id broadcast"); } } + + return false; +} + +void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtastic_Routing *c) +{ + bool isAckorReply = (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) && (p->decoded.request_id != 0); + if (isAckorReply && !isToUs(p) && !isBroadcast(p->to)) { + // do not flood direct message that is ACKed or replied to + LOG_DEBUG("Rxd an ACK/reply not for me, cancel rebroadcast"); + Router::cancelSending(p->to, p->decoded.request_id); // cancel rebroadcast for this DM + } + + perhapsRebroadcast(p); + // handle the packet as normal Router::sniffReceived(p, c); -} +} \ No newline at end of file diff --git a/src/mesh/FloodingRouter.h b/src/mesh/FloodingRouter.h index e398f8d58..52614f391 100644 --- a/src/mesh/FloodingRouter.h +++ b/src/mesh/FloodingRouter.h @@ -1,5 +1,6 @@ #pragma once +#include "PacketHistory.h" #include "Router.h" /** @@ -25,11 +26,15 @@ Any entries in recentBroadcasts that are older than X seconds (longer than the max time a flood can take) will be discarded. */ -class FloodingRouter : public Router +class FloodingRouter : public Router, protected PacketHistory { private: bool isRebroadcaster(); + /** Check if we should rebroadcast this packet, and do so if needed + * @return true if rebroadcasted */ + bool perhapsRebroadcast(const meshtastic_MeshPacket *p); + public: /** * Constructor diff --git a/src/mesh/PacketHistory.cpp b/src/mesh/PacketHistory.cpp index b29d67d66..6eb4b6ea1 100644 --- a/src/mesh/PacketHistory.cpp +++ b/src/mesh/PacketHistory.cpp @@ -16,7 +16,7 @@ PacketHistory::PacketHistory() /** * Update recentBroadcasts and return true if we have already seen this packet */ -bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpdate, bool *isRepeated) +bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpdate) { if (p->id == 0) { LOG_DEBUG("Ignore message with zero id"); @@ -38,18 +38,6 @@ bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpd seenRecently = false; } - /* If the original transmitter is doing retransmissions (hopStart equals hopLimit) for a reliable transmission, e.g., when the - ACK got lost, we will handle the packet again to make sure it gets an ACK/response to its packet. */ - if (seenRecently && p->hop_start > 0 && p->hop_start == p->hop_limit) { - if (withUpdate) - LOG_DEBUG("Repeated reliable tx"); - - if (isRepeated) - *isRepeated = true; - - seenRecently = false; - } - if (seenRecently) { LOG_DEBUG("Found existing packet record for fr=0x%x,to=0x%x,id=0x%x", p->from, p->to, p->id); } @@ -59,7 +47,7 @@ bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpd recentPackets.erase(found); // as unsorted_set::iterator is const (can't update timestamp - so re-insert..) } recentPackets.insert(r); - LOG_DEBUG("Add packet record fr=0x%x, id=0x%x", p->from, p->id); + printPacket("Add packet record", p); } // Capacity is reerved, so only purge expired packets if recentPackets fills past 90% capacity diff --git a/src/mesh/PacketHistory.h b/src/mesh/PacketHistory.h index 1f29155fd..89d237a02 100644 --- a/src/mesh/PacketHistory.h +++ b/src/mesh/PacketHistory.h @@ -1,6 +1,6 @@ #pragma once -#include "NodeDB.h" +#include "Router.h" #include /// We clear our old flood record 10 minutes after we see the last of it @@ -41,5 +41,5 @@ class PacketHistory * * @param withUpdate if true and not found we add an entry to recentPackets */ - bool wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpdate = true, bool *isRepeated = nullptr); -}; \ No newline at end of file + bool wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpdate = true); +}; diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index f42c0b59f..20421e73e 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -12,7 +12,6 @@ #include "PhoneAPI.h" #include "PowerFSM.h" #include "RadioInterface.h" -#include "Router.h" #include "TypeConversions.h" #include "main.h" #include "xmodem.h" @@ -657,4 +656,4 @@ int PhoneAPI::onNotify(uint32_t newValue) } return timeout ? -1 : 0; // If we timed out, MeshService should stop iterating through observers as we just removed one -} \ No newline at end of file +} diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 0663eec98..7b792db30 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -622,17 +622,9 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) // us (because we would be able to decrypt it) if (!decoded && moduleConfig.mqtt.encryption_enabled && p->channel == 0x00 && !isBroadcast(p->to) && !isToUs(p)) p_encrypted->pki_encrypted = true; - // After potentially altering it, publish received message to MQTT if we're not the original transmitter of the packet - if ((decoded || p_encrypted->pki_encrypted) && moduleConfig.mqtt.enabled && !isFromUs(p) && mqtt) { - // Check if it wasn't already seen, then we don't need to handle it again - bool isRepeated = false; - bool *rptr = &isRepeated; - wasSeenRecently(p, false, rptr); - if (!isRepeated) { - mqtt->onSend(*p_encrypted, *p, p->channel); - } - } + if ((decoded || p_encrypted->pki_encrypted) && moduleConfig.mqtt.enabled && !isFromUs(p) && mqtt) + mqtt->onSend(*p_encrypted, *p, p->channel); #endif } diff --git a/src/mesh/Router.h b/src/mesh/Router.h index 14ce4810b..da44d67df 100644 --- a/src/mesh/Router.h +++ b/src/mesh/Router.h @@ -4,7 +4,6 @@ #include "MemoryPool.h" #include "MeshTypes.h" #include "Observer.h" -#include "PacketHistory.h" #include "PointerQueue.h" #include "RadioInterface.h" #include "concurrency/OSThread.h" @@ -12,7 +11,7 @@ /** * A mesh aware router that supports multiple interfaces. */ -class Router : protected concurrency::OSThread, protected PacketHistory +class Router : protected concurrency::OSThread { private: /// Packets which have just arrived from the radio, ready to be processed by this service and possibly diff --git a/src/modules/RoutingModule.cpp b/src/modules/RoutingModule.cpp index 5423318a4..a501e319b 100644 --- a/src/modules/RoutingModule.cpp +++ b/src/modules/RoutingModule.cpp @@ -28,14 +28,8 @@ bool RoutingModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mesh // FIXME - move this to a non promsicious PhoneAPI module? // Note: we are careful not to send back packets that started with the phone back to the phone if ((isBroadcast(mp.to) || isToUs(&mp)) && (mp.from != 0)) { - // Check if it wasn't already seen, then we don't need to handle it again - bool isRepeated = false; - bool *rptr = &isRepeated; - router->wasSeenRecently(&mp, false, rptr); - if (!isRepeated) { - printPacket("Delivering rx packet", &mp); - service->handleFromRadio(&mp); - } + printPacket("Delivering rx packet", &mp); + service->handleFromRadio(&mp); } return false; // Let others look at this message also if they want From 8fcfe7f28bc0b9ced86e63da4e588f471ad66ec9 Mon Sep 17 00:00:00 2001 From: Blake-Latchford Date: Wed, 13 Nov 2024 05:13:55 -0500 Subject: [PATCH 19/29] Read voltage during init fixes #5276 (#5332) Power::readPowerStatus is called on startup, but AnalogBatteryLevel::getBattVoltage skips the read because 5 seconds have not elapsed since last_read_time_ms, which is initialized to zero. `batMv=3100` is reported because AnalogBatteryLevel::last_read_value is initialized as: ``` float last_read_value = (OCV[NUM_OCV_POINTS - 1] * NUM_CELLS); ``` --- src/Power.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Power.cpp b/src/Power.cpp index 4e5cf0f2c..d66214315 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -271,7 +271,7 @@ class AnalogBatteryLevel : public HasBatteryLevel config.power.adc_multiplier_override > 0 ? config.power.adc_multiplier_override : ADC_MULTIPLIER; // Do not call analogRead() often. const uint32_t min_read_interval = 5000; - if (!Throttle::isWithinTimespanMs(last_read_time_ms, min_read_interval)) { + if (!initial_read_done || !Throttle::isWithinTimespanMs(last_read_time_ms, min_read_interval)) { last_read_time_ms = millis(); uint32_t raw = 0; From ac804818de41e66c991969bfbde3d24b18c4250e Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 13 Nov 2024 05:39:15 -0600 Subject: [PATCH 20/29] Only allow 30 seconds minimum for power.on_battery_shutdown_after_secs (#5337) --- src/modules/AdminModule.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 2ed053bae..c81b6ede4 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -526,6 +526,11 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) requiresReboot = false; } config.power = c.payload_variant.power; + if (c.payload_variant.power.on_battery_shutdown_after_secs > 0 && + c.payload_variant.power.on_battery_shutdown_after_secs < 30) { + LOG_WARN("Tried to set on_battery_shutdown_after_secs too low, set to min 30 seconds"); + config.power.on_battery_shutdown_after_secs = 30; + } break; case meshtastic_Config_network_tag: LOG_INFO("Set config: WiFi"); From ea150c32f3826cfdf42d8f2498a826438bd4a9ae Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 13 Nov 2024 07:43:05 -0600 Subject: [PATCH 21/29] Decrease max nodes for NRF52 to 80 as workaround to prevent FS blowouts (#5338) * Decrease max nodes for NRF52 to 80 as workaround to prevent FS blowouts * Don't redefine * Newline --- src/mesh/mesh-pb-constants.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mesh/mesh-pb-constants.h b/src/mesh/mesh-pb-constants.h index f91c48560..539fecb3f 100644 --- a/src/mesh/mesh-pb-constants.h +++ b/src/mesh/mesh-pb-constants.h @@ -20,8 +20,12 @@ /// max number of nodes allowed in the mesh #ifndef MAX_NUM_NODES +#ifdef ARCH_NRF52 +#define MAX_NUM_NODES 80 +#else #define MAX_NUM_NODES 100 #endif +#endif /// Max number of channels allowed #define MAX_NUM_CHANNELS (member_size(meshtastic_ChannelFile, channels) / member_size(meshtastic_ChannelFile, channels[0])) From 3a66c738bdf869126f9def2c4c6d31d6289c1c83 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 13 Nov 2024 10:21:55 -0600 Subject: [PATCH 22/29] =?UTF-8?q?Revert=20"Decrease=20max=20nodes=20for=20?= =?UTF-8?q?NRF52=20to=2080=20as=20workaround=20to=20prevent=20FS=20blowou?= =?UTF-8?q?=E2=80=A6"=20(#5340)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit ea150c32f3826cfdf42d8f2498a826438bd4a9ae. --- src/mesh/mesh-pb-constants.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/mesh/mesh-pb-constants.h b/src/mesh/mesh-pb-constants.h index 539fecb3f..f91c48560 100644 --- a/src/mesh/mesh-pb-constants.h +++ b/src/mesh/mesh-pb-constants.h @@ -20,12 +20,8 @@ /// max number of nodes allowed in the mesh #ifndef MAX_NUM_NODES -#ifdef ARCH_NRF52 -#define MAX_NUM_NODES 80 -#else #define MAX_NUM_NODES 100 #endif -#endif /// Max number of channels allowed #define MAX_NUM_CHANNELS (member_size(meshtastic_ChannelFile, channels) / member_size(meshtastic_ChannelFile, channels[0])) From 73430cb582c866580660c70ab1df67dac2a73724 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 13 Nov 2024 11:00:23 -0600 Subject: [PATCH 23/29] Update version.properties (#5343) --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 91c1f4823..091ebde9e 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 5 -build = 12 +build = 13 From 528e177c62198f172d688af08a5525a4f6fbb640 Mon Sep 17 00:00:00 2001 From: Mictronics Date: Wed, 13 Nov 2024 20:18:38 +0100 Subject: [PATCH 24/29] Remove log spam when reading INA sensor. (#5345) * Fix LED pinout for T-Echo board marked v1.0, date 2021-6-28 * Merge PR #420 * Fixed double and missing Default class. * Use correct format specifier and fixed typo. * Removed duplicate code. * Fix error: #if with no expression * Fix warning: extra tokens at end of #endif directive. * Fix antenna switching logic. Complementary-pin control logic is required on the rp2040-lora board. * Fix deprecated macros. * Set RP2040 in dormant mode when deep sleep is triggered. * Fix array out of bounds read. * Admin key count needs to be set otherwise the key will be zero loaded after reset. * Don't reset the admin key size when loading defaults. Preserve an existing key in config if possible. * Remove log spam when reading INA voltage sensor. --------- Co-authored-by: Ben Meadors --- src/Power.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Power.cpp b/src/Power.cpp index d66214315..a354b74e2 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -251,7 +251,6 @@ class AnalogBatteryLevel : public HasBatteryLevel #if HAS_TELEMETRY && !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && !defined(HAS_PMU) && \ !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR if (hasINA()) { - LOG_DEBUG("Use INA on I2C addr 0x%x for device battery voltage", config.power.device_battery_ina_address); return getINAVoltage(); } #endif From f4908fadd69be8849b2260bfeb85cdc9d76d5e8c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 13:18:57 -0600 Subject: [PATCH 25/29] [create-pull-request] automated change (#5344) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 091ebde9e..bed14bad5 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 5 -build = 13 +build = 14 From ec6949fdc09040cf3ff138e678b0955d75d11d25 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 13 Nov 2024 18:44:35 -0600 Subject: [PATCH 26/29] Migrate NRF52 devices max nodes down to 80 for now to prevent brownouts (#5346) --- src/mesh/NodeDB.cpp | 6 +++++- src/mesh/mesh-pb-constants.h | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 51469ddc0..1275e80e7 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -794,7 +794,7 @@ void NodeDB::loadFromDisk() // disk we will still factoryReset to restore things. // static DeviceState scratch; We no longer read into a tempbuf because this structure is 15KB of valuable RAM - auto state = loadProto(prefFileName, sizeof(meshtastic_DeviceState) + MAX_NUM_NODES * sizeof(meshtastic_NodeInfo), + auto state = loadProto(prefFileName, sizeof(meshtastic_DeviceState) + MAX_NUM_NODES_FS * sizeof(meshtastic_NodeInfo), sizeof(meshtastic_DeviceState), &meshtastic_DeviceState_msg, &devicestate); // See https://github.com/meshtastic/firmware/issues/4184#issuecomment-2269390786 @@ -813,6 +813,10 @@ void NodeDB::loadFromDisk() meshNodes = &devicestate.node_db_lite; numMeshNodes = devicestate.node_db_lite.size(); } + if (numMeshNodes > MAX_NUM_NODES) { + LOG_WARN("Node count %d exceeds MAX_NUM_NODES %d, truncating", numMeshNodes, MAX_NUM_NODES); + numMeshNodes = MAX_NUM_NODES; + } meshNodes->resize(MAX_NUM_NODES); state = loadProto(configFileName, meshtastic_LocalConfig_size, sizeof(meshtastic_LocalConfig), &meshtastic_LocalConfig_msg, diff --git a/src/mesh/mesh-pb-constants.h b/src/mesh/mesh-pb-constants.h index f91c48560..a055804d9 100644 --- a/src/mesh/mesh-pb-constants.h +++ b/src/mesh/mesh-pb-constants.h @@ -1,6 +1,7 @@ #pragma once #include +#include "architecture.h" #include "mesh/generated/meshtastic/admin.pb.h" #include "mesh/generated/meshtastic/deviceonly.pb.h" #include "mesh/generated/meshtastic/localonly.pb.h" @@ -20,8 +21,14 @@ /// max number of nodes allowed in the mesh #ifndef MAX_NUM_NODES +#ifdef ARCH_NRF52 +#define MAX_NUM_NODES 80 +#else #define MAX_NUM_NODES 100 #endif +#endif + +#define MAX_NUM_NODES_FS 100 /// Max number of channels allowed #define MAX_NUM_CHANNELS (member_size(meshtastic_ChannelFile, channels) / member_size(meshtastic_ChannelFile, channels[0])) From 295278bb126c7e7d8319d786a71d0f4aef82eda3 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 13 Nov 2024 18:47:46 -0600 Subject: [PATCH 27/29] Update version.properties --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index bed14bad5..091ebde9e 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 5 -build = 14 +build = 13 From 81172574a4f0c6fba779959bb9ab7a7b5375ec02 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 04:54:56 -0600 Subject: [PATCH 28/29] [create-pull-request] automated change (#5347) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 091ebde9e..bed14bad5 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 5 -build = 13 +build = 14 From d4d89447bd417895b32e9a264bb76a22065b577f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gjels=C3=B8?= <36234524+gjelsoe@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:56:22 +0100 Subject: [PATCH 29/29] Adds fixed GPS, BUTTON_PIN and BLE code to userPrefs.h (#5341) * userPrefs.h Added FixedGPS Added Fixed Bluetooth PIN * Update NodeDB.cpp Removed some un-used LOG_INFO * Added BUTTON_PIN * Trunk * Variable re-naming. --------- Co-authored-by: Ben Meadors --- src/ButtonThread.cpp | 33 +++++++++++++++++++++++++++------ src/ButtonThread.h | 2 +- src/mesh/NodeDB.cpp | 30 ++++++++++++++++++++++++++++++ userPrefs.h | 21 +++++++++++++++++++++ 4 files changed, 79 insertions(+), 7 deletions(-) diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp index 0ea1309cc..238359952 100644 --- a/src/ButtonThread.cpp +++ b/src/ButtonThread.cpp @@ -1,4 +1,5 @@ #include "ButtonThread.h" +#include "../userPrefs.h" #include "configuration.h" #if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" @@ -26,12 +27,12 @@ using namespace concurrency; ButtonThread *buttonThread; // Declared extern in header volatile ButtonThread::ButtonEventType ButtonThread::btnEvent = ButtonThread::BUTTON_EVENT_NONE; -#if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) +#if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) || defined(USERPREFS_BUTTON_PIN) OneButton ButtonThread::userButton; // Get reference to static member #endif ButtonThread::ButtonThread() : OSThread("Button") { -#if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) +#if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) || defined(USERPREFS_BUTTON_PIN) #if defined(ARCH_PORTDUINO) if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) { @@ -39,7 +40,12 @@ ButtonThread::ButtonThread() : OSThread("Button") LOG_DEBUG("Use GPIO%02d for button", settingsMap[user]); } #elif defined(BUTTON_PIN) - int pin = config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN; // Resolved button pin +#if !defined(USERPREFS_BUTTON_PIN) + int pin = config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN; // Resolved button pin +#endif +#ifdef USERPREFS_BUTTON_PIN + int pin = config.device.button_gpio ? config.device.button_gpio : USERPREFS_BUTTON_PIN; // Resolved button pin +#endif #if defined(HELTEC_CAPSULE_SENSOR_V3) this->userButton = OneButton(pin, false, false); #elif defined(BUTTON_ACTIVE_LOW) @@ -59,7 +65,7 @@ ButtonThread::ButtonThread() : OSThread("Button") #endif #endif -#if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) +#if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) || defined(USERPREFS_BUTTON_PIN) userButton.attachClick(userButtonPressed); userButton.setClickMs(BUTTON_CLICK_MS); userButton.setPressMs(BUTTON_LONGPRESS_MS); @@ -102,7 +108,7 @@ int32_t ButtonThread::runOnce() // If the button is pressed we suppress CPU sleep until release canSleep = true; // Assume we should not keep the board awake -#if defined(BUTTON_PIN) +#if defined(BUTTON_PIN) || defined(USERPREFS_BUTTON_PIN) userButton.tick(); canSleep &= userButton.isIdle(); #elif defined(ARCH_PORTDUINO) @@ -130,7 +136,12 @@ int32_t ButtonThread::runOnce() return 50; } #ifdef BUTTON_PIN +#if !defined(USERPREFS_BUTTON_PIN) if (((config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN) != +#endif +#if defined(USERPREFS_BUTTON_PIN) + if (((config.device.button_gpio ? config.device.button_gpio : USERPREFS_BUTTON_PIN) != +#endif moduleConfig.canned_message.inputbroker_pin_press) || !(moduleConfig.canned_message.updown1_enabled || moduleConfig.canned_message.rotary1_enabled) || !moduleConfig.canned_message.enabled) { @@ -244,7 +255,12 @@ void ButtonThread::attachButtonInterrupts() #elif defined(BUTTON_PIN) // Interrupt for user button, during normal use. Improves responsiveness. attachInterrupt( +#if !defined(USERPREFS_BUTTON_PIN) config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN, +#endif +#if defined(USERPREFS_BUTTON_PIN) + config.device.button_gpio ? config.device.button_gpio : USERPREFS_BUTTON_PIN, +#endif []() { ButtonThread::userButton.tick(); runASAP = true; @@ -273,8 +289,13 @@ void ButtonThread::detachButtonInterrupts() if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) detachInterrupt(settingsMap[user]); #elif defined(BUTTON_PIN) +#if !defined(USERPREFS_BUTTON_PIN) detachInterrupt(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN); #endif +#if defined(USERPREFS_BUTTON_PIN) + detachInterrupt(config.device.button_gpio ? config.device.button_gpio : USERPREFS_BUTTON_PIN); +#endif +#endif #ifdef BUTTON_PIN_ALT detachInterrupt(BUTTON_PIN_ALT); @@ -315,7 +336,7 @@ void ButtonThread::userButtonMultiPressed(void *callerThread) // Non-static method, runs during callback. Grabs info while still valid void ButtonThread::storeClickCount() { -#ifdef BUTTON_PIN +#if defined(BUTTON_PIN) || defined(USERPREFS_BUTTON_PIN) multipressClickCount = userButton.getNumberClicks(); #endif } diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 9cd7b3dac..a01a1718f 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -38,7 +38,7 @@ class ButtonThread : public concurrency::OSThread void storeClickCount(); private: -#if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) +#if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) || defined(USERPREFS_BUTTON_PIN) static OneButton userButton; // Static - accessed from an interrupt #endif #ifdef BUTTON_PIN_ALT diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 1275e80e7..7f051ae16 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -246,6 +246,31 @@ NodeDB::NodeDB() config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED; config.position.gps_enabled = 0; } +#ifdef USERPREFS_FIXED_GPS + if (myNodeInfo.reboot_count == 1) { // Check if First boot ever or after Factory Reset. + meshtastic_Position fixedGPS = meshtastic_Position_init_default; +#ifdef USERPREFS_FIXED_GPS_LAT + fixedGPS.latitude_i = (int32_t)(USERPREFS_FIXED_GPS_LAT * 1e7); + fixedGPS.has_latitude_i = true; +#endif +#ifdef USERPREFS_FIXED_GPS_LON + fixedGPS.longitude_i = (int32_t)(USERPREFS_FIXED_GPS_LON * 1e7); + fixedGPS.has_longitude_i = true; +#endif +#ifdef USERPREFS_FIXED_GPS_ALT + fixedGPS.altitude = USERPREFS_FIXED_GPS_ALT; + fixedGPS.has_altitude = true; +#endif +#if defined(USERPREFS_FIXED_GPS_LAT) && defined(USERPREFS_FIXED_GPS_LON) + fixedGPS.location_source = meshtastic_Position_LocSource_LOC_MANUAL; + config.has_position = true; + info->has_position = true; + info->position = TypeConversions::ConvertToPositionLite(fixedGPS); + nodeDB->setLocalPosition(fixedGPS); + config.position.fixed_position = true; +#endif + } +#endif saveToDisk(saveWhat); } @@ -438,8 +463,13 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) #else bool hasScreen = screen_found.port != ScanI2C::I2CPort::NO_I2C; #endif +#ifdef USERPREFS_FIXED_BLUETOOTH + config.bluetooth.fixed_pin = USERPREFS_FIXED_BLUETOOTH; + config.bluetooth.mode = meshtastic_Config_BluetoothConfig_PairingMode_FIXED_PIN; +#else config.bluetooth.mode = hasScreen ? meshtastic_Config_BluetoothConfig_PairingMode_RANDOM_PIN : meshtastic_Config_BluetoothConfig_PairingMode_FIXED_PIN; +#endif // for backward compat, default position flags are ALT+MSL config.position.position_flags = (meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE | meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE_MSL | diff --git a/userPrefs.h b/userPrefs.h index 58a44fef0..c105e6b52 100644 --- a/userPrefs.h +++ b/userPrefs.h @@ -74,4 +74,25 @@ static unsigned char USERPREFS_ADMIN_KEY[] = {0xcd, 0xc0, 0xb4, 0x3c, 0x53, 0x24 0x0c, 0x0d, 0xec, 0x85, 0x5a, 0x4c, 0xf6, 0x1a, 0x96, 0x04, 0x1a, 0x3e, 0xfc, 0xbb, 0x8e, 0x33, 0x71, 0xe5, 0xfc, 0xff, 0x3c}; */ + +/* + * USERPREF_FIXED_GPS_LAT and USERPREF_FIXED_GPS_LON must be set, USERPREF_FIXED_GPS_ALT is optional + * + * Fixed GPS is Eiffel Tower, Paris, France + */ +// #define USERPREFS_FIXED_GPS +// #define USERPREFS_FIXED_GPS_LAT 48.85873920 +// #define USERPREFS_FIXED_GPS_LON 2.294508368 +// #define USERPREFS_FIXED_GPS_ALT 0 + +/* + * Set Fixed Bluetooth paring code + */ +// #define USERPREFS_FIXED_BLUETOOTH 121212 + +/* + * Will overwrite BUTTON_PIN if set + */ +// #define USERPREFS_BUTTON_PIN 36 + #endif \ No newline at end of file