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 01/13] 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 02/13] [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 03/13] 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 04/13] 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 05/13] 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 06/13] 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 07/13] 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 08/13] 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 09/13] 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 10/13] 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 11/13] 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 dd2a4a31213b228822771b0e682ff45052341663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Mon, 11 Nov 2024 23:40:58 +0100 Subject: [PATCH 12/13] WIP. Needs PA and GPIO verification --- .../radiomaster_nomad_gemini/platformio.ini | 20 ++++++++ variants/radiomaster_nomad_gemini/rfswitch.h | 21 ++++++++ variants/radiomaster_nomad_gemini/variant.h | 51 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 variants/radiomaster_nomad_gemini/platformio.ini create mode 100644 variants/radiomaster_nomad_gemini/rfswitch.h create mode 100644 variants/radiomaster_nomad_gemini/variant.h diff --git a/variants/radiomaster_nomad_gemini/platformio.ini b/variants/radiomaster_nomad_gemini/platformio.ini new file mode 100644 index 000000000..96ea42e50 --- /dev/null +++ b/variants/radiomaster_nomad_gemini/platformio.ini @@ -0,0 +1,20 @@ +[env:radiomaster_nomad_gemini] +extends = esp32_base +board = esp32doit-devkit-v1 +build_flags = + ${esp32_base.build_flags} + -DRADIOMASTER_NOMAD_GEMINI + -DPRIVATE_HW + -DVTABLES_IN_FLASH=1 + -DCONFIG_DISABLE_HAL_LOCKS=1 + -O2 + -Ivariants/radiomaster_nomad_gemini + -DMESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR=1 + -DMESHTASTIC_EXCLUDE_I2C=1 + -DRADIOLIB_EXCLUDE_SX128X=1 + -DRADIOLIB_EXCLUDE_SX127X=1 + -DRADIOLIB_EXCLUDE_SX126X=1 +board_build.f_cpu = 240000000L +upload_protocol = esptool +lib_deps = + ${esp32_base.lib_deps} diff --git a/variants/radiomaster_nomad_gemini/rfswitch.h b/variants/radiomaster_nomad_gemini/rfswitch.h new file mode 100644 index 000000000..a84f62fde --- /dev/null +++ b/variants/radiomaster_nomad_gemini/rfswitch.h @@ -0,0 +1,21 @@ +#include "RadioLib.h" + +static const uint32_t rfswitch_dio_pins[] = {RADIOLIB_LR11X0_DIO5, RADIOLIB_LR11X0_DIO6, RADIOLIB_LR11X0_DIO7, + RADIOLIB_LR11X0_DIO8, RADIOLIB_NC}; + +static const Module::RfSwitchMode_t rfswitch_table[] = { + // mode DIO5 DIO6 DIO7 DIO8 + {LR11x0::MODE_STBY, {LOW, LOW, LOW, LOW}}, {LR11x0::MODE_RX, {LOW, LOW, HIGH, LOW}}, + {LR11x0::MODE_TX, {LOW, LOW, LOW, HIGH}}, {LR11x0::MODE_TX_HP, {LOW, LOW, LOW, HIGH}}, + {LR11x0::MODE_TX_HF, {LOW, HIGH, LOW, LOW}}, {LR11x0::MODE_GNSS, {LOW, LOW, LOW, LOW}}, + {LR11x0::MODE_WIFI, {LOW, LOW, LOW, LOW}}, END_OF_MODE_TABLE, +}; + +/* + +DIO5: RXEN 2.4GHz +DIO6: TXEN 2.4GHz +DIO7: RXEN 900MHz +DIO8: TXEN 900MHz + +*/ \ No newline at end of file diff --git a/variants/radiomaster_nomad_gemini/variant.h b/variants/radiomaster_nomad_gemini/variant.h new file mode 100644 index 000000000..b403db2d1 --- /dev/null +++ b/variants/radiomaster_nomad_gemini/variant.h @@ -0,0 +1,51 @@ +#define HAS_SCREEN 0 +#define HAS_WIRE 0 +#define HAS_GPS 0 +#undef GPS_RX_PIN +#undef GPS_TX_PIN + +#define PIN_SPI_MISO 33 +#define PIN_SPI_MOSI 32 +#define PIN_SPI_SCK 25 +#define PIN_SPI_NSS 27 + +#define LORA_RESET 15 +#define LORA_DIO1 37 +#define LORA_DIO2 36 +#define LORA_SCK PIN_SPI_SCK +#define LORA_MISO PIN_SPI_MISO +#define LORA_MOSI PIN_SPI_MOSI +#define LORA_CS PIN_SPI_NSS + +// supported modules list +#define USE_LR1121 + +#define LR1121_IRQ_PIN LORA_DIO1 +#define LR1121_NRESET_PIN LORA_RESET +#define LR1121_BUSY_PIN LORA_DIO2 +#define LR1121_SPI_NSS_PIN LORA_CS +#define LR1121_SPI_SCK_PIN LORA_SCK +#define LR1121_SPI_MOSI_PIN LORA_MOSI +#define LR1121_SPI_MISO_PIN LORA_MISO + +// #define LR11X0_DIO3_TCXO_VOLTAGE 1.6 +#define LR11X0_DIO_AS_RF_SWITCH + +#define HAS_NEOPIXEL // Enable the use of neopixels +#define NEOPIXEL_COUNT 2 // How many neopixels are connected +#define NEOPIXEL_DATA 22 // GPIO pin used to send data to the neopixels +#define NEOPIXEL_TYPE (NEO_GRB + NEO_KHZ800) // Type of neopixels in use +#define ENABLE_AMBIENTLIGHTING // Turn on Ambient Lighting + +#define BUTTON_PIN 34 +#define BUTTON_NEED_PULLUP + +#undef EXT_NOTIFY_OUT + +#define BAT_MEASURE_ADC_UNIT +#define BATTERY_PIN 26 +#define ADC_CHANNEL ADC2_GPIO26_CHANNEL +#define BATTERY_SENSE_SAMPLES 30 + +// ratio of voltage divider = 2.0 (R42=100k, R43=100k) +#define ADC_MULTIPLIER 2 From 1898aec281e9cce74dd29294bf31144eaea0e01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 12 Nov 2024 16:53:36 +0100 Subject: [PATCH 13/13] Update Radiomaster target --- platformio.ini | 1 + src/main.cpp | 32 +++++++++++++++--- src/main.h | 2 ++ src/mesh/LR11x0Interface.cpp | 16 +++++++++ src/mesh/LR11x0Interface.h | 2 ++ src/mesh/RF95Interface.cpp | 10 ++---- src/mesh/RadioLibInterface.cpp | 33 +++++++++++++++++++ src/mesh/RadioLibInterface.h | 3 ++ src/mesh/SX126xInterface.cpp | 2 ++ src/mesh/SX128xInterface.cpp | 5 +-- src/modules/AdminModule.cpp | 14 ++++++-- variants/betafpv_2400_tx_micro/variant.h | 2 +- variants/radiomaster_900_bandit/variant.h | 3 +- .../radiomaster_900_bandit_nano/variant.h | 2 +- variants/radiomaster_nomad_gemini/variant.h | 20 +++++++---- 15 files changed, 118 insertions(+), 29 deletions(-) diff --git a/platformio.ini b/platformio.ini index f7c73c190..42689e41c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -59,6 +59,7 @@ build_flags = -Wno-missing-field-initializers -DUSE_THREAD_NAMES -DTINYGPS_OPTION_NO_CUSTOM_FIELDS -DPB_ENABLE_MALLOC=1 + -DRADIOLIB_LOW_LEVEL=1 -DRADIOLIB_EXCLUDE_CC1101=1 -DRADIOLIB_EXCLUDE_NRF24=1 -DRADIOLIB_EXCLUDE_RF69=1 diff --git a/src/main.cpp b/src/main.cpp index 97a64a378..203075da0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -170,6 +170,8 @@ bool pauseBluetoothLogging = false; bool pmu_found; +uint8_t pa_fan_percentage = 50; + #if !MESHTASTIC_EXCLUDE_I2C // Array map of sensor types with i2c address and wire as we'll find in the i2c scan std::pair nodeTelemetrySensorsMap[_meshtastic_TelemetrySensorType_MAX + 1] = {}; @@ -1086,16 +1088,36 @@ void setup() mqttInit(); #endif -#ifdef RF95_FAN_EN - // Ability to disable FAN if PIN has been set with RF95_FAN_EN. +#ifdef RADIO_FAN_EN + // Ability to disable FAN if PIN has been set with RADIO_FAN_EN. // Make sure LoRa has been started before disabling FAN. - if (config.lora.pa_fan_disabled) - digitalWrite(RF95_FAN_EN, LOW ^ 0); +#ifdef RADIO_FAN_PWM +#if defined(ARCH_ESP32) + // Set up PWM at Channel 1 at 25KHz, using 8-bit resolution + // Turn ON/OFF fan to the specified value if enabled by config. + // code by https://github.com/gjelsoe/ + if (ledcSetup(1, 25000, 8)) { + ledcAttachPin(RADIO_FAN_EN, 1); + LOG_INFO("PWM init C1 P%d\n", RADIO_FAN_EN); + // Set PWM duty cycle based on fan disabled state + ledcWrite(1, config.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55)); + } else { + LOG_WARN("PWM init fail P%d\n", RADIO_FAN_EN); + } +#elif defined(ARCH_NRF52) + pinMode(RF95_FAN_PWM, OUTPUT); + analogWrite(RF95_FAN_PWM, config.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55)); +#endif +#else + // Set up as ON/OFF switch of fan + pinMode(RF95_FAN_EN, OUTPUT); + digitalWrite(RADIO_FAN_EN, LOW ^ 0); +#endif #endif #ifndef ARCH_PORTDUINO - // Initialize Wifi + // Initialize Wifi #if HAS_WIFI initWifi(); #endif diff --git a/src/main.h b/src/main.h index 5722f7cf0..33e0e2126 100644 --- a/src/main.h +++ b/src/main.h @@ -75,6 +75,8 @@ extern uint32_t shutdownAtMsec; extern uint32_t serialSinceMsec; +extern uint8_t pa_fan_percentage; + // If a thread does something that might need for it to be rescheduled ASAP it can set this flag // This will suppress the current delay and instead try to run ASAP. extern bool runASAP; diff --git a/src/mesh/LR11x0Interface.cpp b/src/mesh/LR11x0Interface.cpp index 30ef8f9af..12a83b38b 100644 --- a/src/mesh/LR11x0Interface.cpp +++ b/src/mesh/LR11x0Interface.cpp @@ -3,6 +3,7 @@ #include "Throttle.h" #include "configuration.h" #include "error.h" +#include "main.h" #include "mesh/NodeDB.h" #ifdef LR11X0_DIO_AS_RF_SWITCH #include "rfswitch.h" @@ -48,6 +49,8 @@ template bool LR11x0Interface::init() digitalWrite(LR11X0_POWER_EN, HIGH); #endif + enableFan(); + // FIXME: correct logic to default to not using TCXO if no voltage is specified for LR11x0_DIO3_TCXO_VOLTAGE #if !defined(LR11X0_DIO3_TCXO_VOLTAGE) float tcxoVoltage = @@ -275,6 +278,19 @@ template bool LR11x0Interface::isActivelyReceiving() RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED); } +template void LR11x0Interface::regulateFan() +{ + float *pa_temp = 0; + lora.getTemp(pa_temp); + if (*pa_temp > 40) { + pa_fan_percentage = max(pa_fan_percentage + 1, 100); + enableFan(); + } else { + pa_fan_percentage = max(pa_fan_percentage - 1, 100); + enableFan(); + } +} + template bool LR11x0Interface::sleep() { // \todo Display actual typename of the adapter, not just `LR11x0` diff --git a/src/mesh/LR11x0Interface.h b/src/mesh/LR11x0Interface.h index 4829ddc1d..355acf7f6 100644 --- a/src/mesh/LR11x0Interface.h +++ b/src/mesh/LR11x0Interface.h @@ -65,5 +65,7 @@ template class LR11x0Interface : public RadioLibInterface virtual void addReceiveMetadata(meshtastic_MeshPacket *mp) override; virtual void setStandby() override; + + void regulateFan(); }; #endif \ No newline at end of file diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index 9ef045099..fbd1513d7 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -154,10 +154,7 @@ bool RF95Interface::init() digitalWrite(RF95_TXEN, 0); #endif -#ifdef RF95_FAN_EN - pinMode(RF95_FAN_EN, OUTPUT); - digitalWrite(RF95_FAN_EN, 1); -#endif + enableFan(); #ifdef RF95_RXEN pinMode(RF95_RXEN, OUTPUT); @@ -330,10 +327,7 @@ bool RF95Interface::sleep() // put chipset into sleep mode setStandby(); // First cancel any active receiving/sending lora->sleep(); - -#ifdef RF95_FAN_EN - digitalWrite(RF95_FAN_EN, 0); -#endif + disableFan(); return true; } diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 23ef3d6f1..a67114e12 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -497,4 +497,37 @@ bool RadioLibInterface::startSend(meshtastic_MeshPacket *txp) return res == RADIOLIB_ERR_NONE; } +} + +void RadioLibInterface::enableFan() +{ +#ifdef RADIO_FAN_EN + +#ifdef RADIO_FAN_PWM +#if defined(ARCH_ESP32) + ledcWrite(1, config.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55)); +#elif defined(ARCH_NRF52) + analogWrite(RADIO_FAN_EN, config.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55)); +#endif +#else + pinMode(RADIO_FAN_EN, OUTPUT); + digitalWrite(RADIO_FAN_EN, 1); +#endif +#endif +} + +void RadioLibInterface::disableFan() +{ +#ifdef RADIO_FAN_EN +#ifdef RADIO_FAN_PWM +#if defined(ARCH_ESP32) + ledcWrite(1, 0); +#elif defined(ARCH_NRF52) + analogWrite(RADIO_FAN_EN, 0); +#endif +#else + pinMode(RADIO_FAN_EN, OUTPUT); + digitalWrite(RADIO_FAN_EN, 0); +#endif +#endif } \ No newline at end of file diff --git a/src/mesh/RadioLibInterface.h b/src/mesh/RadioLibInterface.h index a5c2e30dd..620231209 100644 --- a/src/mesh/RadioLibInterface.h +++ b/src/mesh/RadioLibInterface.h @@ -142,6 +142,9 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified /** Attempt to cancel a previously sent packet. Returns true if a packet was found we could cancel */ virtual bool cancelSending(NodeNum from, PacketId id) override; + void enableFan(); + void disableFan(); + private: /** if we have something waiting to send, start a short (random) timer so we can come check for collision before actually * doing the transmit */ diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 002fb41ca..c8ab6f358 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -49,6 +49,8 @@ template bool SX126xInterface::init() pinMode(SX126X_POWER_EN, OUTPUT); #endif + enableFan(); + #if ARCH_PORTDUINO float tcxoVoltage = 0; if (settingsMap[dio3_tcxo_voltage]) diff --git a/src/mesh/SX128xInterface.cpp b/src/mesh/SX128xInterface.cpp index 013164bca..efaf37fd7 100644 --- a/src/mesh/SX128xInterface.cpp +++ b/src/mesh/SX128xInterface.cpp @@ -32,10 +32,7 @@ template bool SX128xInterface::init() digitalWrite(SX128X_POWER_EN, HIGH); #endif -#ifdef RF95_FAN_EN - pinMode(RF95_FAN_EN, OUTPUT); - digitalWrite(RF95_FAN_EN, 1); -#endif + enableFan(); #if ARCH_PORTDUINO if (settingsMap[rxen] != RADIOLIB_NC) { diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 5401e1fdb..f64951ac1 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -545,13 +545,21 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) requiresReboot = false; } -#ifdef RF95_FAN_EN +#ifdef RADIO_FAN_EN +#ifdef RADIO_FAN_PWM +#if defined(ARCH_ESP32) + ledcWrite(1, c.payload_variant.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55)); +#elif defined(ARCH_NFR52) + analogWrite(RADIO_FAN_EN, c.payload_variant.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55)); +#endif +#else // Turn PA off if disabled by config if (c.payload_variant.lora.pa_fan_disabled) { - digitalWrite(RF95_FAN_EN, LOW ^ 0); + digitalWrite(RADIO_FAN_EN, LOW ^ 0); } else { - digitalWrite(RF95_FAN_EN, HIGH ^ 0); + digitalWrite(RADIO_FAN_EN, HIGH ^ 0); } +#endif #endif config.lora = c.payload_variant.lora; // If we're setting region for the first time, init the region diff --git a/variants/betafpv_2400_tx_micro/variant.h b/variants/betafpv_2400_tx_micro/variant.h index 67699e7c8..9e3503bd5 100644 --- a/variants/betafpv_2400_tx_micro/variant.h +++ b/variants/betafpv_2400_tx_micro/variant.h @@ -12,7 +12,7 @@ #define LORA_MISO 19 #define LORA_MOSI 23 #define LORA_CS 5 -#define RF95_FAN_EN 17 +#define RADIO_FAN_EN 17 // #define LED_PIN 16 // This is a LED_WS2812 not a standard LED #define HAS_NEOPIXEL // Enable the use of neopixels diff --git a/variants/radiomaster_900_bandit/variant.h b/variants/radiomaster_900_bandit/variant.h index 0c7417cac..a84a1ca4a 100644 --- a/variants/radiomaster_900_bandit/variant.h +++ b/variants/radiomaster_900_bandit/variant.h @@ -46,7 +46,8 @@ FAN is active at 250mW on it's ExpressLRS Firmware. This FAN has TACHO signal on Pin 27 for use with PWM. */ -#define RF95_FAN_EN 2 +#define RADIO_FAN_EN 2 +#define RADIO_FAN_PWM /* LED PIN setup and it has a NeoPixel LED. diff --git a/variants/radiomaster_900_bandit_nano/variant.h b/variants/radiomaster_900_bandit_nano/variant.h index 1b6bba126..d960dd9ef 100644 --- a/variants/radiomaster_900_bandit_nano/variant.h +++ b/variants/radiomaster_900_bandit_nano/variant.h @@ -32,7 +32,7 @@ This unit has a FAN built-in. FAN is active at 250mW on it's ExpressLRS Firmware. */ -#define RF95_FAN_EN 2 +#define RADIO_FAN_EN 2 /* LED PIN setup. diff --git a/variants/radiomaster_nomad_gemini/variant.h b/variants/radiomaster_nomad_gemini/variant.h index b403db2d1..25e757918 100644 --- a/variants/radiomaster_nomad_gemini/variant.h +++ b/variants/radiomaster_nomad_gemini/variant.h @@ -28,6 +28,13 @@ #define LR1121_SPI_MOSI_PIN LORA_MOSI #define LR1121_SPI_MISO_PIN LORA_MISO +// not yet implemented +#define JANUS_RADIO +#define LR1121_IRQ2_PIN 34 +#define LR1121_NRESET2_PIN 21 +#define LR1121_BUSY2_PIN 39 +#define LR1121_SPI_NSS2_PIN 13 + // #define LR11X0_DIO3_TCXO_VOLTAGE 1.6 #define LR11X0_DIO_AS_RF_SWITCH @@ -42,10 +49,11 @@ #undef EXT_NOTIFY_OUT -#define BAT_MEASURE_ADC_UNIT -#define BATTERY_PIN 26 -#define ADC_CHANNEL ADC2_GPIO26_CHANNEL -#define BATTERY_SENSE_SAMPLES 30 +// #define BAT_MEASURE_ADC_UNIT +// #define BATTERY_PIN 26 +// #define ADC_CHANNEL ADC2_GPIO26_CHANNEL +// #define BATTERY_SENSE_SAMPLES 30 -// ratio of voltage divider = 2.0 (R42=100k, R43=100k) -#define ADC_MULTIPLIER 2 +#define RADIO_FAN_EN 2 +// this board does need PWM on the FAN PIN +#define RADIO_FAN_PWM