From e79ee118722fc0050c1de0378bb5ac93fc7084e6 Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Tue, 16 Dec 2025 20:27:48 +0100 Subject: [PATCH 01/33] EnvironmentSensorManager.cpp: Fix RAK4631 serial GPS detection Serial1 is always true. If we want to check for the presence of a GPS receiver, we need to check if any data was received. Signed-off-by: Frieder Schrempf --- src/helpers/sensors/EnvironmentSensorManager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index 77a791bd..f0bb5654 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -653,8 +653,7 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){ _location = &RAK12500_provider; return true; - } - else if(Serial1){ + } else if (Serial1.available()) { MESH_DEBUG_PRINTLN("Serial GPS init correctly and is turned on"); if(PIN_GPS_EN){ gpsResetPin = PIN_GPS_EN; From ab7935142cd257c860f58671dc849dfb047338b8 Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Tue, 16 Dec 2025 20:28:20 +0100 Subject: [PATCH 02/33] EnvironmentSensorManager.cpp: Cleanup after failed RAK4631 GPS detection If no GPS was detected, revert the hardware to the initial state, otherwise we may see conflicts or increased power consumption on some boards. Signed-off-by: Frieder Schrempf --- src/helpers/sensors/EnvironmentSensorManager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index f0bb5654..b7238def 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -615,6 +615,7 @@ void EnvironmentSensorManager::rakGPSInit(){ MESH_DEBUG_PRINTLN("No GPS found"); gps_active = false; gps_detected = false; + Serial1.end(); return; } @@ -663,6 +664,8 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){ gps_detected = true; return true; } + + pinMode(ioPin, INPUT); MESH_DEBUG_PRINTLN("GPS did not init with this IO pin... try the next"); return false; } From faf177de467d124485ff5e7710cc2c46e216a4aa Mon Sep 17 00:00:00 2001 From: liquidraver <504870+liquidraver@users.noreply.github.com> Date: Wed, 31 Dec 2025 13:40:05 +0100 Subject: [PATCH 03/33] ESP factory reset clear NVS too --- examples/companion_radio/DataStore.cpp | 5 ++++- examples/companion_radio/MyMesh.cpp | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index 7f5761f3..4faac975 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -65,6 +65,7 @@ void DataStore::begin() { #if defined(ESP32) #include + #include #elif defined(RP2040_PLATFORM) #include #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) @@ -172,7 +173,9 @@ bool DataStore::formatFileSystem() { #elif defined(RP2040_PLATFORM) return LittleFS.format(); #elif defined(ESP32) - return ((fs::SPIFFSFS *)_fs)->format(); + bool fs_success = ((fs::SPIFFSFS *)_fs)->format(); + esp_err_t nvs_err = nvs_flash_erase(); // no need to reinit, will be done by reboot + return fs_success && (nvs_err == ESP_OK); #else #error "need to implement format()" #endif diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 9cbb2eba..19a92f77 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -1613,6 +1613,10 @@ void MyMesh::handleCmdFrame(size_t len) { writeErrFrame(ERR_CODE_ILLEGAL_ARG); // invalid stats sub-type } } else if (cmd_frame[0] == CMD_FACTORY_RESET && memcmp(&cmd_frame[1], "reset", 5) == 0) { + if (_serial) { + MESH_DEBUG_PRINTLN("Factory reset: disabling serial interface to prevent reconnects (BLE/WiFi)"); + _serial->disable(); // Phone app disconnects before we can send OK frame so it's safe here + } bool success = _store->formatFileSystem(); if (success) { writeOKFrame(); From 3af25495bb4e2eaf17de4a916ce9355e62e71f31 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Sat, 3 Jan 2026 12:02:15 +1100 Subject: [PATCH 04/33] * Repeater: new anon request sub-type: ANON_REQ_TYPE_REGIONS (rate limited to max 4 every 3 mins) * Companion: new CMD_SEND_ANON_REQ command (reply with existing RESP_CODE_SENT frame) --- examples/companion_radio/MyMesh.cpp | 22 ++++++++++++++++++ examples/simple_repeater/MyMesh.cpp | 22 +++++++++++++++--- examples/simple_repeater/MyMesh.h | 3 ++- src/helpers/BaseChatMesh.cpp | 25 ++++++++++++++++++++ src/helpers/BaseChatMesh.h | 1 + src/helpers/RegionMap.cpp | 36 ++++++++++++++++++++++++----- src/helpers/RegionMap.h | 7 ++++-- 7 files changed, 104 insertions(+), 12 deletions(-) diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 7689708c..59a0078f 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -53,6 +53,7 @@ #define CMD_SET_FLOOD_SCOPE 54 // v8+ #define CMD_SEND_CONTROL_DATA 55 // v8+ #define CMD_GET_STATS 56 // v8+, second byte is stats type +#define CMD_SEND_ANON_REQ 57 // Stats sub-types for CMD_GET_STATS #define STATS_TYPE_CORE 0 @@ -1286,6 +1287,27 @@ void MyMesh::handleCmdFrame(size_t len) { } else { writeErrFrame(ERR_CODE_NOT_FOUND); // contact not found } + } else if (cmd_frame[0] == CMD_SEND_ANON_REQ && len > 1 + PUB_KEY_SIZE) { + uint8_t *pub_key = &cmd_frame[1]; + ContactInfo *recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE); + uint8_t *data = &cmd_frame[1 + PUB_KEY_SIZE]; + if (recipient) { + uint32_t tag, est_timeout; + int result = sendAnonReq(*recipient, data, len - (1 + PUB_KEY_SIZE), tag, est_timeout); + if (result == MSG_SEND_FAILED) { + writeErrFrame(ERR_CODE_TABLE_FULL); + } else { + clearPendingReqs(); + pending_req = tag; // match this to onContactResponse() + out_frame[0] = RESP_CODE_SENT; + out_frame[1] = (result == MSG_SEND_SENT_FLOOD) ? 1 : 0; + memcpy(&out_frame[2], &tag, 4); + memcpy(&out_frame[6], &est_timeout, 4); + _serial->writeFrame(out_frame, 10); + } + } else { + writeErrFrame(ERR_CODE_NOT_FOUND); // contact not found + } } else if (cmd_frame[0] == CMD_SEND_STATUS_REQ && len >= 1 + PUB_KEY_SIZE) { uint8_t *pub_key = &cmd_frame[1]; ContactInfo *recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE); diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 33e32a68..253fa701 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -51,6 +51,8 @@ #define RESP_SERVER_LOGIN_OK 0 // response to ANON_REQ +#define ANON_REQ_TYPE_REGIONS 0x01 + #define CLI_REPLY_DELAY_MILLIS 600 #define LAZY_CONTACTS_WRITE_DELAY 5000 @@ -139,6 +141,19 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr return 13; // reply length } +uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { + // REVISIT: should there be params like 'since' in request data[] ? + if (regions_limiter.allow(rtc_clock.getCurrentTime())) { + memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag + + uint32_t now = getRTCClock()->getCurrentTime(); + memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, if this is a trusted node) + + return 8 + region_map.exportNamesTo((char *) &reply_data[8], sizeof(reply_data) - 12, REGION_DENY_FLOOD); // reply length + } + return 0; +} + int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t *payload, size_t payload_len) { // uint32_t now = getRTCClock()->getCurrentTimeUnique(); // memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp @@ -450,8 +465,8 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m uint8_t reply_len; if (data[4] == 0 || data[4] >= ' ') { // is password, ie. a login request reply_len = handleLoginReq(sender, secret, timestamp, &data[4], packet->isRouteFlood()); - //} else if (data[4] == ANON_REQ_TYPE_*) { // future type codes - // TODO + } else if (data[4] == ANON_REQ_TYPE_REGIONS) { + reply_len = handleAnonRegionsReq(sender, timestamp, &data[5]); } else { reply_len = 0; // unknown request type } @@ -668,7 +683,8 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc mesh::RTCClock &rtc, mesh::MeshTables &tables) : mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables), _cli(board, rtc, sensors, &_prefs, this), telemetry(MAX_PACKET_PAYLOAD - 4), region_map(key_store), temp_map(key_store), - discover_limiter(4, 120) // max 4 every 2 minutes + discover_limiter(4, 120), // max 4 every 2 minutes + regions_limiter(4, 180) // max 4 every 3 minutes #if defined(WITH_RS232_BRIDGE) , bridge(&_prefs, WITH_RS232_BRIDGE, _mgr, &rtc) #endif diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index 343aa44f..172c756b 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -93,7 +93,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { RegionMap region_map, temp_map; RegionEntry* load_stack[8]; RegionEntry* recv_pkt_region; - RateLimiter discover_limiter; + RateLimiter discover_limiter, regions_limiter; bool region_load_active; unsigned long dirty_contacts_expiry; #if MAX_NEIGHBOURS @@ -114,6 +114,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { void putNeighbour(const mesh::Identity& id, uint32_t timestamp, float snr); uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood); + uint8_t handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data); int handleRequest(ClientInfo* sender, uint32_t sender_timestamp, uint8_t* payload, size_t payload_len); mesh::Packet* createSelfAdvert(); diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index 597444fa..08185628 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -477,6 +477,31 @@ int BaseChatMesh::sendLogin(const ContactInfo& recipient, const char* password, return MSG_SEND_FAILED; } +int BaseChatMesh::sendAnonReq(const ContactInfo& recipient, const uint8_t* data, uint8_t len, uint32_t& tag, uint32_t& est_timeout) { + mesh::Packet* pkt; + { + uint8_t temp[MAX_PACKET_PAYLOAD]; + tag = getRTCClock()->getCurrentTimeUnique(); + memcpy(temp, &tag, 4); // tag to match later (also extra blob to help make packet_hash unique) + memcpy(&temp[4], data, len); + + pkt = createAnonDatagram(PAYLOAD_TYPE_ANON_REQ, self_id, recipient.id, recipient.getSharedSecret(self_id), temp, 4 + len); + } + if (pkt) { + uint32_t t = _radio->getEstAirtimeFor(pkt->getRawLength()); + if (recipient.out_path_len < 0) { + sendFloodScoped(recipient, pkt); + est_timeout = calcFloodTimeoutMillisFor(t); + return MSG_SEND_SENT_FLOOD; + } else { + sendDirect(pkt, recipient.out_path, recipient.out_path_len); + est_timeout = calcDirectTimeoutMillisFor(t, recipient.out_path_len); + return MSG_SEND_SENT_DIRECT; + } + } + return MSG_SEND_FAILED; +} + int BaseChatMesh::sendRequest(const ContactInfo& recipient, const uint8_t* req_data, uint8_t data_len, uint32_t& tag, uint32_t& est_timeout) { if (data_len > MAX_PACKET_PAYLOAD - 16) return MSG_SEND_FAILED; diff --git a/src/helpers/BaseChatMesh.h b/src/helpers/BaseChatMesh.h index 76b0dd1c..40818fed 100644 --- a/src/helpers/BaseChatMesh.h +++ b/src/helpers/BaseChatMesh.h @@ -141,6 +141,7 @@ public: int sendCommandData(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char* text, uint32_t& est_timeout); bool sendGroupMessage(uint32_t timestamp, mesh::GroupChannel& channel, const char* sender_name, const char* text, int text_len); int sendLogin(const ContactInfo& recipient, const char* password, uint32_t& est_timeout); + int sendAnonReq(const ContactInfo& recipient, const uint8_t* data, uint8_t len, uint32_t& tag, uint32_t& est_timeout); int sendRequest(const ContactInfo& recipient, uint8_t req_type, uint32_t& tag, uint32_t& est_timeout); int sendRequest(const ContactInfo& recipient, const uint8_t* req_data, uint8_t data_len, uint32_t& tag, uint32_t& est_timeout); bool shareContactZeroHop(const ContactInfo& contact); diff --git a/src/helpers/RegionMap.cpp b/src/helpers/RegionMap.cpp index 36844615..e227532a 100644 --- a/src/helpers/RegionMap.cpp +++ b/src/helpers/RegionMap.cpp @@ -24,12 +24,12 @@ static File openWrite(FILESYSTEM* _fs, const char* filename) { #endif } -bool RegionMap::load(FILESYSTEM* _fs) { - if (_fs->exists("/regions2")) { +bool RegionMap::load(FILESYSTEM* _fs, const char* path) { + if (_fs->exists(path ? path : "/regions2")) { #if defined(RP2040_PLATFORM) - File file = _fs->open("/regions2", "r"); + File file = _fs->open(path ? path : "/regions2", "r"); #else - File file = _fs->open("/regions2"); + File file = _fs->open(path ? path : "/regions2"); #endif if (file) { @@ -67,8 +67,8 @@ bool RegionMap::load(FILESYSTEM* _fs) { return false; // failed } -bool RegionMap::save(FILESYSTEM* _fs) { - File file = openWrite(_fs, "/regions2"); +bool RegionMap::save(FILESYSTEM* _fs, const char* path) { + File file = openWrite(_fs, path ? path : "/regions2"); if (file) { uint8_t pad[128]; memset(pad, 0, sizeof(pad)); @@ -235,3 +235,27 @@ void RegionMap::printChildRegions(int indent, const RegionEntry* parent, Stream& void RegionMap::exportTo(Stream& out) const { printChildRegions(0, &wildcard, out); // recursive } + +int RegionMap::exportNamesTo(char *dest, int max_len, uint8_t mask) { + char *dp = dest; + if ((wildcard.flags & mask) == 0) { + *dp++ = '*'; + *dp++ = ','; + } + + for (int i = 0; i < num_regions; i++) { + auto region = ®ions[i]; + if ((region->flags & mask) == 0) { // region allowed? (per 'mask' param) + int len = strlen(region->name); + if ((dp - dest) + len + 2 < max_len) { // only append if name will fit + memcpy(dp, region->name, len); + dp += len; + *dp++ = ','; + } + } + } + if (dp > dest) { dp--; } // don't include trailing comma + + *dp = 0; // set null terminator + return dp - dest; // return length +} diff --git a/src/helpers/RegionMap.h b/src/helpers/RegionMap.h index 50513be1..dcd9a774 100644 --- a/src/helpers/RegionMap.h +++ b/src/helpers/RegionMap.h @@ -32,8 +32,8 @@ public: static bool is_name_char(char c); - bool load(FILESYSTEM* _fs); - bool save(FILESYSTEM* _fs); + bool load(FILESYSTEM* _fs, const char* path=NULL); + bool save(FILESYSTEM* _fs, const char* path=NULL); RegionEntry* putRegion(const char* name, uint16_t parent_id, uint16_t id = 0); RegionEntry* findMatch(mesh::Packet* packet, uint8_t mask); @@ -47,6 +47,9 @@ public: bool clear(); void resetFrom(const RegionMap& src) { num_regions = 0; next_id = src.next_id; } int getCount() const { return num_regions; } + const RegionEntry* getByIdx(int i) const { return ®ions[i]; } + const RegionEntry* getRoot() const { return &wildcard; } + int exportNamesTo(char *dest, int max_len, uint8_t mask); void exportTo(Stream& out) const; }; From ed263b07270096ebf8062d155052c3a9d727beb3 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sat, 3 Jan 2026 15:39:57 +1300 Subject: [PATCH 05/33] implement frame header parising for wifi interface --- src/helpers/esp32/SerialWifiInterface.cpp | 85 +++++++++++++++++++++-- src/helpers/esp32/SerialWifiInterface.h | 7 ++ 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/src/helpers/esp32/SerialWifiInterface.cpp b/src/helpers/esp32/SerialWifiInterface.cpp index 2df9980a..9470c827 100644 --- a/src/helpers/esp32/SerialWifiInterface.cpp +++ b/src/helpers/esp32/SerialWifiInterface.cpp @@ -54,6 +54,9 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) { // switch active connection to new client client = newClient; + + // forget received frame header + received_frame_header = NULL; } @@ -86,13 +89,83 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) { send_queue[i] = send_queue[i + 1]; } } else { - int len = client.available(); - if (len > 0) { - uint8_t buf[MAX_FRAME_SIZE + 4]; - client.readBytes(buf, len); - memcpy(dest, buf+3, len-3); // remove header (don't even check ... problems are on the other dir) - return len-3; + + // check if we are waiting for a frame header + if(received_frame_header == NULL){ + + // make sure we have received enough bytes for a frame header + // 3 bytes frame header = (1 byte frame type) + (2 bytes frame length as unsigned 16-bit little endian) + int frame_header_length = 3; + if(client.available() >= frame_header_length){ + + // read frame header + uint8_t frame_header[3]; + client.readBytes(frame_header, frame_header_length); + + // parse frame header + uint8_t frame_type = frame_header[0]; + uint16_t frame_length; + memcpy(&frame_length, &frame_header[1], 2); + + // we have received a frame header + received_frame_header = new FrameHeader(); + received_frame_header->type = frame_type; + received_frame_header->length = frame_length; + + } + } + + // check if we have received a frame header + if(received_frame_header){ + + // make sure we have received enough bytes for the required frame length + int available = client.available(); + int frame_type = received_frame_header->type; + int frame_length = received_frame_header->length; + if(frame_length > available){ + WIFI_DEBUG_PRINTLN("Waiting for %d more bytes", frame_length - available); + return 0; + } + + // skip frames that are larger than MAX_FRAME_SIZE + if(frame_length > MAX_FRAME_SIZE){ + WIFI_DEBUG_PRINTLN("Skipping frame: length=%d is larger than MAX_FRAME_SIZE=%d", frame_length, MAX_FRAME_SIZE); + while(frame_length > 0){ + uint8_t skip[1]; + int skipped = client.read(skip, 1); + frame_length -= skipped; + } + received_frame_header = NULL; + return 0; + } + + // skip frames that are not expected type + // '<' is 0x3c which indicates a frame sent from app to radio + if(frame_type != '<'){ + WIFI_DEBUG_PRINTLN("Skipping frame: type=0x%x is unexpected", frame_type); + while(frame_length > 0){ + uint8_t skip[1]; + int skipped = client.read(skip, 1); + frame_length -= skipped; + } + received_frame_header = NULL; + return 0; + } + + // read frame data + uint8_t frame_data[MAX_FRAME_SIZE]; + client.readBytes(frame_data, frame_length); + + // copy frame to provided buffer + memcpy(dest, frame_data, frame_length); + + // ready for next frame + received_frame_header = NULL; + return frame_length; + + } + } } diff --git a/src/helpers/esp32/SerialWifiInterface.h b/src/helpers/esp32/SerialWifiInterface.h index 2b6c6edd..c7139b40 100644 --- a/src/helpers/esp32/SerialWifiInterface.h +++ b/src/helpers/esp32/SerialWifiInterface.h @@ -12,11 +12,18 @@ class SerialWifiInterface : public BaseSerialInterface { WiFiServer server; WiFiClient client; + struct FrameHeader { + uint8_t type; + uint16_t length; + }; + struct Frame { uint8_t len; uint8_t buf[MAX_FRAME_SIZE]; }; + FrameHeader* received_frame_header = NULL; + #define FRAME_QUEUE_SIZE 4 int recv_queue_len; Frame recv_queue[FRAME_QUEUE_SIZE]; From 71bb49e556d11e2fb4276c4346d901f125ff1850 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sat, 3 Jan 2026 16:36:19 +1300 Subject: [PATCH 06/33] remove use of dynamic allocation --- src/helpers/esp32/SerialWifiInterface.cpp | 30 ++++++++++++++--------- src/helpers/esp32/SerialWifiInterface.h | 7 +++++- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/helpers/esp32/SerialWifiInterface.cpp b/src/helpers/esp32/SerialWifiInterface.cpp index 9470c827..de5cce78 100644 --- a/src/helpers/esp32/SerialWifiInterface.cpp +++ b/src/helpers/esp32/SerialWifiInterface.cpp @@ -43,6 +43,15 @@ bool SerialWifiInterface::isWriteBusy() const { return false; } +bool SerialWifiInterface::hasReceivedFrameHeader() { + return received_frame_header.type != 0 && received_frame_header.length != 0; +} + +void SerialWifiInterface::resetReceivedFrameHeader() { + received_frame_header.type = 0; + received_frame_header.length = 0; +} + size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) { // check if new client connected auto newClient = server.available(); @@ -56,7 +65,7 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) { client = newClient; // forget received frame header - received_frame_header = NULL; + resetReceivedFrameHeader(); } @@ -91,7 +100,7 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) { } else { // check if we are waiting for a frame header - if(received_frame_header == NULL){ + if(!hasReceivedFrameHeader()){ // make sure we have received enough bytes for a frame header // 3 bytes frame header = (1 byte frame type) + (2 bytes frame length as unsigned 16-bit little endian) @@ -108,21 +117,20 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) { memcpy(&frame_length, &frame_header[1], 2); // we have received a frame header - received_frame_header = new FrameHeader(); - received_frame_header->type = frame_type; - received_frame_header->length = frame_length; + received_frame_header.type = frame_type; + received_frame_header.length = frame_length; } } // check if we have received a frame header - if(received_frame_header){ + if(hasReceivedFrameHeader()){ // make sure we have received enough bytes for the required frame length int available = client.available(); - int frame_type = received_frame_header->type; - int frame_length = received_frame_header->length; + int frame_type = received_frame_header.type; + int frame_length = received_frame_header.length; if(frame_length > available){ WIFI_DEBUG_PRINTLN("Waiting for %d more bytes", frame_length - available); return 0; @@ -136,7 +144,7 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) { int skipped = client.read(skip, 1); frame_length -= skipped; } - received_frame_header = NULL; + resetReceivedFrameHeader(); return 0; } @@ -149,7 +157,7 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) { int skipped = client.read(skip, 1); frame_length -= skipped; } - received_frame_header = NULL; + resetReceivedFrameHeader(); return 0; } @@ -161,7 +169,7 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) { memcpy(dest, frame_data, frame_length); // ready for next frame - received_frame_header = NULL; + resetReceivedFrameHeader(); return frame_length; } diff --git a/src/helpers/esp32/SerialWifiInterface.h b/src/helpers/esp32/SerialWifiInterface.h index c7139b40..19291497 100644 --- a/src/helpers/esp32/SerialWifiInterface.h +++ b/src/helpers/esp32/SerialWifiInterface.h @@ -22,7 +22,7 @@ class SerialWifiInterface : public BaseSerialInterface { uint8_t buf[MAX_FRAME_SIZE]; }; - FrameHeader* received_frame_header = NULL; + FrameHeader received_frame_header; #define FRAME_QUEUE_SIZE 4 int recv_queue_len; @@ -40,6 +40,8 @@ public: _isEnabled = false; _last_write = 0; send_queue_len = recv_queue_len = 0; + received_frame_header.type = 0; + received_frame_header.length = 0; } void begin(int port); @@ -54,6 +56,9 @@ public: size_t writeFrame(const uint8_t src[], size_t len) override; size_t checkRecvFrame(uint8_t dest[]) override; + + bool hasReceivedFrameHeader(); + void resetReceivedFrameHeader(); }; #if WIFI_DEBUG_LOGGING && ARDUINO From 63ae92aa0973d312b802ef938eb44f1414731c82 Mon Sep 17 00:00:00 2001 From: Rastislav Vysoky Date: Sat, 3 Jan 2026 16:32:36 +0100 Subject: [PATCH 07/33] fix compilation errors for m6 companion roles --- variants/thinknode_m6/platformio.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/variants/thinknode_m6/platformio.ini b/variants/thinknode_m6/platformio.ini index 16394ced..db22073c 100644 --- a/variants/thinknode_m6/platformio.ini +++ b/variants/thinknode_m6/platformio.ini @@ -90,7 +90,6 @@ build_src_filter = ${ThinkNode_M6.build_src_filter} + + +<../examples/companion_radio/*.cpp> - +<../examples/companion_radio/ui-new/*.cpp> lib_deps = ${ThinkNode_M6.lib_deps} densaugeo/base64 @ ~1.4.0 @@ -113,7 +112,6 @@ build_src_filter = ${ThinkNode_M6.build_src_filter} + + +<../examples/companion_radio/*.cpp> - +<../examples/companion_radio/ui-new/*.cpp> lib_deps = ${ThinkNode_M6.lib_deps} densaugeo/base64 @ ~1.4.0 From 63767cdb7de6dcdec7eadadf3cf16716b3d3f88e Mon Sep 17 00:00:00 2001 From: cj-vana Date: Sat, 3 Jan 2026 18:54:48 -0700 Subject: [PATCH 08/33] Fix typos in README and source comments --- README.md | 4 ++-- src/helpers/radiolib/CustomLR1110.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 73fa960c..d3bcbbef 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ Please submit PR's using 'dev' as the base branch! For minor changes just submit your PR and I'll try to review it, but for anything more 'impactful' please open an Issue first and start a discussion. Is better to sound out what it is you want to achieve first, and try to come to a consensus on what the best approach is, especially when it impacts the structure or architecture of this codebase. Here are some general principals you should try to adhere to: -* Keep it simple. Please, don't think like a high-level lang programmer. Think embedded, and keep code concise, without any unecessary layers. +* Keep it simple. Please, don't think like a high-level lang programmer. Think embedded, and keep code concise, without any unnecessary layers. * No dynamic memory allocation, except during setup/begin functions. * Use the same brace and indenting style that's in the core source modules. (A .clang-format is prob going to be added soon, but please do NOT retroactively re-format existing code. This just creates unnecessary diffs that make finding problems harder) @@ -106,7 +106,7 @@ There are a number of fairly major features in the pipeline, with no particular - [ ] Core + Apps: support for LZW message compression - [ ] Core: dynamic CR (Coding Rate) for weak vs strong hops - [ ] Core: new framework for hosting multiple virtual nodes on one physical device -- [ ] V2 protocol spec: discussion and concensus around V2 packet protocol, including path hashes, new encryption specs, etc +- [ ] V2 protocol spec: discussion and consensus around V2 packet protocol, including path hashes, new encryption specs, etc ## 📞 Get Support diff --git a/src/helpers/radiolib/CustomLR1110.h b/src/helpers/radiolib/CustomLR1110.h index 2e536de5..e4332013 100644 --- a/src/helpers/radiolib/CustomLR1110.h +++ b/src/helpers/radiolib/CustomLR1110.h @@ -10,7 +10,7 @@ class CustomLR1110 : public LR1110 { size_t getPacketLength(bool update) override { size_t len = LR1110::getPacketLength(update); if (len == 0 && getIrqStatus() & RADIOLIB_LR11X0_IRQ_HEADER_ERR) { - // we've just recieved a corrupted packet + // we've just received a corrupted packet // this may have triggered a bug causing subsequent packets to be shifted // call standby() to return radio to known-good state // recvRaw will call startReceive() to restart rx From 8708fa012ad9f64f1b7bc1fa93ef466378f4f496 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sun, 4 Jan 2026 17:43:25 +1300 Subject: [PATCH 09/33] simplify reading frame header --- src/helpers/esp32/SerialWifiInterface.cpp | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/helpers/esp32/SerialWifiInterface.cpp b/src/helpers/esp32/SerialWifiInterface.cpp index de5cce78..462e3ecc 100644 --- a/src/helpers/esp32/SerialWifiInterface.cpp +++ b/src/helpers/esp32/SerialWifiInterface.cpp @@ -108,17 +108,8 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) { if(client.available() >= frame_header_length){ // read frame header - uint8_t frame_header[3]; - client.readBytes(frame_header, frame_header_length); - - // parse frame header - uint8_t frame_type = frame_header[0]; - uint16_t frame_length; - memcpy(&frame_length, &frame_header[1], 2); - - // we have received a frame header - received_frame_header.type = frame_type; - received_frame_header.length = frame_length; + client.readBytes(&received_frame_header.type, 1); + client.readBytes((uint8_t*)&received_frame_header.length, 2); } @@ -161,12 +152,8 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) { return 0; } - // read frame data - uint8_t frame_data[MAX_FRAME_SIZE]; - client.readBytes(frame_data, frame_length); - - // copy frame to provided buffer - memcpy(dest, frame_data, frame_length); + // read frame data to provided buffer + client.readBytes(dest, frame_length); // ready for next frame resetReceivedFrameHeader(); From 818f5e9da507840be3753eb7bffb08a23546f286 Mon Sep 17 00:00:00 2001 From: alex-vg <22611767+alex-vg@users.noreply.github.com> Date: Sat, 20 Dec 2025 00:12:39 +0100 Subject: [PATCH 10/33] variants: Xiao_S3_WIO: Add WiFi companion env --- variants/xiao_s3_wio/platformio.ini | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/variants/xiao_s3_wio/platformio.ini b/variants/xiao_s3_wio/platformio.ini index 8979edc2..22bb4090 100644 --- a/variants/xiao_s3_wio/platformio.ini +++ b/variants/xiao_s3_wio/platformio.ini @@ -195,6 +195,29 @@ lib_deps = densaugeo/base64 @ ~1.4.0 adafruit/Adafruit SSD1306 @ ^2.5.13 +[env:Xiao_S3_WIO_companion_radio_wifi] +extends = Xiao_S3_WIO +build_src_filter = ${Xiao_S3_WIO.build_src_filter} + + + + + + + +<../examples/companion_radio/*.cpp> +build_flags = + ${Xiao_S3_WIO.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D OFFLINE_QUEUE_SIZE=256 + -D WIFI_DEBUG_LOGGING=1 + -D WIFI_SSID='"myssid"' + -D WIFI_PWD='"password"' + ; -D BLE_DEBUG_LOGGING=1 + ; -D MESH_PACKET_LOGGING=1 + ; -D MESH_DEBUG=1 +lib_deps = + ${Xiao_S3_WIO.lib_deps} + densaugeo/base64 @ ~1.4.0 + [env:Xiao_S3_WIO_sensor] extends = Xiao_S3_WIO build_src_filter = ${Xiao_S3_WIO.build_src_filter} From d4a2e5789f0de675a84589fb0cdeaee451929bb1 Mon Sep 17 00:00:00 2001 From: Luke Date: Tue, 6 Jan 2026 14:49:15 +0000 Subject: [PATCH 11/33] OFFLINE_QUEUE_SIZE for Heltec Wifi companions OFFLINE_QUEUE_SIZE missing from h3/h4 wifi companions, causing them only store 16 messages. --- variants/heltec_v3/platformio.ini | 2 ++ variants/heltec_v4/platformio.ini | 1 + 2 files changed, 3 insertions(+) diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index 36c6386f..dcb2873c 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -189,6 +189,7 @@ build_flags = -D WIFI_DEBUG_LOGGING=1 -D WIFI_SSID='"myssid"' -D WIFI_PWD='"mypwd"' + -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${Heltec_lora32_v3.build_src_filter} @@ -341,6 +342,7 @@ build_flags = -D WIFI_DEBUG_LOGGING=1 -D WIFI_SSID='"myssid"' -D WIFI_PWD='"mypwd"' + -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${Heltec_lora32_v3.build_src_filter} diff --git a/variants/heltec_v4/platformio.ini b/variants/heltec_v4/platformio.ini index c26a5bc6..ecfd7889 100644 --- a/variants/heltec_v4/platformio.ini +++ b/variants/heltec_v4/platformio.ini @@ -176,6 +176,7 @@ build_flags = -D WIFI_DEBUG_LOGGING=1 -D WIFI_SSID='"myssid"' -D WIFI_PWD='"mypwd"' + -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${Heltec_lora32_v4.build_src_filter} From a7a6bb51ce867da45851583f8f50bf0a64abfeaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Weyhm=C3=BCller?= Date: Wed, 7 Jan 2026 03:40:00 +0100 Subject: [PATCH 12/33] Apply #1331 to other WiFi companions --- variants/heltec_tracker_v2/platformio.ini | 1 + variants/heltec_v2/platformio.ini | 1 + variants/lilygo_tlora_v2_1/platformio.ini | 1 + variants/nibble_screen_connect/platformio.ini | 1 + variants/station_g2/platformio.ini | 1 + 5 files changed, 5 insertions(+) diff --git a/variants/heltec_tracker_v2/platformio.ini b/variants/heltec_tracker_v2/platformio.ini index 61ccd4f4..36de671e 100644 --- a/variants/heltec_tracker_v2/platformio.ini +++ b/variants/heltec_tracker_v2/platformio.ini @@ -185,6 +185,7 @@ build_flags = -D WIFI_DEBUG_LOGGING=1 -D WIFI_SSID='"myssid"' -D WIFI_PWD='"mypwd"' + -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${Heltec_tracker_v2.build_src_filter} diff --git a/variants/heltec_v2/platformio.ini b/variants/heltec_v2/platformio.ini index 539cc52e..f8cc9360 100644 --- a/variants/heltec_v2/platformio.ini +++ b/variants/heltec_v2/platformio.ini @@ -183,6 +183,7 @@ build_flags = -D WIFI_DEBUG_LOGGING=1 -D WIFI_SSID='"myssid"' -D WIFI_PWD='"mypwd"' + -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${Heltec_lora32_v2.build_src_filter} diff --git a/variants/lilygo_tlora_v2_1/platformio.ini b/variants/lilygo_tlora_v2_1/platformio.ini index 9ef9734e..f27f57fd 100644 --- a/variants/lilygo_tlora_v2_1/platformio.ini +++ b/variants/lilygo_tlora_v2_1/platformio.ini @@ -136,6 +136,7 @@ build_flags = -D WIFI_SSID='"ssid"' -D WIFI_PWD='"password"' -D WIFI_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 build_src_filter = ${LilyGo_TLora_V2_1_1_6.build_src_filter} + + diff --git a/variants/nibble_screen_connect/platformio.ini b/variants/nibble_screen_connect/platformio.ini index e18bcde1..0d3d4652 100644 --- a/variants/nibble_screen_connect/platformio.ini +++ b/variants/nibble_screen_connect/platformio.ini @@ -147,6 +147,7 @@ build_flags = -D WIFI_DEBUG_LOGGING=1 -D WIFI_SSID='"myssid"' -D WIFI_PWD='"mypwd"' + -D OFFLINE_QUEUE_SIZE=256 build_src_filter = ${nibble_screen_connect_base.build_src_filter} + + diff --git a/variants/station_g2/platformio.ini b/variants/station_g2/platformio.ini index b3ba2a86..1428221d 100644 --- a/variants/station_g2/platformio.ini +++ b/variants/station_g2/platformio.ini @@ -226,6 +226,7 @@ build_flags = -D WIFI_DEBUG_LOGGING=1 -D WIFI_SSID='"myssid"' -D WIFI_PWD='"mypwd"' + -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${Station_G2.build_src_filter} From 55fc03b1090251ae4dac5070ee09ed1a1cfd663b Mon Sep 17 00:00:00 2001 From: Ferdia McKeogh Date: Tue, 6 Jan 2026 20:11:19 +0100 Subject: [PATCH 13/33] Fix capitalization in T1000-E manufacturer string --- variants/t1000-e/T1000eBoard.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variants/t1000-e/T1000eBoard.h b/variants/t1000-e/T1000eBoard.h index 32f54bb3..f26bdf02 100644 --- a/variants/t1000-e/T1000eBoard.h +++ b/variants/t1000-e/T1000eBoard.h @@ -34,7 +34,7 @@ public: } const char* getManufacturerName() const override { - return "Seeed Tracker T1000-e"; + return "Seeed Tracker T1000-E"; } int buttonStateChanged() { @@ -91,4 +91,4 @@ public: } // bool startOTAUpdate(const char* id, char reply[]) override; -}; \ No newline at end of file +}; From 5cc44dd802b07a4f4180e8ba694fabcb7de96174 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Thu, 8 Jan 2026 13:20:52 +1100 Subject: [PATCH 14/33] * ANON_REQ_TYPE_REGIONS now direct only, with reply_path encoded in request --- examples/simple_repeater/MyMesh.cpp | 18 ++++++++++++++---- examples/simple_repeater/MyMesh.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 253fa701..261184c5 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -142,8 +142,13 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr } uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { - // REVISIT: should there be params like 'since' in request data[] ? if (regions_limiter.allow(rtc_clock.getCurrentTime())) { + // request data has: {reply-path-len}{reply-path} + reply_path_len = *data++ & 0x3F; + memcpy(reply_path, data, reply_path_len); + // data += reply_path_len; + // other params?? + memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag uint32_t now = getRTCClock()->getCurrentTime(); @@ -463,12 +468,14 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m data[len] = 0; // ensure null terminator uint8_t reply_len; + + reply_path_len = -1; if (data[4] == 0 || data[4] >= ' ') { // is password, ie. a login request reply_len = handleLoginReq(sender, secret, timestamp, &data[4], packet->isRouteFlood()); - } else if (data[4] == ANON_REQ_TYPE_REGIONS) { + } else if (data[4] == ANON_REQ_TYPE_REGIONS && packet->isRouteDirect()) { reply_len = handleAnonRegionsReq(sender, timestamp, &data[5]); } else { - reply_len = 0; // unknown request type + reply_len = 0; // unknown/invalid request type } if (reply_len == 0) return; // invalid request @@ -478,9 +485,12 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m mesh::Packet* path = createPathReturn(sender, secret, packet->path, packet->path_len, PAYLOAD_TYPE_RESPONSE, reply_data, reply_len); if (path) sendFlood(path, SERVER_RESPONSE_DELAY); - } else { + } else if (reply_path_len < 0) { mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len); if (reply) sendFlood(reply, SERVER_RESPONSE_DELAY); + } else { + mesh::Packet* reply = createDatagram(PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len); + if (reply) sendDirect(reply, reply_path, reply_path_len, SERVER_RESPONSE_DELAY); } } } diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index 172c756b..49952770 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -88,6 +88,8 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { NodePrefs _prefs; CommonCLI _cli; uint8_t reply_data[MAX_PACKET_PAYLOAD]; + uint8_t reply_path[MAX_PATH_SIZE]; + int8_t reply_path_len; ClientACL acl; TransportKeyStore key_store; RegionMap region_map, temp_map; From 5475043083756b4bed07da6e6dec683f5d5f99a8 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Fri, 9 Jan 2026 11:07:31 +1100 Subject: [PATCH 15/33] * new ANON_REQ_TYPE_VER_OWNER * CommonCLI: new "get/set owner.info ..." --- examples/simple_repeater/MyMesh.cpp | 27 +++++++++++++++++++++++++-- examples/simple_repeater/MyMesh.h | 3 ++- src/helpers/CommonCLI.cpp | 25 +++++++++++++++++++++++-- src/helpers/CommonCLI.h | 1 + 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 261184c5..eb561939 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -52,6 +52,7 @@ #define RESP_SERVER_LOGIN_OK 0 // response to ANON_REQ #define ANON_REQ_TYPE_REGIONS 0x01 +#define ANON_REQ_TYPE_VER_OWNER 0x02 #define CLI_REPLY_DELAY_MILLIS 600 @@ -142,7 +143,7 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr } uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { - if (regions_limiter.allow(rtc_clock.getCurrentTime())) { + if (anon_limiter.allow(rtc_clock.getCurrentTime())) { // request data has: {reply-path-len}{reply-path} reply_path_len = *data++ & 0x3F; memcpy(reply_path, data, reply_path_len); @@ -159,6 +160,26 @@ uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t send return 0; } +uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { + if (anon_limiter.allow(rtc_clock.getCurrentTime())) { + // request data has: {reply-path-len}{reply-path} + reply_path_len = *data++ & 0x3F; + memcpy(reply_path, data, reply_path_len); + // data += reply_path_len; + // other params?? + + memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag + + uint32_t now = getRTCClock()->getCurrentTime(); + memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, if this is a trusted node) + + sprintf((char *) &reply_data[8], "%s,%s", FIRMWARE_VERSION, _prefs.owner_info); + + return 8 + strlen((char *) &reply_data[8]); // reply length + } + return 0; +} + int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t *payload, size_t payload_len) { // uint32_t now = getRTCClock()->getCurrentTimeUnique(); // memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp @@ -474,6 +495,8 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m reply_len = handleLoginReq(sender, secret, timestamp, &data[4], packet->isRouteFlood()); } else if (data[4] == ANON_REQ_TYPE_REGIONS && packet->isRouteDirect()) { reply_len = handleAnonRegionsReq(sender, timestamp, &data[5]); + } else if (data[4] == ANON_REQ_TYPE_VER_OWNER && packet->isRouteDirect()) { + reply_len = handleAnonVerOwnerReq(sender, timestamp, &data[5]); } else { reply_len = 0; // unknown/invalid request type } @@ -694,7 +717,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc : mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables), _cli(board, rtc, sensors, &_prefs, this), telemetry(MAX_PACKET_PAYLOAD - 4), region_map(key_store), temp_map(key_store), discover_limiter(4, 120), // max 4 every 2 minutes - regions_limiter(4, 180) // max 4 every 3 minutes + anon_limiter(4, 180) // max 4 every 3 minutes #if defined(WITH_RS232_BRIDGE) , bridge(&_prefs, WITH_RS232_BRIDGE, _mgr, &rtc) #endif diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index 49952770..f63aee24 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -95,7 +95,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { RegionMap region_map, temp_map; RegionEntry* load_stack[8]; RegionEntry* recv_pkt_region; - RateLimiter discover_limiter, regions_limiter; + RateLimiter discover_limiter, anon_limiter; bool region_load_active; unsigned long dirty_contacts_expiry; #if MAX_NEIGHBOURS @@ -117,6 +117,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { void putNeighbour(const mesh::Identity& id, uint32_t timestamp, float snr); uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood); uint8_t handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data); + uint8_t handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data); int handleRequest(ClientInfo* sender, uint32_t sender_timestamp, uint8_t* payload, size_t payload_len); mesh::Packet* createSelfAdvert(); diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 78e1b5e0..14b67b39 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -72,7 +72,8 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) { file.read((uint8_t *)&_prefs->advert_loc_policy, sizeof (_prefs->advert_loc_policy)); // 161 file.read((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162 file.read((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166 - // 170 + file.read((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170 + // 290 // sanitise bad pref values _prefs->rx_delay_base = constrain(_prefs->rx_delay_base, 0, 20.0f); @@ -155,7 +156,8 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) { file.write((uint8_t *)&_prefs->advert_loc_policy, sizeof(_prefs->advert_loc_policy)); // 161 file.write((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162 file.write((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166 - // 170 + file.write((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170 + // 290 file.close(); } @@ -301,6 +303,15 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch sprintf(reply, "> %d", (uint32_t)_prefs->flood_max); } else if (memcmp(config, "direct.txdelay", 14) == 0) { sprintf(reply, "> %s", StrHelper::ftoa(_prefs->direct_tx_delay_factor)); + } else if (memcmp(config, "owner.info", 10) == 0) { + *reply++ = '>'; + *reply++ = ' '; + const char* sp = _prefs->owner_info; + while (*sp) { + *reply++ = (*sp == '\n') ? '|' : *sp; // translate newline back to orig '|' + sp++; + } + *reply = 0; // set null terminator } else if (memcmp(config, "tx", 2) == 0 && (config[2] == 0 || config[2] == ' ')) { sprintf(reply, "> %d", (uint32_t) _prefs->tx_power_dbm); } else if (memcmp(config, "freq", 4) == 0) { @@ -479,6 +490,16 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch } else { strcpy(reply, "Error, cannot be negative"); } + } else if (memcmp(config, "owner.info ", 11) == 0) { + config += 11; + char *dp = _prefs->owner_info; + while (*config && dp - _prefs->owner_info < sizeof(_prefs->owner_info)-1) { + *dp++ = (*config == '|') ? '\n' : *config; // translate '|' to newline chars + config++; + } + *dp = 0; + savePrefs(); + strcpy(reply, "OK"); } else if (memcmp(config, "tx ", 3) == 0) { _prefs->tx_power_dbm = atoi(&config[3]); savePrefs(); diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index 642a4cce..3b1d05f9 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -50,6 +50,7 @@ struct NodePrefs { // persisted to file uint8_t advert_loc_policy; uint32_t discovery_mod_timestamp; float adc_multiplier; + char owner_info[120]; }; class CommonCLICallbacks { From 2a035ad8167f03901ff064d637b7ae714c57bcd2 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Fri, 9 Jan 2026 13:20:20 +1100 Subject: [PATCH 16/33] * ANON_REQ_TYPE_VER_OWNER, now includes node_name --- examples/simple_repeater/MyMesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index eb561939..d86e97bc 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -173,7 +173,7 @@ uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sen uint32_t now = getRTCClock()->getCurrentTime(); memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, if this is a trusted node) - sprintf((char *) &reply_data[8], "%s,%s", FIRMWARE_VERSION, _prefs.owner_info); + sprintf((char *) &reply_data[8], "%s,%s,%s", FIRMWARE_VERSION, _prefs.node_name, _prefs.owner_info); return 8 + strlen((char *) &reply_data[8]); // reply length } From fd69acb4212fef2ad955860de4a9955e309ce4d2 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Fri, 9 Jan 2026 13:54:18 +1100 Subject: [PATCH 17/33] * new ANON_REQ_TYPE_VER (for just simple clock + ver info) --- examples/simple_repeater/MyMesh.cpp | 29 ++++++++++++++++++++++------- examples/simple_repeater/MyMesh.h | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index d86e97bc..38f81ff9 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -53,6 +53,7 @@ #define ANON_REQ_TYPE_REGIONS 0x01 #define ANON_REQ_TYPE_VER_OWNER 0x02 +#define ANON_REQ_TYPE_VER 0x03 #define CLI_REPLY_DELAY_MILLIS 600 @@ -148,12 +149,10 @@ uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t send reply_path_len = *data++ & 0x3F; memcpy(reply_path, data, reply_path_len); // data += reply_path_len; - // other params?? memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag - uint32_t now = getRTCClock()->getCurrentTime(); - memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, if this is a trusted node) + memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, and packet hash uniqueness) return 8 + region_map.exportNamesTo((char *) &reply_data[8], sizeof(reply_data) - 12, REGION_DENY_FLOOD); // reply length } @@ -166,13 +165,10 @@ uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sen reply_path_len = *data++ & 0x3F; memcpy(reply_path, data, reply_path_len); // data += reply_path_len; - // other params?? memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag - uint32_t now = getRTCClock()->getCurrentTime(); - memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, if this is a trusted node) - + memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, and packet hash uniqueness) sprintf((char *) &reply_data[8], "%s,%s,%s", FIRMWARE_VERSION, _prefs.node_name, _prefs.owner_info); return 8 + strlen((char *) &reply_data[8]); // reply length @@ -180,6 +176,23 @@ uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sen return 0; } +uint8_t MyMesh::handleAnonVerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { + if (anon_limiter.allow(rtc_clock.getCurrentTime())) { + // request data has: {reply-path-len}{reply-path} + reply_path_len = *data++ & 0x3F; + memcpy(reply_path, data, reply_path_len); + // data += reply_path_len; + + memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag + uint32_t now = getRTCClock()->getCurrentTime(); + memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, and packet hash uniqueness) + strcpy((char *) &reply_data[8], FIRMWARE_VERSION); + + return 8 + strlen((char *) &reply_data[8]); // reply length + } + return 0; +} + int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t *payload, size_t payload_len) { // uint32_t now = getRTCClock()->getCurrentTimeUnique(); // memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp @@ -497,6 +510,8 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m reply_len = handleAnonRegionsReq(sender, timestamp, &data[5]); } else if (data[4] == ANON_REQ_TYPE_VER_OWNER && packet->isRouteDirect()) { reply_len = handleAnonVerOwnerReq(sender, timestamp, &data[5]); + } else if (data[4] == ANON_REQ_TYPE_VER && packet->isRouteDirect()) { + reply_len = handleAnonVerReq(sender, timestamp, &data[5]); } else { reply_len = 0; // unknown/invalid request type } diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index f63aee24..96a51da8 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -118,6 +118,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood); uint8_t handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data); uint8_t handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data); + uint8_t handleAnonVerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data); int handleRequest(ClientInfo* sender, uint32_t sender_timestamp, uint8_t* payload, size_t payload_len); mesh::Packet* createSelfAdvert(); From 65796c8f2043dd2a3bc4327dfe091304ccbe6945 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Fri, 9 Jan 2026 16:28:08 +1100 Subject: [PATCH 18/33] * CommonCLI: added "set name ..." validation * ANON_REQ_TYPE_VER_OWNER, now removes commas from node_name --- examples/simple_repeater/MyMesh.cpp | 13 ++++++++++++- src/helpers/CommonCLI.cpp | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 38f81ff9..c50d860f 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -159,6 +159,14 @@ uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t send return 0; } +static void sanitiseName(char* dest, const char* src) { + while (*src) { + *dest++ = (*src == ',') ? ' ' : *src; + src++; + } + *dest = 0; +} + uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { if (anon_limiter.allow(rtc_clock.getCurrentTime())) { // request data has: {reply-path-len}{reply-path} @@ -166,10 +174,13 @@ uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sen memcpy(reply_path, data, reply_path_len); // data += reply_path_len; + char tmp[sizeof(_prefs.node_name)]; + sanitiseName(tmp, _prefs.node_name); + memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag uint32_t now = getRTCClock()->getCurrentTime(); memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, and packet hash uniqueness) - sprintf((char *) &reply_data[8], "%s,%s,%s", FIRMWARE_VERSION, _prefs.node_name, _prefs.owner_info); + sprintf((char *) &reply_data[8], "%s,%s,%s", FIRMWARE_VERSION, tmp, _prefs.owner_info); return 8 + strlen((char *) &reply_data[8]); // reply length } diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 14b67b39..2fc93006 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -14,6 +14,14 @@ static uint32_t _atoi(const char* sp) { return n; } +static bool isValidName(const char *n) { + while (*n) { + if (*n == '[' || *n == ']' || *n == '/' || *n == '\\' || *n == ':' || *n == ',' || *n == '?' || *n == '*') return false; + n++; + } + return true; +} + void CommonCLI::loadPrefs(FILESYSTEM* fs) { if (fs->exists("/com_prefs")) { loadPrefsInt(fs, "/com_prefs"); // new filename @@ -421,9 +429,13 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch strcpy(reply, "Error, invalid key"); } } else if (memcmp(config, "name ", 5) == 0) { - StrHelper::strncpy(_prefs->node_name, &config[5], sizeof(_prefs->node_name)); - savePrefs(); - strcpy(reply, "OK"); + if (isValidName(&config[5])) { + StrHelper::strncpy(_prefs->node_name, &config[5], sizeof(_prefs->node_name)); + savePrefs(); + strcpy(reply, "OK"); + } else { + strcpy(reply, "Error, bad chars"); + } } else if (memcmp(config, "repeat ", 7) == 0) { _prefs->disable_fwd = memcmp(&config[7], "off", 3) == 0; savePrefs(); From 4e4f6d92a0fced540cded8fd7866a4fe4e1b2557 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Fri, 9 Jan 2026 16:32:08 +1100 Subject: [PATCH 19/33] * ANON_REQ_TYPE_VER_OWNER now delimited by newline chars --- examples/simple_repeater/MyMesh.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index c50d860f..d504fec9 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -159,14 +159,6 @@ uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t send return 0; } -static void sanitiseName(char* dest, const char* src) { - while (*src) { - *dest++ = (*src == ',') ? ' ' : *src; - src++; - } - *dest = 0; -} - uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { if (anon_limiter.allow(rtc_clock.getCurrentTime())) { // request data has: {reply-path-len}{reply-path} @@ -174,13 +166,10 @@ uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sen memcpy(reply_path, data, reply_path_len); // data += reply_path_len; - char tmp[sizeof(_prefs.node_name)]; - sanitiseName(tmp, _prefs.node_name); - memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag uint32_t now = getRTCClock()->getCurrentTime(); memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, and packet hash uniqueness) - sprintf((char *) &reply_data[8], "%s,%s,%s", FIRMWARE_VERSION, tmp, _prefs.owner_info); + sprintf((char *) &reply_data[8], "%s\n%s\n%s", FIRMWARE_VERSION, _prefs.node_name, _prefs.owner_info); return 8 + strlen((char *) &reply_data[8]); // reply length } From b6110eee38b2c7b80b36f54186095430e975bc83 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Mon, 12 Jan 2026 16:58:35 +1100 Subject: [PATCH 20/33] * new req/resp (after login): REQ_TYPE_GET_OWNER_INFO (includes firmware-ver) * ANON_REQ_TYPE_OWNER, firmware-ver removed (security exploit) * ANON_REQ_TYPE_BASIC, formware-ver removed, just remote clock + some 'feature' bits * CTL_TYPE_NODE_DISCOVER_REQ now ingored if 'repeat off' has been set --- examples/simple_repeater/MyMesh.cpp | 39 +++++++++++++++++++---------- examples/simple_repeater/MyMesh.h | 4 +-- src/helpers/RegionMap.cpp | 5 ++-- src/helpers/RegionMap.h | 2 +- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index d504fec9..54f3ef79 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -48,12 +48,13 @@ #define REQ_TYPE_GET_TELEMETRY_DATA 0x03 #define REQ_TYPE_GET_ACCESS_LIST 0x05 #define REQ_TYPE_GET_NEIGHBOURS 0x06 +#define REQ_TYPE_GET_OWNER_INFO 0x07 #define RESP_SERVER_LOGIN_OK 0 // response to ANON_REQ #define ANON_REQ_TYPE_REGIONS 0x01 -#define ANON_REQ_TYPE_VER_OWNER 0x02 -#define ANON_REQ_TYPE_VER 0x03 +#define ANON_REQ_TYPE_OWNER 0x02 +#define ANON_REQ_TYPE_BASIC 0x03 // just remote clock #define CLI_REPLY_DELAY_MILLIS 600 @@ -159,7 +160,7 @@ uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t send return 0; } -uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { +uint8_t MyMesh::handleAnonOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { if (anon_limiter.allow(rtc_clock.getCurrentTime())) { // request data has: {reply-path-len}{reply-path} reply_path_len = *data++ & 0x3F; @@ -169,14 +170,14 @@ uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sen memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag uint32_t now = getRTCClock()->getCurrentTime(); memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, and packet hash uniqueness) - sprintf((char *) &reply_data[8], "%s\n%s\n%s", FIRMWARE_VERSION, _prefs.node_name, _prefs.owner_info); + sprintf((char *) &reply_data[8], "%s\n%s", _prefs.node_name, _prefs.owner_info); return 8 + strlen((char *) &reply_data[8]); // reply length } return 0; } -uint8_t MyMesh::handleAnonVerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { +uint8_t MyMesh::handleAnonClockReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { if (anon_limiter.allow(rtc_clock.getCurrentTime())) { // request data has: {reply-path-len}{reply-path} reply_path_len = *data++ & 0x3F; @@ -186,9 +187,16 @@ uint8_t MyMesh::handleAnonVerReq(const mesh::Identity& sender, uint32_t sender_t memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag uint32_t now = getRTCClock()->getCurrentTime(); memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, and packet hash uniqueness) - strcpy((char *) &reply_data[8], FIRMWARE_VERSION); - - return 8 + strlen((char *) &reply_data[8]); // reply length + reply_data[8] = 0; // features +#ifdef WITH_RS232_BRIDGE + reply_data[8] |= 0x01; // is bridge, type UART +#elif WITH_ESPNOW_BRIDGE + reply_data[8] |= 0x03; // is bridge, type ESP-NOW +#endif + if (_prefs.disable_fwd) { // is this repeater currently disabled + reply_data[8] |= 0x80; // is disabled + } + return 9; // reply length } return 0; } @@ -350,6 +358,9 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t return reply_offset; } + } else if (payload[0] == REQ_TYPE_GET_OWNER_INFO) { + sprintf((char *) &reply_data[4], "%s\n%s", FIRMWARE_VERSION, _prefs.owner_info); + return 4 + strlen((char *) &reply_data[4]); } return 0; // unknown command } @@ -508,10 +519,10 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m reply_len = handleLoginReq(sender, secret, timestamp, &data[4], packet->isRouteFlood()); } else if (data[4] == ANON_REQ_TYPE_REGIONS && packet->isRouteDirect()) { reply_len = handleAnonRegionsReq(sender, timestamp, &data[5]); - } else if (data[4] == ANON_REQ_TYPE_VER_OWNER && packet->isRouteDirect()) { - reply_len = handleAnonVerOwnerReq(sender, timestamp, &data[5]); - } else if (data[4] == ANON_REQ_TYPE_VER && packet->isRouteDirect()) { - reply_len = handleAnonVerReq(sender, timestamp, &data[5]); + } else if (data[4] == ANON_REQ_TYPE_OWNER && packet->isRouteDirect()) { + reply_len = handleAnonOwnerReq(sender, timestamp, &data[5]); + } else if (data[4] == ANON_REQ_TYPE_BASIC && packet->isRouteDirect()) { + reply_len = handleAnonClockReq(sender, timestamp, &data[5]); } else { reply_len = 0; // unknown/invalid request type } @@ -700,7 +711,9 @@ bool MyMesh::onPeerPathRecv(mesh::Packet *packet, int sender_idx, const uint8_t void MyMesh::onControlDataRecv(mesh::Packet* packet) { uint8_t type = packet->payload[0] & 0xF0; // just test upper 4 bits - if (type == CTL_TYPE_NODE_DISCOVER_REQ && packet->payload_len >= 6 && discover_limiter.allow(rtc_clock.getCurrentTime())) { + if (type == CTL_TYPE_NODE_DISCOVER_REQ && packet->payload_len >= 6 + && !_prefs.disable_fwd && discover_limiter.allow(rtc_clock.getCurrentTime()) + ) { int i = 1; uint8_t filter = packet->payload[i++]; uint32_t tag; diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index 96a51da8..f930ee7e 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -117,8 +117,8 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { void putNeighbour(const mesh::Identity& id, uint32_t timestamp, float snr); uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood); uint8_t handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data); - uint8_t handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data); - uint8_t handleAnonVerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data); + uint8_t handleAnonOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data); + uint8_t handleAnonClockReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data); int handleRequest(ClientInfo* sender, uint32_t sender_timestamp, uint8_t* payload, size_t payload_len); mesh::Packet* createSelfAdvert(); diff --git a/src/helpers/RegionMap.cpp b/src/helpers/RegionMap.cpp index e227532a..fbc5f017 100644 --- a/src/helpers/RegionMap.cpp +++ b/src/helpers/RegionMap.cpp @@ -9,8 +9,9 @@ RegionMap::RegionMap(TransportKeyStore& store) : _store(&store) { strcpy(wildcard.name, "*"); } -bool RegionMap::is_name_char(char c) { - return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '.' || c == '_' || c == '#'; +bool RegionMap::is_name_char(uint8_t c) { + // accept all alpha-num or accented characters, but exclude most punctuation chars + return c == '-' || c == '#' || (c >= '0' && c <= '9') || c >= 'A'; } static File openWrite(FILESYSTEM* _fs, const char* filename) { diff --git a/src/helpers/RegionMap.h b/src/helpers/RegionMap.h index dcd9a774..01174d09 100644 --- a/src/helpers/RegionMap.h +++ b/src/helpers/RegionMap.h @@ -30,7 +30,7 @@ class RegionMap { public: RegionMap(TransportKeyStore& store); - static bool is_name_char(char c); + static bool is_name_char(uint8_t c); bool load(FILESYSTEM* _fs, const char* path=NULL); bool save(FILESYSTEM* _fs, const char* path=NULL); From 69a71d0e25b956e70d33ada889ff0580d6dbb060 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Mon, 12 Jan 2026 17:47:51 +1100 Subject: [PATCH 21/33] * repeater login response, FIRMWARE_VER_LEVEL now bumped to 2 --- docs/payloads.md | 53 ++++++++++++++++++++++++++++- examples/simple_repeater/MyMesh.cpp | 7 ++-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/docs/payloads.md b/docs/payloads.md index 5a41e69c..4742bfbb 100644 --- a/docs/payloads.md +++ b/docs/payloads.md @@ -103,7 +103,9 @@ Request type | `0x02` | keepalive | (deprecated) | | `0x03` | get telemetry data | TODO | | `0x04` | get min,max,avg data | sensor nodes - get min, max, average for given time span | -| `0x05` | get access list | get node's approved access list | +| `0x05` | get access list | get node's approved access list | +| `0x06` | get neighbors | get repeater node's neighbors | +| `0x07` | get owner info | get repeater firmware-ver/name/owner info | ### Get stats @@ -132,6 +134,27 @@ Gets information about the node, possibly including the following: Request data about sensors on the node, including battery level. +### Get Telemetry + +TODO + +### Get Min/Max/Ave (Sensor nodes) + +TODO + +### Get Access List + +TODO + +### Get Neighors + +TODO + +### Get Owner Info + +TODO + + ## Response | Field | Size (bytes) | Description | @@ -179,6 +202,34 @@ txt_type | timestamp | 4 | sender time (unix timestamp) | | password | rest of message | password for repeater/sensor | +## Repeater - Regions request + +| Field | Size (bytes) | Description | +|----------------|-----------------|-------------------------------------------------------------------------------| +| timestamp | 4 | sender time (unix timestamp) | +| req type | 1 | 0x01 (request sub type) | +| reply path len | 1 | path len for reply | +| reply path | (variable) | reply path | + +## Repeater - Owner info request + +| Field | Size (bytes) | Description | +|----------------|-----------------|-------------------------------------------------------------------------------| +| timestamp | 4 | sender time (unix timestamp) | +| req type | 1 | 0x02 (request sub type) | +| reply path len | 1 | path len for reply | +| reply path | (variable) | reply path | + +## Repeater - Clock and status request + +| Field | Size (bytes) | Description | +|----------------|-----------------|-------------------------------------------------------------------------------| +| timestamp | 4 | sender time (unix timestamp) | +| req type | 1 | 0x03 (request sub type) | +| reply path len | 1 | path len for reply | +| reply path | (variable) | reply path | + + # Group text message / datagram | Field | Size (bytes) | Description | diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 54f3ef79..d926148d 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -41,14 +41,14 @@ #define TXT_ACK_DELAY 200 #endif -#define FIRMWARE_VER_LEVEL 1 +#define FIRMWARE_VER_LEVEL 2 #define REQ_TYPE_GET_STATUS 0x01 // same as _GET_STATS #define REQ_TYPE_KEEP_ALIVE 0x02 #define REQ_TYPE_GET_TELEMETRY_DATA 0x03 #define REQ_TYPE_GET_ACCESS_LIST 0x05 #define REQ_TYPE_GET_NEIGHBOURS 0x06 -#define REQ_TYPE_GET_OWNER_INFO 0x07 +#define REQ_TYPE_GET_OWNER_INFO 0x07 // FIRMWARE_VER_LEVEL >= 2 #define RESP_SERVER_LOGIN_OK 0 // response to ANON_REQ @@ -196,6 +196,7 @@ uint8_t MyMesh::handleAnonClockReq(const mesh::Identity& sender, uint32_t sender if (_prefs.disable_fwd) { // is this repeater currently disabled reply_data[8] |= 0x80; // is disabled } + // TODO: add some kind of moving-window utilisation metric, so can query 'how busy' is this repeater return 9; // reply length } return 0; @@ -359,7 +360,7 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t return reply_offset; } } else if (payload[0] == REQ_TYPE_GET_OWNER_INFO) { - sprintf((char *) &reply_data[4], "%s\n%s", FIRMWARE_VERSION, _prefs.owner_info); + sprintf((char *) &reply_data[4], "%s\n%s\n%s", FIRMWARE_VERSION, _prefs.node_name, _prefs.owner_info); return 4 + strlen((char *) &reply_data[4]); } return 0; // unknown command From 266e4893fda2b42e8e7e5f08239a827a13ef26dd Mon Sep 17 00:00:00 2001 From: Rastislav Vysoky Date: Mon, 12 Jan 2026 19:19:23 +0100 Subject: [PATCH 22/33] remove serial debug logging from t3s3 sx1276 companion usb --- variants/lilygo_t3s3_sx1276/platformio.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/variants/lilygo_t3s3_sx1276/platformio.ini b/variants/lilygo_t3s3_sx1276/platformio.ini index f544be11..5a7ece2c 100644 --- a/variants/lilygo_t3s3_sx1276/platformio.ini +++ b/variants/lilygo_t3s3_sx1276/platformio.ini @@ -138,8 +138,6 @@ build_flags = -D DISPLAY_CLASS=SSD1306Display -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 - -D MESH_PACKET_LOGGING=1 - -D MESH_DEBUG=1 build_src_filter = ${LilyGo_T3S3_sx1276.build_src_filter} + + From 324eab93948868dd4d5c86bb23117d243e58f3e3 Mon Sep 17 00:00:00 2001 From: Rastislav Vysoky Date: Mon, 12 Jan 2026 19:29:32 +0100 Subject: [PATCH 23/33] cleanup ikoka variants and add all supported sensors --- variants/ikoka_handheld_nrf/platformio.ini | 48 +++++----- variants/ikoka_nano_nrf/platformio.ini | 104 +++++++-------------- variants/ikoka_stick_nrf/platformio.ini | 84 ++++++----------- 3 files changed, 90 insertions(+), 146 deletions(-) diff --git a/variants/ikoka_handheld_nrf/platformio.ini b/variants/ikoka_handheld_nrf/platformio.ini index e4643c38..d2bbeffe 100644 --- a/variants/ikoka_handheld_nrf/platformio.ini +++ b/variants/ikoka_handheld_nrf/platformio.ini @@ -1,8 +1,5 @@ -[ikoka_nrf52] -extends = Xiao_nrf52 -lib_deps = ${nrf52_base.lib_deps} - ${sensor_base.lib_deps} - densaugeo/base64 @ ~1.4.0 +[ikoka_handheld_nrf] +extends = nrf52_base build_flags = ${nrf52_base.build_flags} ${sensor_base.build_flags} -I lib/nrf52/s140_nrf52_7.3.0_API/include @@ -26,12 +23,15 @@ build_flags = ${nrf52_base.build_flags} build_src_filter = ${nrf52_base.build_src_filter} +<../variants/ikoka_handheld_nrf> + +lib_deps = ${nrf52_base.lib_deps} + ${sensor_base.lib_deps} + densaugeo/base64 @ ~1.4.0 # larger screen has a different driver, this is for the 0.96 inch -[ikoka_nrf52_ssd1306_companion] -lib_deps = ${ikoka_nrf52.lib_deps} +[ikoka_handheld_nrf_ssd1306_companion] +lib_deps = ${ikoka_handheld_nrf.lib_deps} adafruit/Adafruit SSD1306 @ ^2.5.13 -build_flags = ${ikoka_nrf52.build_flags} +build_flags = ${ikoka_handheld_nrf.build_flags} -D DISPLAY_CLASS=SSD1306Display -D DISPLAY_ROTATION=0 -D PIN_WIRE_SCL=D6 @@ -42,62 +42,62 @@ build_flags = ${ikoka_nrf52.build_flags} -D OFFLINE_QUEUE_SIZE=256 -D QSPIFLASH=1 -I examples/companion_radio/ui-new -build_src_filter = ${ikoka_nrf52.build_src_filter} +build_src_filter = ${ikoka_handheld_nrf.build_src_filter} + +<../examples/companion_radio/ui-new/UITask.cpp> +<../examples/companion_radio/*.cpp> [env:ikoka_handheld_nrf_e22_30dbm_096_companion_radio_ble] extends = ikoka_nrf52 -build_flags = ${ikoka_nrf52_ssd1306_companion.build_flags} +build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags} -D BLE_PIN_CODE=123456 -D LORA_TX_POWER=20 -build_src_filter = ${ikoka_nrf52_ssd1306_companion.build_src_filter} +build_src_filter = ${ikoka_handheld_nrf_ssd1306_companion.build_src_filter} + [env:ikoka_handheld_nrf_e22_30dbm_096_rotated_companion_radio_ble] extends = ikoka_nrf52 -build_flags = ${ikoka_nrf52_ssd1306_companion.build_flags} +build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags} -D BLE_PIN_CODE=123456 -D LORA_TX_POWER=20 - -D DISPLAY_ROTATION=2 -build_src_filter = ${ikoka_nrf52_ssd1306_companion.build_src_filter} + -D DISPLAY_ROTATION=2 +build_src_filter = ${ikoka_handheld_nrf_ssd1306_companion.build_src_filter} + [env:ikoka_handheld_nrf_e22_30dbm_096_companion_radio_usb] extends = ikoka_nrf52 -build_flags = ${ikoka_nrf52_ssd1306_companion.build_flags} +build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags} -D LORA_TX_POWER=20 -build_src_filter = ${ikoka_nrf52_ssd1306_companion.build_src_filter} +build_src_filter = ${ikoka_handheld_nrf_ssd1306_companion.build_src_filter} [env:ikoka_handheld_nrf_e22_30dbm_096_rotated_companion_radio_usb] extends = ikoka_nrf52 -build_flags = ${ikoka_nrf52_ssd1306_companion.build_flags} +build_flags = ${ikoka_handheld_nrf_ssd1306_companion.build_flags} -D LORA_TX_POWER=20 -D DISPLAY_ROTATION=2 -build_src_filter = ${ikoka_nrf52_ssd1306_companion.build_src_filter} +build_src_filter = ${ikoka_handheld_nrf_ssd1306_companion.build_src_filter} [env:ikoka_handheld_nrf_e22_30dbm_repeater] extends = ikoka_nrf52 build_flags = - ${ikoka_nrf52.build_flags} + ${ikoka_handheld_nrf.build_flags} -D ADVERT_NAME='"ikoka_handheld Repeater"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' -D MAX_NEIGHBOURS=50 - -D LORA_TX_POWER=20 -build_src_filter = ${ikoka_nrf52.build_src_filter} + -D LORA_TX_POWER=20 +build_src_filter = ${ikoka_handheld_nrf.build_src_filter} +<../examples/simple_repeater/*.cpp> [env:ikoka_handheld_nrf_e22_30dbm_room_server] extends = ikoka_nrf52 build_flags = - ${ikoka_nrf52.build_flags} + ${ikoka_handheld_nrf.build_flags} -D ADVERT_NAME='"ikoka_handheld Room"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' - -D LORA_TX_POWER=20 -build_src_filter = ${ikoka_nrf52.build_src_filter} + -D LORA_TX_POWER=20 +build_src_filter = ${ikoka_handheld_nrf.build_src_filter} +<../examples/simple_room_server/*.cpp> diff --git a/variants/ikoka_nano_nrf/platformio.ini b/variants/ikoka_nano_nrf/platformio.ini index abfbcf67..08b1101b 100644 --- a/variants/ikoka_nano_nrf/platformio.ini +++ b/variants/ikoka_nano_nrf/platformio.ini @@ -1,151 +1,124 @@ -[nrf52840_xiao] +[ikoka_nano_nrf] extends = nrf52_base -platform_packages = - toolchain-gccarmnoneeabi@~1.100301.0 - framework-arduinoadafruitnrf52 board = seeed-xiao-afruitnrf52-nrf52840 board_build.ldscript = boards/nrf52840_s140_v7.ld build_flags = ${nrf52_base.build_flags} + ${sensor_base.build_flags} -D NRF52_PLATFORM -D XIAO_NRF52 -I lib/nrf52/s140_nrf52_7.3.0_API/include -I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52 -lib_ignore = - BluetoothOTA - lvgl - lib5b4 -lib_deps = - ${nrf52_base.lib_deps} - rweather/Crypto @ ^0.4.0 - adafruit/Adafruit INA3221 Library @ ^1.0.1 - adafruit/Adafruit INA219 @ ^1.2.3 - adafruit/Adafruit AHTX0 @ ^2.0.5 - adafruit/Adafruit BME280 Library @ ^2.3.0 - adafruit/Adafruit SSD1306 @ ^2.5.13 - -[ikoka_nano_nrf_baseboard] -extends = nrf52840_xiao -;board_build.ldscript = boards/nrf52840_s140_v7.ld -build_flags = ${nrf52840_xiao.build_flags} - -D P_LORA_TX_LED=11 -I variants/ikoka_nano_nrf -I src/helpers/nrf52 + -D P_LORA_TX_LED=11 -D DISPLAY_CLASS=NullDisplayDriver -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper -D P_LORA_DIO_1=D1 -; -D P_LORA_BUSY=D3 - -D P_LORA_BUSY=D2 ; specific to ikoka nano variant. -; -D P_LORA_RESET=D2 - -D P_LORA_RESET=D3 ; specific to ikoka nano variant. -; -D P_LORA_NSS=D4 - -D P_LORA_NSS=D0 ; specific to ikoka nano variant. -; -D SX126X_RXEN=D5 + -D P_LORA_BUSY=D2 + -D P_LORA_RESET=D3 + -D P_LORA_NSS=D0 -D SX126X_RXEN=D7 -D SX126X_TXEN=RADIOLIB_NC -D SX126X_DIO2_AS_RF_SWITCH=1 -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=140 -D SX126X_RX_BOOSTED_GAIN=1 - -D PIN_WIRE_SCL=5 ; specific to ikoka nano variant. - -D PIN_WIRE_SDA=4 ; specific to ikoka nano variant. - -D ENV_INCLUDE_AHTX0=1 - -D ENV_INCLUDE_BME280=1 - -D ENV_INCLUDE_INA3221=1 - -D ENV_INCLUDE_INA219=1 + -D PIN_WIRE_SCL=5 + -D PIN_WIRE_SDA=4 + -UENV_INCLUDE_GPS debug_tool = jlink upload_protocol = nrfutil - - -;;; abstracted hardware variants +lib_deps = ${nrf52_base.lib_deps} + ${sensor_base.lib_deps} [ikoka_nano_nrf_e22_22dbm] -extends = ikoka_nano_nrf_baseboard +extends = ikoka_nano_nrf ; No PA in this model, full 22dBm build_flags = - ${ikoka_nano_nrf_baseboard.build_flags} + ${ikoka_nano_nrf.build_flags} -D MANUFACTURER_STRING='"Ikoka Nano-E22-22dBm (Xiao_nrf52)"' -D LORA_TX_POWER=22 -build_src_filter = ${nrf52840_xiao.build_src_filter} +build_src_filter = ${ikoka_nano_nrf.build_src_filter} + + + +<../variants/ikoka_nano_nrf> [ikoka_nano_nrf_e22_30dbm] -extends = ikoka_nano_nrf_baseboard +extends = ikoka_nano_nrf ; limit txpower to 20dBm on E22-900M30S. Anything higher will ; cause distortion in the PA output. 20dBm in -> 30dBm out build_flags = - ${ikoka_nano_nrf_baseboard.build_flags} + ${ikoka_nano_nrf.build_flags} -D MANUFACTURER_STRING='"Ikoka Nano-E22-30dBm (Xiao_nrf52)"' -D LORA_TX_POWER=20 -build_src_filter = ${nrf52840_xiao.build_src_filter} +build_src_filter = ${ikoka_nano_nrf.build_src_filter} + + + +<../variants/ikoka_nano_nrf> [ikoka_nano_nrf_e22_33dbm] -extends = ikoka_nano_nrf_baseboard +extends = ikoka_nano_nrf ; limit txpower to 9dBm on E22-900M33S to avoid hardware damage ; to the rf amplifier frontend. 9dBm in -> 33dBm out build_flags = - ${ikoka_nano_nrf_baseboard.build_flags} + ${ikoka_nano_nrf.build_flags} -D MANUFACTURER_STRING='"Ikoka Nano-E22-33dBm (Xiao_nrf52)"' -D LORA_TX_POWER=9 -build_src_filter = ${nrf52840_xiao.build_src_filter} +build_src_filter = ${ikoka_nano_nrf.build_src_filter} + + + +<../variants/ikoka_nano_nrf> -;;; abstracted firmware roles - [ikoka_nano_nrf_companion_radio_ble] -extends = ikoka_nano_nrf_baseboard +extends = ikoka_nano_nrf board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld board_upload.maximum_size = 708608 build_flags = - ${ikoka_nano_nrf_baseboard.build_flags} + ${ikoka_nano_nrf.build_flags} -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 -D OFFLINE_QUEUE_SIZE=256 -I examples/companion_radio/ui-new + -D QSPIFLASH=1 ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${ikoka_nano_nrf_baseboard.build_src_filter} +build_src_filter = ${ikoka_nano_nrf.build_src_filter} + +<../examples/companion_radio/*.cpp> +<../examples/companion_radio/ui-new/*.cpp> lib_deps = - ${ikoka_nano_nrf_baseboard.lib_deps} + ${ikoka_nano_nrf.lib_deps} densaugeo/base64 @ ~1.4.0 [ikoka_nano_nrf_companion_radio_usb] -extends = ikoka_nano_nrf_baseboard +extends = ikoka_nano_nrf board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld board_upload.maximum_size = 708608 build_flags = - ${ikoka_nano_nrf_baseboard.build_flags} + ${ikoka_nano_nrf.build_flags} -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -I examples/companion_radio/ui-new + -D QSPIFLASH=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${ikoka_nano_nrf_baseboard.build_src_filter} +build_src_filter = ${ikoka_nano_nrf.build_src_filter} + +<../examples/companion_radio/*.cpp> +<../examples/companion_radio/ui-new/*.cpp> lib_deps = - ${ikoka_nano_nrf_baseboard.lib_deps} + ${ikoka_nano_nrf.lib_deps} densaugeo/base64 @ ~1.4.0 [ikoka_nano_nrf_repeater] -extends = ikoka_nano_nrf_baseboard +extends = ikoka_nano_nrf build_flags = - ${ikoka_nano_nrf_baseboard.build_flags} + ${ikoka_nano_nrf.build_flags} -D ADVERT_NAME='"Ikoka Nano Repeater"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 @@ -153,26 +126,23 @@ build_flags = -D MAX_NEIGHBOURS=50 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${ikoka_nano_nrf_baseboard.build_src_filter} +build_src_filter = ${ikoka_nano_nrf.build_src_filter} +<../examples/simple_repeater/*.cpp> [ikoka_nano_nrf_room_server] -extends = ikoka_nano_nrf_baseboard +extends = ikoka_nano_nrf build_flags = - ${ikoka_nano_nrf_baseboard.build_flags} + ${ikoka_nano_nrf.build_flags} -D ADVERT_NAME='"Ikoka Nano Room"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${ikoka_nano_nrf_baseboard.build_src_filter} +build_src_filter = ${ikoka_nano_nrf.build_src_filter} +<../examples/simple_room_server/*.cpp> -;;; hardware + firmware variants - ;;; 22dBm EBYTE E22-900M22 variants - [env:ikoka_nano_nrf_22dbm_companion_radio_usb] extends = ikoka_nano_nrf_e22_22dbm @@ -219,7 +189,6 @@ build_src_filter = ;;; 30dBm EBYTE E22-900M30 variants - [env:ikoka_nano_nrf_30dbm_companion_radio_usb] extends = ikoka_nano_nrf_e22_30dbm @@ -266,7 +235,6 @@ build_src_filter = ;;; 33dBm EBYTE E22-900M33 variants - [env:ikoka_nano_nrf_33dbm_companion_radio_usb] extends = ikoka_nano_nrf_e22_33dbm diff --git a/variants/ikoka_stick_nrf/platformio.ini b/variants/ikoka_stick_nrf/platformio.ini index 9ced2bbb..4f664054 100644 --- a/variants/ikoka_stick_nrf/platformio.ini +++ b/variants/ikoka_stick_nrf/platformio.ini @@ -1,34 +1,15 @@ -[nrf52840_xiao] +[ikoka_stick_nrf] extends = nrf52_base -platform_packages = - toolchain-gccarmnoneeabi@~1.100301.0 - framework-arduinoadafruitnrf52 board = seeed-xiao-afruitnrf52-nrf52840 board_build.ldscript = boards/nrf52840_s140_v7.ld build_flags = ${nrf52_base.build_flags} + ${sensor_base.build_flags} -D NRF52_PLATFORM -D XIAO_NRF52 -I lib/nrf52/s140_nrf52_7.3.0_API/include -I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52 -lib_ignore = - BluetoothOTA - lvgl - lib5b4 -lib_deps = - ${nrf52_base.lib_deps} - rweather/Crypto @ ^0.4.0 - adafruit/Adafruit INA3221 Library @ ^1.0.1 - adafruit/Adafruit INA219 @ ^1.2.3 - adafruit/Adafruit AHTX0 @ ^2.0.5 - adafruit/Adafruit BME280 Library @ ^2.3.0 - adafruit/Adafruit SSD1306 @ ^2.5.13 - -[ikoka_stick_nrf_baseboard] -extends = nrf52840_xiao -;board_build.ldscript = boards/nrf52840_s140_v7.ld -build_flags = ${nrf52840_xiao.build_flags} - -D P_LORA_TX_LED=11 -I variants/ikoka_stick_nrf -I src/helpers/nrf52 + -D P_LORA_TX_LED=11 -D DISPLAY_CLASS=SSD1306Display -D DISPLAY_ROTATION=2 -D RADIO_CLASS=CustomSX1262 @@ -46,24 +27,17 @@ build_flags = ${nrf52840_xiao.build_flags} -D PIN_USER_BTN=0 -D PIN_WIRE_SCL=7 -D PIN_WIRE_SDA=6 - -D ENV_INCLUDE_AHTX0=1 - -D ENV_INCLUDE_BME280=1 - -D ENV_INCLUDE_INA3221=1 - -D ENV_INCLUDE_INA219=1 -debug_tool = jlink -upload_protocol = nrfutil - - -;;; abstracted hardware variants +lib_deps = ${nrf52_base.lib_deps} + ${sensor_base.lib_deps} [ikoka_stick_nrf_e22_22dbm] -extends = ikoka_stick_nrf_baseboard +extends = ikoka_stick_nrf ; No PA in this model, full 22dBm build_flags = - ${ikoka_stick_nrf_baseboard.build_flags} + ${ikoka_stick_nrf.build_flags} -D MANUFACTURER_STRING='"Ikoka Stick-E22-22dBm (Xiao_nrf52)"' -D LORA_TX_POWER=22 -build_src_filter = ${nrf52840_xiao.build_src_filter} +build_src_filter = ${ikoka_stick_nrf.build_src_filter} + + + @@ -71,14 +45,14 @@ build_src_filter = ${nrf52840_xiao.build_src_filter} +<../variants/ikoka_stick_nrf> [ikoka_stick_nrf_e22_30dbm] -extends = ikoka_stick_nrf_baseboard +extends = ikoka_stick_nrf ; limit txpower to 20dBm on E22-900M30S. Anything higher will ; cause distortion in the PA output. 20dBm in -> 30dBm out build_flags = - ${ikoka_stick_nrf_baseboard.build_flags} + ${ikoka_stick_nrf.build_flags} -D MANUFACTURER_STRING='"Ikoka Stick-E22-30dBm (Xiao_nrf52)"' -D LORA_TX_POWER=20 -build_src_filter = ${nrf52840_xiao.build_src_filter} +build_src_filter = ${ikoka_stick_nrf.build_src_filter} + + + @@ -86,14 +60,14 @@ build_src_filter = ${nrf52840_xiao.build_src_filter} +<../variants/ikoka_stick_nrf> [ikoka_stick_nrf_e22_33dbm] -extends = ikoka_stick_nrf_baseboard +extends = ikoka_stick_nrf ; limit txpower to 9dBm on E22-900M33S to avoid hardware damage ; to the rf amplifier frontend. 9dBm in -> 33dBm out build_flags = - ${ikoka_stick_nrf_baseboard.build_flags} + ${ikoka_stick_nrf.build_flags} -D MANUFACTURER_STRING='"Ikoka Stick-E22-33dBm (Xiao_nrf52)"' -D LORA_TX_POWER=9 -build_src_filter = ${nrf52840_xiao.build_src_filter} +build_src_filter = ${ikoka_stick_nrf.build_src_filter} + + + @@ -103,50 +77,52 @@ build_src_filter = ${nrf52840_xiao.build_src_filter} ;;; abstracted firmware roles [ikoka_stick_nrf_companion_radio_ble] -extends = ikoka_stick_nrf_baseboard +extends = ikoka_stick_nrf board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld board_upload.maximum_size = 708608 build_flags = - ${ikoka_stick_nrf_baseboard.build_flags} + ${ikoka_stick_nrf.build_flags} -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 -D OFFLINE_QUEUE_SIZE=256 -I examples/companion_radio/ui-new + -D QSPIFLASH=1 ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${ikoka_stick_nrf_baseboard.build_src_filter} +build_src_filter = ${ikoka_stick_nrf.build_src_filter} + +<../examples/companion_radio/*.cpp> +<../examples/companion_radio/ui-new/*.cpp> lib_deps = - ${ikoka_stick_nrf_baseboard.lib_deps} + ${ikoka_stick_nrf.lib_deps} densaugeo/base64 @ ~1.4.0 [ikoka_stick_nrf_companion_radio_usb] -extends = ikoka_stick_nrf_baseboard +extends = ikoka_stick_nrf board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld board_upload.maximum_size = 708608 build_flags = - ${ikoka_stick_nrf_baseboard.build_flags} + ${ikoka_stick_nrf.build_flags} -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -I examples/companion_radio/ui-new + -D QSPIFLASH=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${ikoka_stick_nrf_baseboard.build_src_filter} +build_src_filter = ${ikoka_stick_nrf.build_src_filter} + +<../examples/companion_radio/*.cpp> +<../examples/companion_radio/ui-new/*.cpp> lib_deps = - ${ikoka_stick_nrf_baseboard.lib_deps} + ${ikoka_stick_nrf.lib_deps} densaugeo/base64 @ ~1.4.0 [ikoka_stick_nrf_repeater] -extends = ikoka_stick_nrf_baseboard +extends = ikoka_stick_nrf build_flags = - ${ikoka_stick_nrf_baseboard.build_flags} + ${ikoka_stick_nrf.build_flags} -D ADVERT_NAME='"Ikoka Stick Repeater"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 @@ -154,21 +130,21 @@ build_flags = -D MAX_NEIGHBOURS=50 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${ikoka_stick_nrf_baseboard.build_src_filter} +build_src_filter = ${ikoka_stick_nrf.build_src_filter} + +<../examples/simple_repeater/*.cpp> [ikoka_stick_nrf_room_server] -extends = ikoka_stick_nrf_baseboard +extends = ikoka_stick_nrf build_flags = - ${ikoka_stick_nrf_baseboard.build_flags} + ${ikoka_stick_nrf.build_flags} -D ADVERT_NAME='"Ikoka Stick Room"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${ikoka_stick_nrf_baseboard.build_src_filter} +build_src_filter = ${ikoka_stick_nrf.build_src_filter} +<../examples/simple_room_server/*.cpp> ;;; hardware + firmware variants From a48b18518932791494d9838d277f0649491c4c1d Mon Sep 17 00:00:00 2001 From: liquidraver <504870+liquidraver@users.noreply.github.com> Date: Sun, 11 Jan 2026 22:03:48 +0100 Subject: [PATCH 24/33] DISABLE_DEBUG=1 env variable to build.sh --- build.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/build.sh b/build.sh index f2127941..b7f95dd7 100755 --- a/build.sh +++ b/build.sh @@ -29,6 +29,20 @@ $ sh build.sh build-repeater-firmwares Build all chat room server firmwares $ sh build.sh build-room-server-firmwares + +Environment Variables: + DISABLE_DEBUG=1: Disables all debug logging flags (MESH_DEBUG, MESH_PACKET_LOGGING, etc.) + If not set, debug flags from variant platformio.ini files are used. + +Examples: +Build without debug logging: +$ export FIRMWARE_VERSION=v1.0.0 +$ export DISABLE_DEBUG=1 +$ sh build.sh build-firmware RAK_4631_repeater + +Build with debug logging (default, uses flags from variant files): +$ export FIRMWARE_VERSION=v1.0.0 +$ sh build.sh build-firmware RAK_4631_repeater EOF } @@ -68,6 +82,13 @@ get_pio_envs_ending_with_string() { done } +# disable all debug logging flags if DISABLE_DEBUG=1 is set +disable_debug_flags() { + if [ "$DISABLE_DEBUG" == "1" ]; then + export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -UMESH_DEBUG -UBLE_DEBUG_LOGGING -UWIFI_DEBUG_LOGGING -UBRIDGE_DEBUG -UGPS_NMEA_DEBUG -UCORE_DEBUG_LEVEL -UESPNOW_DEBUG_LOGGING -UDEBUG_RP2040_WIRE -UDEBUG_RP2040_SPI -UDEBUG_RP2040_CORE -UDEBUG_RP2040_PORT -URADIOLIB_DEBUG_SPI -UCFG_DEBUG -URADIOLIB_DEBUG_BASIC -URADIOLIB_DEBUG_PROTOCOL" + fi +} + # build firmware for the provided pio env in $1 build_firmware() { @@ -94,6 +115,9 @@ build_firmware() { # add firmware version info to end of existing platformio build flags in environment vars export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -DFIRMWARE_BUILD_DATE='\"${FIRMWARE_BUILD_DATE}\"' -DFIRMWARE_VERSION='\"${FIRMWARE_VERSION_STRING}\"'" + # disable debug flags if requested + disable_debug_flags + # build firmware target pio run -e $1 From 06c4ca19ab064e359b6708c565be8c3e9bbc532a Mon Sep 17 00:00:00 2001 From: chrisdavis2110 Date: Tue, 13 Jan 2026 10:06:50 -0800 Subject: [PATCH 25/33] added variant rak3401 --- variants/rak3401/RAK3401Board.cpp | 37 ++++++ variants/rak3401/RAK3401Board.h | 81 ++++++++++++ variants/rak3401/platformio.ini | 135 +++++++++++++++++++ variants/rak3401/target.cpp | 66 ++++++++++ variants/rak3401/target.h | 30 +++++ variants/rak3401/variant.cpp | 43 +++++++ variants/rak3401/variant.h | 207 ++++++++++++++++++++++++++++++ 7 files changed, 599 insertions(+) create mode 100644 variants/rak3401/RAK3401Board.cpp create mode 100644 variants/rak3401/RAK3401Board.h create mode 100644 variants/rak3401/platformio.ini create mode 100644 variants/rak3401/target.cpp create mode 100644 variants/rak3401/target.h create mode 100644 variants/rak3401/variant.cpp create mode 100644 variants/rak3401/variant.h diff --git a/variants/rak3401/RAK3401Board.cpp b/variants/rak3401/RAK3401Board.cpp new file mode 100644 index 00000000..50499dff --- /dev/null +++ b/variants/rak3401/RAK3401Board.cpp @@ -0,0 +1,37 @@ +#include +#include + +#include "RAK3401Board.h" + +void RAK3401Board::begin() { + NRF52BoardDCDC::begin(); + pinMode(PIN_VBAT_READ, INPUT); +#ifdef PIN_USER_BTN + pinMode(PIN_USER_BTN, INPUT_PULLUP); +#endif + +#ifdef PIN_USER_BTN_ANA + pinMode(PIN_USER_BTN_ANA, INPUT_PULLUP); +#endif + +#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL) + Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL); +#endif + + Wire.begin(); + + // Enable 3.3V periphery power rail (GPS, IO Module, etc.) + pinMode(PIN_3V3_EN, OUTPUT); + digitalWrite(PIN_3V3_EN, HIGH); + + pinMode(SX126X_POWER_EN, OUTPUT); + digitalWrite(SX126X_POWER_EN, HIGH); + delay(10); // give sx1262 some time to power up + +#ifdef P_LORA_PA_EN + // Initialize RAK13302 1W LoRa transceiver module PA control pin + pinMode(P_LORA_PA_EN, OUTPUT); + digitalWrite(P_LORA_PA_EN, LOW); // Start with PA disabled + delay(10); // Allow PA module to initialize +#endif +} diff --git a/variants/rak3401/RAK3401Board.h b/variants/rak3401/RAK3401Board.h new file mode 100644 index 00000000..5188f274 --- /dev/null +++ b/variants/rak3401/RAK3401Board.h @@ -0,0 +1,81 @@ +#pragma once + +#include +#include +#include + +// LoRa radio module pins for RAK3401 with RAK13302 (uses SPI1) +#define P_LORA_DIO_1 10 +#define P_LORA_NSS 26 +#define P_LORA_RESET 4 +#define P_LORA_BUSY 9 +#define P_LORA_SCLK 3 // SPI1_SCK +#define P_LORA_MISO 29 // SPI1_MISO +#define P_LORA_MOSI 30 // SPI1_MOSI +#define SX126X_POWER_EN 21 + +//#define PIN_GPS_SDA 13 //GPS SDA pin (output option) +//#define PIN_GPS_SCL 14 //GPS SCL pin (output option) +//#define PIN_GPS_TX 16 //GPS TX pin +//#define PIN_GPS_RX 15 //GPS RX pin +#define PIN_GPS_1PPS 17 //GPS PPS pin +#define GPS_BAUD_RATE 9600 +#define GPS_ADDRESS 0x42 //i2c address for GPS + +// RAK13302 1W LoRa transceiver module PA control (WisBlock IO slot) +// The RAK13302 mounts to the IO slot and has an ANT_SW (antenna switch) pin that controls the PA +// This pin must be controlled during transmission to enable the 1W power amplifier +// +// According to RAK13302 datasheet: ANT_SW connects to IO3 on the IO slot +// RAK19007 base board pin mapping: IO3 = pin 31 (also available as AIN1/A1 for analog input) +// +// Default: Pin 31 (IO3) - ANT_SW pin from RAK13302 datasheet +// Override by defining P_LORA_PA_EN in platformio.ini if needed +#ifndef P_LORA_PA_EN + #define P_LORA_PA_EN 31 // ANT_SW pin from RAK13302 datasheet (IO3, pin 31 on RAK19007) +#endif + +#define SX126X_DIO2_AS_RF_SWITCH true +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 + +// built-ins +#define PIN_VBAT_READ 5 +#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000) + +// 3.3V periphery enable (GPS, IO Module, etc.) +#define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN + +class RAK3401Board : public NRF52BoardDCDC, public NRF52BoardOTA { +public: + RAK3401Board() : NRF52BoardOTA("RAK3401_OTA") {} + void begin(); + + #define BATTERY_SAMPLES 8 + + uint16_t getBattMilliVolts() override { + analogReadResolution(12); + + uint32_t raw = 0; + for (int i = 0; i < BATTERY_SAMPLES; i++) { + raw += analogRead(PIN_VBAT_READ); + } + raw = raw / BATTERY_SAMPLES; + + return (ADC_MULTIPLIER * raw) / 4096; + } + + const char* getManufacturerName() const override { + return "RAK 3401"; + } + +#ifdef P_LORA_PA_EN + void onBeforeTransmit() override { + digitalWrite(P_LORA_PA_EN, HIGH); // Enable PA before transmission + } + + void onAfterTransmit() override { + digitalWrite(P_LORA_PA_EN, LOW); // Disable PA after transmission to save power + } +#endif +}; diff --git a/variants/rak3401/platformio.ini b/variants/rak3401/platformio.ini new file mode 100644 index 00000000..f1c4bd2d --- /dev/null +++ b/variants/rak3401/platformio.ini @@ -0,0 +1,135 @@ +[rak3401] +extends = nrf52_base +board = rak4631 +board_check = true +build_flags = ${nrf52_base.build_flags} + ${sensor_base.build_flags} + -I variants/rak3401 + -D RAK_4631 + -D RAK_3401 + -D RAK13302 + -D RAK_BOARD + -D PIN_BOARD_SCL=14 + -D PIN_BOARD_SDA=13 + -D PIN_GPS_TX=PIN_SERIAL1_RX + -D PIN_GPS_RX=PIN_SERIAL1_TX + -D PIN_GPS_EN=-1 + -D PIN_OLED_RESET=-1 + -D RADIO_CLASS=CustomSX1262 + -D WRAPPER_CLASS=CustomSX1262Wrapper + -D LORA_TX_POWER=22 + -D SX126X_CURRENT_LIMIT=140 + -D SX126X_RX_BOOSTED_GAIN=1 +build_src_filter = ${nrf52_base.build_src_filter} + +<../variants/rak3401> + + + + + + +lib_deps = + ${nrf52_base.lib_deps} + ${sensor_base.lib_deps} + adafruit/Adafruit SSD1306 @ ^2.5.13 + sparkfun/SparkFun u-blox GNSS Arduino Library@^2.2.27 + +[env:RAK_3401_repeater] +extends = rak3401 +build_flags = + ${rak3401.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D ADVERT_NAME='"RAK3401 1W Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 + ;-D MESH_PACKET_LOGGING=1 + ;-D MESH_DEBUG=1 +build_src_filter = ${rak3401.build_src_filter} + + + +<../examples/simple_repeater> + +[env:RAK_3401_room_server] +extends = rak3401 +build_flags = + ${rak3401.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D ADVERT_NAME='"Test Room"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D ROOM_PASSWORD='"hello"' + ;-D MESH_PACKET_LOGGING=1 + ;-D MESH_DEBUG=1 +build_src_filter = ${rak3401.build_src_filter} + + + +<../examples/simple_room_server> + +[env:RAK_3401_companion_radio_usb] +extends = rak3401 +board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld +board_upload.maximum_size = 712704 +build_flags = + ${rak3401.build_flags} + -I examples/companion_radio/ui-new + -D DISPLAY_CLASS=SSD1306Display + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 +; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 +; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 +build_src_filter = ${rak3401.build_src_filter} + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${rak3401.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:RAK_3401_companion_radio_ble] +extends = rak3401 +board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld +board_upload.maximum_size = 712704 +build_flags = + ${rak3401.build_flags} + -I examples/companion_radio/ui-new + -D DISPLAY_CLASS=SSD1306Display + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D BLE_PIN_CODE=123456 + -D BLE_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 + ;-D MESH_PACKET_LOGGING=1 + ;-D MESH_DEBUG=1 +build_src_filter = ${rak3401.build_src_filter} + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${rak3401.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:RAK_3401_terminal_chat] +extends = rak3401 +build_flags = + ${rak3401.build_flags} + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=1 + ;-D MESH_PACKET_LOGGING=1 + ;-D MESH_DEBUG=1 +build_src_filter = ${rak3401.build_src_filter} + +<../examples/simple_secure_chat/main.cpp> +lib_deps = + ${rak3401.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:RAK_3401_sensor] +extends = rak3401 +build_flags = + ${rak3401.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D ADVERT_NAME='"RAK3401 Sensor"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + ;-D MESH_PACKET_LOGGING=1 + ;-D MESH_DEBUG=1 +build_src_filter = ${rak3401.build_src_filter} + + + +<../examples/simple_sensor> \ No newline at end of file diff --git a/variants/rak3401/target.cpp b/variants/rak3401/target.cpp new file mode 100644 index 00000000..ba827ad1 --- /dev/null +++ b/variants/rak3401/target.cpp @@ -0,0 +1,66 @@ +#include +#include "target.h" +#include + +RAK3401Board board; + +#ifndef PIN_USER_BTN + #define PIN_USER_BTN (-1) +#endif + +#ifdef DISPLAY_CLASS + DISPLAY_CLASS display; + MomentaryButton user_btn(PIN_USER_BTN, 1000, true, true); + + #if defined(PIN_USER_BTN_ANA) + MomentaryButton analog_btn(PIN_USER_BTN_ANA, 1000, 20); + #endif +#endif + +// RAK3401 uses SPI1 for the RAK13302 LoRa module +// Note: nRF52 doesn't have a separate SPI1 object, so we use SPI but configure it with SPI1 pins +RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); + +WRAPPER_CLASS radio_driver(radio, board); + +VolatileRTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + +#if ENV_INCLUDE_GPS + #include + MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1); + EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea); +#else + EnvironmentSensorManager sensors; +#endif + +bool radio_init() { + rtc_clock.begin(Wire); + + // Configure SPI with SPI1 pins for RAK13302 + // nRF52 uses the same SPI peripheral but with different pin assignments + SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); + SPI.begin(); + + return radio.std_init(&SPI); +} + +uint32_t radio_get_rng_seed() { + return radio.random(0x7FFFFFFF); +} + +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { + radio.setFrequency(freq); + radio.setSpreadingFactor(sf); + radio.setBandwidth(bw); + radio.setCodingRate(cr); +} + +void radio_set_tx_power(uint8_t dbm) { + radio.setOutputPower(dbm); +} + +mesh::LocalIdentity radio_new_identity() { + RadioNoiseListener rng(radio); + return mesh::LocalIdentity(&rng); // create new random identity +} diff --git a/variants/rak3401/target.h b/variants/rak3401/target.h new file mode 100644 index 00000000..32f17cd1 --- /dev/null +++ b/variants/rak3401/target.h @@ -0,0 +1,30 @@ +#pragma once + +#define RADIOLIB_STATIC_ONLY 1 +#include +#include +#include +#include +#include +#include + +#ifdef DISPLAY_CLASS + #include + extern DISPLAY_CLASS display; + #include + extern MomentaryButton user_btn; + #if defined(PIN_USER_BTN_ANA) + extern MomentaryButton analog_btn; + #endif +#endif + +extern RAK3401Board board; +extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; +extern EnvironmentSensorManager sensors; + +bool radio_init(); +uint32_t radio_get_rng_seed(); +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); +void radio_set_tx_power(uint8_t dbm); +mesh::LocalIdentity radio_new_identity(); diff --git a/variants/rak3401/variant.cpp b/variants/rak3401/variant.cpp new file mode 100644 index 00000000..db55920c --- /dev/null +++ b/variants/rak3401/variant.cpp @@ -0,0 +1,43 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" +#include "nrf.h" +#include "wiring_constants.h" +#include "wiring_digital.h" + +const uint32_t g_ADigitalPinMap[] = { + // P0 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + + // P1 + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; + +void initVariant() +{ + // LED1 & LED2 + pinMode(PIN_LED1, OUTPUT); + ledOff(PIN_LED1); + + pinMode(PIN_LED2, OUTPUT); + ledOff(PIN_LED2); + + // 3V3 Power Rail + pinMode(PIN_3V3_EN, OUTPUT); + digitalWrite(PIN_3V3_EN, HIGH); +} diff --git a/variants/rak3401/variant.h b/variants/rak3401/variant.h new file mode 100644 index 00000000..03e9c2a8 --- /dev/null +++ b/variants/rak3401/variant.h @@ -0,0 +1,207 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _VARIANT_RAK3401_ +#define _VARIANT_RAK3401_ + +#define RAK4630 + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +#define USE_LFXO // Board uses 32khz crystal for LF +// define USE_LFRC // Board uses RC for LF + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// Number of pins defined in PinDescription array +#define PINS_COUNT (48) +#define NUM_DIGITAL_PINS (48) +#define NUM_ANALOG_INPUTS (6) +#define NUM_ANALOG_OUTPUTS (0) + +// LEDs +#define PIN_LED1 (35) +#define PIN_LED2 (36) + +#define LED_BUILTIN PIN_LED1 +#define LED_CONN PIN_LED2 + +#define LED_GREEN PIN_LED1 +#define LED_BLUE PIN_LED2 + +#define LED_STATE_ON 1 // State when LED is litted + +/* + * Analog pins + */ +#define PIN_A0 (5) +#define PIN_A1 (31) +#define PIN_A2 (28) +#define PIN_A3 (29) +#define PIN_A4 (30) +#define PIN_A5 (31) +#define PIN_A6 (0xff) +#define PIN_A7 (0xff) + +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; +static const uint8_t A4 = PIN_A4; +static const uint8_t A5 = PIN_A5; +static const uint8_t A6 = PIN_A6; +static const uint8_t A7 = PIN_A7; +#define ADC_RESOLUTION 14 + +// Other pins +#define WB_I2C1_SDA (13) // SENSOR_SLOT IO_SLOT +#define WB_I2C1_SCL (14) // SENSOR_SLOT IO_SLOT + +#define PIN_AREF (2) +#define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) +#define PIN_NFC2 (10) + +static const uint8_t AREF = PIN_AREF; + +/* + * Serial interfaces + */ +#define PIN_SERIAL1_RX (15) +#define PIN_SERIAL1_TX (16) + +// Connected to Jlink CDC +#define PIN_SERIAL2_RX (8) +#define PIN_SERIAL2_TX (6) + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 2 + +#define PIN_SPI_MISO (45) +#define PIN_SPI_MOSI (44) +#define PIN_SPI_SCK (43) + +// SPI1 pins for RAK13302 1W LoRa module +#define PIN_SPI1_MISO (29) // (0 + 29) +#define PIN_SPI1_MOSI (30) // (0 + 30) +#define PIN_SPI1_SCK (3) // (0 + 3) + +static const uint8_t SS = 42; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; + +/* + * Wire Interfaces + */ +#define WIRE_INTERFACES_COUNT 1 + +#define PIN_WIRE_SDA (WB_I2C1_SDA) +#define PIN_WIRE_SCL (WB_I2C1_SCL) + +// QSPI Pins +#define PIN_QSPI_SCK 3 +#define PIN_QSPI_CS 26 +#define PIN_QSPI_IO0 30 +#define PIN_QSPI_IO1 29 +#define PIN_QSPI_IO2 28 +#define PIN_QSPI_IO3 2 + +// On-board QSPI Flash +#define EXTERNAL_FLASH_DEVICES IS25LP080D +#define EXTERNAL_FLASH_USE_QSPI + +// RAK13302 1W LoRa transceiver module (uses SPI1) +// LoRa radio module pins for RAK3401 with RAK13302 +#define P_LORA_DIO_1 10 +#define P_LORA_NSS 26 +#define P_LORA_RESET 4 +#define P_LORA_BUSY 9 +#define P_LORA_SCLK PIN_SPI1_SCK // 3 +#define P_LORA_MISO PIN_SPI1_MISO // 29 +#define P_LORA_MOSI PIN_SPI1_MOSI // 30 +#define SX126X_POWER_EN 21 + +// RAK13302 1W LoRa transceiver module PA control (WisBlock IO slot) +// The RAK13302 mounts to the IO slot and has an ANT_SW (antenna switch) pin that controls the PA +// This pin must be controlled during transmission to enable the 1W power amplifier +// +// According to RAK13302 datasheet: ANT_SW connects to IO3 on the IO slot +// RAK19007 base board pin mapping: IO3 = pin 31 (also available as AIN1/A1 for analog input) +// +// Default: Pin 31 (IO3) - ANT_SW pin from RAK13302 datasheet +// Override by defining P_LORA_PA_EN in platformio.ini if needed +#ifndef P_LORA_PA_EN + #define P_LORA_PA_EN 31 // ANT_SW pin from RAK13302 datasheet (IO3, pin 31 on RAK19007) +#endif + +#define SX126X_DIO2_AS_RF_SWITCH true +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 + +// enables 3.3V periphery like GPS or IO Module +// Do not toggle this for GPS power savings +#define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN + +// RAK1910 GPS module +// If using the wisblock GPS module and pluged into Port A on WisBlock base +// IO1 is hooked to PPS (pin 12 on header) = gpio 17 +// IO2 is hooked to GPS RESET = gpio 34, but it can not be used to this because IO2 is ALSO used to control 3V3_S power (1 is on). +// Therefore must be 1 to keep peripherals powered +// Power is on the controllable 3V3_S rail +#define PIN_GPS_PPS (17) // Pulse per second input from the GPS + +#define GPS_RX_PIN PIN_SERIAL1_RX +#define GPS_TX_PIN PIN_SERIAL1_TX + +// Battery +// The battery sense is hooked to pin A0 (5) +#define BATTERY_PIN PIN_A0 +// and has 12 bit resolution +#define BATTERY_SENSE_RESOLUTION_BITS 12 +#define BATTERY_SENSE_RESOLUTION 4096.0 +#undef AREF_VOLTAGE +#define AREF_VOLTAGE 3.0 +#define VBAT_AR_INTERNAL AR_INTERNAL_3_0 +#define ADC_MULTIPLIER 1.73 + +#define HAS_RTC 1 + +#define RAK_4631 1 + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#endif From 31f98bdd43c2a404ceea304a2d8dbfe2618cf498 Mon Sep 17 00:00:00 2001 From: Dustin Brewer Date: Wed, 14 Jan 2026 17:53:42 -0800 Subject: [PATCH 26/33] Fix Ikoka Stick builds --- variants/ikoka_stick_nrf/platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/variants/ikoka_stick_nrf/platformio.ini b/variants/ikoka_stick_nrf/platformio.ini index 4f664054..2e43b700 100644 --- a/variants/ikoka_stick_nrf/platformio.ini +++ b/variants/ikoka_stick_nrf/platformio.ini @@ -27,6 +27,7 @@ build_flags = ${nrf52_base.build_flags} -D PIN_USER_BTN=0 -D PIN_WIRE_SCL=7 -D PIN_WIRE_SDA=6 + -UENV_INCLUDE_GPS lib_deps = ${nrf52_base.lib_deps} ${sensor_base.lib_deps} From 403ce1db08249b51dc637bb1545d45894f1a03c7 Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 13 Jan 2026 00:38:20 +1100 Subject: [PATCH 27/33] contacts: granular autoadd and overwrite-oldest --- examples/companion_radio/DataStore.cpp | 2 + examples/companion_radio/MyMesh.cpp | 70 +++++++++++++++++++++++++- examples/companion_radio/MyMesh.h | 4 ++ examples/companion_radio/NodePrefs.h | 1 + src/helpers/BaseChatMesh.cpp | 69 +++++++++++++++++++------ src/helpers/BaseChatMesh.h | 5 ++ 6 files changed, 134 insertions(+), 17 deletions(-) diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index 4faac975..f61f53ae 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -227,6 +227,7 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no file.read((uint8_t *)&_prefs.buzzer_quiet, sizeof(_prefs.buzzer_quiet)); // 84 file.read((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85 file.read((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86 + file.read((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87 file.close(); } @@ -261,6 +262,7 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_ file.write((uint8_t *)&_prefs.buzzer_quiet, sizeof(_prefs.buzzer_quiet)); // 84 file.write((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85 file.write((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86 + file.write((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87 file.close(); } diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 59a0078f..803e3b03 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -54,6 +54,8 @@ #define CMD_SEND_CONTROL_DATA 55 // v8+ #define CMD_GET_STATS 56 // v8+, second byte is stats type #define CMD_SEND_ANON_REQ 57 +#define CMD_SET_AUTOADD_CONFIG 58 +#define CMD_GET_AUTOADD_CONFIG 59 // Stats sub-types for CMD_GET_STATS #define STATS_TYPE_CORE 0 @@ -85,6 +87,7 @@ #define RESP_CODE_ADVERT_PATH 22 #define RESP_CODE_TUNING_PARAMS 23 #define RESP_CODE_STATS 24 // v8+, second byte is stats type +#define RESP_CODE_AUTOADD_CONFIG 25 #define SEND_TIMEOUT_BASE_MILLIS 500 #define FLOOD_SEND_TIMEOUT_FACTOR 16.0f @@ -110,6 +113,8 @@ #define PUSH_CODE_BINARY_RESPONSE 0x8C #define PUSH_CODE_PATH_DISCOVERY_RESPONSE 0x8D #define PUSH_CODE_CONTROL_DATA 0x8E // v8+ +#define PUSH_CODE_CONTACT_DELETED 0x8F // used to notify client app of deleted contact when overwriting oldest +#define PUSH_CODE_CONTACTS_FULL 0x90 // used to notify client app that contacts storage is full #define ERR_CODE_UNSUPPORTED_CMD 1 #define ERR_CODE_NOT_FOUND 2 @@ -120,6 +125,15 @@ #define MAX_SIGN_DATA_LEN (8 * 1024) // 8K +// Auto-add config bitmask +// Bit 0: If set, overwrite oldest non-favourite contact when contacts file is full +// Bits 1-4: these indicate which contact types to auto-add when manual_contact_mode = 0x01 +#define AUTO_ADD_OVERWRITE_OLDEST (1 << 0) // 0x01 - overwrite oldest non-favourite when full +#define AUTO_ADD_CHAT (1 << 1) // 0x02 - auto-add Chat (Companion) (ADV_TYPE_CHAT) +#define AUTO_ADD_REPEATER (1 << 2) // 0x04 - auto-add Repeater (ADV_TYPE_REPEATER) +#define AUTO_ADD_ROOM_SERVER (1 << 3) // 0x08 - auto-add Room Server (ADV_TYPE_ROOM) +#define AUTO_ADD_SENSOR (1 << 4) // 0x10 - auto-add Sensor (ADV_TYPE_SENSOR) + void MyMesh::writeOKFrame() { uint8_t buf[1]; buf[0] = RESP_CODE_OK; @@ -262,9 +276,54 @@ bool MyMesh::isAutoAddEnabled() const { return (_prefs.manual_add_contacts & 1) == 0; } +bool MyMesh::shouldAutoAddContactType(uint8_t contact_type) const { + if ((_prefs.manual_add_contacts & 1) == 0) { + return true; + } + + uint8_t type_bit = 0; + switch (contact_type) { + case ADV_TYPE_CHAT: + type_bit = AUTO_ADD_CHAT; + break; + case ADV_TYPE_REPEATER: + type_bit = AUTO_ADD_REPEATER; + break; + case ADV_TYPE_ROOM: + type_bit = AUTO_ADD_ROOM_SERVER; + break; + case ADV_TYPE_SENSOR: + type_bit = AUTO_ADD_SENSOR; + break; + default: + return false; // Unknown type, don't auto-add + } + + return (_prefs.autoadd_config & type_bit) != 0; +} + +bool MyMesh::shouldOverwriteWhenFull() const { + return (_prefs.autoadd_config & AUTO_ADD_OVERWRITE_OLDEST) != 0; +} + +void MyMesh::onContactOverwrite(const uint8_t* pub_key) { + if (_serial->isConnected()) { + out_frame[0] = PUSH_CODE_CONTACT_DELETED; + memcpy(&out_frame[1], pub_key, PUB_KEY_SIZE); + _serial->writeFrame(out_frame, 1 + PUB_KEY_SIZE); + } +} + +void MyMesh::onContactsFull() { + if (_serial->isConnected()) { + out_frame[0] = PUSH_CODE_CONTACTS_FULL; + _serial->writeFrame(out_frame, 1); + } +} + void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) { if (_serial->isConnected()) { - if (!isAutoAddEnabled() && is_new) { + if (!shouldAutoAddContactType(contact.type) && is_new) { writeContactRespFrame(PUSH_CODE_NEW_ADVERT, contact); } else { out_frame[0] = PUSH_CODE_ADVERT; @@ -1663,6 +1722,15 @@ void MyMesh::handleCmdFrame(size_t len) { } else { writeErrFrame(ERR_CODE_TABLE_FULL); } + } else if (cmd_frame[0] == CMD_SET_AUTOADD_CONFIG) { + _prefs.autoadd_config = cmd_frame[1]; + savePrefs(); + writeOKFrame(); + } else if (cmd_frame[0] == CMD_GET_AUTOADD_CONFIG) { + int i = 0; + out_frame[i++] = RESP_CODE_AUTOADD_CONFIG; + out_frame[i++] = _prefs.autoadd_config; + _serial->writeFrame(out_frame, i); } else { writeErrFrame(ERR_CODE_UNSUPPORTED_CMD); MESH_DEBUG_PRINTLN("ERROR: unknown command: %02X", cmd_frame[0]); diff --git a/examples/companion_radio/MyMesh.h b/examples/companion_radio/MyMesh.h index 1fcc5697..a2b0033f 100644 --- a/examples/companion_radio/MyMesh.h +++ b/examples/companion_radio/MyMesh.h @@ -114,6 +114,10 @@ protected: void logRxRaw(float snr, float rssi, const uint8_t raw[], int len) override; bool isAutoAddEnabled() const override; + bool shouldAutoAddContactType(uint8_t type) const override; + bool shouldOverwriteWhenFull() const override; + void onContactsFull() override; + void onContactOverwrite(const uint8_t* pub_key) override; bool onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_t in_path_len, uint8_t* out_path, uint8_t out_path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override; void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) override; void onContactPathUpdated(const ContactInfo &contact) override; diff --git a/examples/companion_radio/NodePrefs.h b/examples/companion_radio/NodePrefs.h index e9db5444..62cd4164 100644 --- a/examples/companion_radio/NodePrefs.h +++ b/examples/companion_radio/NodePrefs.h @@ -27,4 +27,5 @@ struct NodePrefs { // persisted to file uint8_t buzzer_quiet; uint8_t gps_enabled; // GPS enabled flag (0=disabled, 1=enabled) uint32_t gps_interval; // GPS read interval in seconds + uint8_t autoadd_config; // bitmask for auto-add contacts config }; \ No newline at end of file diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index 08185628..241c5d32 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -55,6 +55,28 @@ void BaseChatMesh::sendAckTo(const ContactInfo& dest, uint32_t ack_hash) { } } +ContactInfo* BaseChatMesh::allocateContactSlot() { + if (num_contacts < MAX_CONTACTS) { + return &contacts[num_contacts++]; + } else if (shouldOverwriteWhenFull()) { + // Find oldest non-favourite contact by last_advert_timestamp + int oldest_idx = -1; + uint32_t oldest_timestamp = 0xFFFFFFFF; + for (int i = 0; i < num_contacts; i++) { + bool is_favourite = (contacts[i].flags & 0x01) != 0; + if (!is_favourite && contacts[i].last_advert_timestamp < oldest_timestamp) { + oldest_timestamp = contacts[i].last_advert_timestamp; + oldest_idx = i; + } + } + if (oldest_idx >= 0) { + onContactOverwrite(contacts[oldest_idx].id.pub_key); + return &contacts[oldest_idx]; + } + } + return NULL; // no space, no overwrite or all contacts are all favourites +} + void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id, uint32_t timestamp, const uint8_t* app_data, size_t app_data_len) { AdvertDataParser parser(app_data, app_data_len); if (!(parser.isValid() && parser.hasName())) { @@ -87,7 +109,7 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id, bool is_new = false; if (from == NULL) { - if (!isAutoAddEnabled()) { + if (!shouldAutoAddContactType(parser.getType())) { ContactInfo ci; memset(&ci, 0, sizeof(ci)); ci.id = id; @@ -105,20 +127,33 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id, } is_new = true; - if (num_contacts < MAX_CONTACTS) { - from = &contacts[num_contacts++]; - from->id = id; - from->out_path_len = -1; // initially out_path is unknown - from->gps_lat = 0; // initially unknown GPS loc - from->gps_lon = 0; - from->sync_since = 0; - - from->shared_secret_valid = false; // ecdh shared_secret will be calculated later on demand - } else { - MESH_DEBUG_PRINTLN("onAdvertRecv: contacts table is full!"); + from = allocateContactSlot(); + if (from == NULL) { + ContactInfo ci; + memset(&ci, 0, sizeof(ci)); + ci.id = id; + ci.out_path_len = -1; // initially out_path is unknown + StrHelper::strncpy(ci.name, parser.getName(), sizeof(ci.name)); + ci.type = parser.getType(); + if (parser.hasLatLon()) { + ci.gps_lat = parser.getIntLat(); + ci.gps_lon = parser.getIntLon(); + } + ci.last_advert_timestamp = timestamp; + ci.lastmod = getRTCClock()->getCurrentTime(); + onDiscoveredContact(ci, true, packet->path_len, packet->path); // let UI know + onContactsFull(); + MESH_DEBUG_PRINTLN("onAdvertRecv: unable to allocate contact slot for new contact"); return; } - } + + from->id = id; + from->out_path_len = -1; // initially out_path is unknown + from->gps_lat = 0; // initially unknown GPS loc + from->gps_lon = 0; + from->sync_since = 0; + from->shared_secret_valid = false; // ecdh shared_secret will be calculated later on demand + } // update StrHelper::strncpy(from->name, parser.getName(), sizeof(from->name)); @@ -722,10 +757,12 @@ ContactInfo* BaseChatMesh::lookupContactByPubKey(const uint8_t* pub_key, int pre } bool BaseChatMesh::addContact(const ContactInfo& contact) { - if (num_contacts < MAX_CONTACTS) { - auto dest = &contacts[num_contacts++]; + ContactInfo* dest = allocateContactSlot(); + if (dest) { *dest = contact; - + if (dest->last_advert_timestamp == 0) { // ensure non-zero timestamp to prevent contacts added from discover list being considered 'oldest' + dest->last_advert_timestamp = getRTCClock()->getCurrentTimeUnique(); + } dest->shared_secret_valid = false; // mark shared_secret as needing calculation return true; // success } diff --git a/src/helpers/BaseChatMesh.h b/src/helpers/BaseChatMesh.h index 40818fed..bfbf254e 100644 --- a/src/helpers/BaseChatMesh.h +++ b/src/helpers/BaseChatMesh.h @@ -89,9 +89,14 @@ protected: } void resetContacts() { num_contacts = 0; } + ContactInfo* allocateContactSlot(); // helper to find slot for new contact // 'UI' concepts, for sub-classes to implement virtual bool isAutoAddEnabled() const { return true; } + virtual bool shouldAutoAddContactType(uint8_t type) const { return true; } + virtual void onContactsFull() {}; + virtual bool shouldOverwriteWhenFull() const { return false; } + virtual void onContactOverwrite(const uint8_t* pub_key) {}; virtual void onDiscoveredContact(ContactInfo& contact, bool is_new, uint8_t path_len, const uint8_t* path) = 0; virtual ContactInfo* processAck(const uint8_t *data) = 0; virtual void onContactPathUpdated(const ContactInfo& contact) = 0; From 741564dd48d29ea328b1fd041bf4891ee28aa6e7 Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 13 Jan 2026 01:05:42 +1100 Subject: [PATCH 28/33] refactor: add populateContactFromAdvert() --- src/helpers/BaseChatMesh.cpp | 66 +++++++++++++++--------------------- src/helpers/BaseChatMesh.h | 1 + 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index 241c5d32..b68f4805 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -77,6 +77,20 @@ ContactInfo* BaseChatMesh::allocateContactSlot() { return NULL; // no space, no overwrite or all contacts are all favourites } +void BaseChatMesh::populateContactFromAdvert(ContactInfo& ci, const mesh::Identity& id, const AdvertDataParser& parser, uint32_t timestamp) { + memset(&ci, 0, sizeof(ci)); + ci.id = id; + ci.out_path_len = -1; // initially out_path is unknown + StrHelper::strncpy(ci.name, parser.getName(), sizeof(ci.name)); + ci.type = parser.getType(); + if (parser.hasLatLon()) { + ci.gps_lat = parser.getIntLat(); + ci.gps_lon = parser.getIntLon(); + } + ci.last_advert_timestamp = timestamp; + ci.lastmod = getRTCClock()->getCurrentTime(); +} + void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id, uint32_t timestamp, const uint8_t* app_data, size_t app_data_len) { AdvertDataParser parser(app_data, app_data_len); if (!(parser.isValid() && parser.hasName())) { @@ -111,17 +125,7 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id, if (from == NULL) { if (!shouldAutoAddContactType(parser.getType())) { ContactInfo ci; - memset(&ci, 0, sizeof(ci)); - ci.id = id; - ci.out_path_len = -1; // initially out_path is unknown - StrHelper::strncpy(ci.name, parser.getName(), sizeof(ci.name)); - ci.type = parser.getType(); - if (parser.hasLatLon()) { - ci.gps_lat = parser.getIntLat(); - ci.gps_lon = parser.getIntLon(); - } - ci.last_advert_timestamp = timestamp; - ci.lastmod = getRTCClock()->getCurrentTime(); + populateContactFromAdvert(ci, id, parser, timestamp); onDiscoveredContact(ci, true, packet->path_len, packet->path); // let UI know return; } @@ -130,40 +134,26 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id, from = allocateContactSlot(); if (from == NULL) { ContactInfo ci; - memset(&ci, 0, sizeof(ci)); - ci.id = id; - ci.out_path_len = -1; // initially out_path is unknown - StrHelper::strncpy(ci.name, parser.getName(), sizeof(ci.name)); - ci.type = parser.getType(); - if (parser.hasLatLon()) { - ci.gps_lat = parser.getIntLat(); - ci.gps_lon = parser.getIntLon(); - } - ci.last_advert_timestamp = timestamp; - ci.lastmod = getRTCClock()->getCurrentTime(); - onDiscoveredContact(ci, true, packet->path_len, packet->path); // let UI know + populateContactFromAdvert(ci, id, parser, timestamp); + onDiscoveredContact(ci, true, packet->path_len, packet->path); onContactsFull(); MESH_DEBUG_PRINTLN("onAdvertRecv: unable to allocate contact slot for new contact"); return; } - from->id = id; - from->out_path_len = -1; // initially out_path is unknown - from->gps_lat = 0; // initially unknown GPS loc - from->gps_lon = 0; + populateContactFromAdvert(*from, id, parser, timestamp); from->sync_since = 0; - from->shared_secret_valid = false; // ecdh shared_secret will be calculated later on demand - } - - // update - StrHelper::strncpy(from->name, parser.getName(), sizeof(from->name)); - from->type = parser.getType(); - if (parser.hasLatLon()) { - from->gps_lat = parser.getIntLat(); - from->gps_lon = parser.getIntLon(); + from->shared_secret_valid = false; } - from->last_advert_timestamp = timestamp; - from->lastmod = getRTCClock()->getCurrentTime(); + // update + StrHelper::strncpy(from->name, parser.getName(), sizeof(from->name)); + from->type = parser.getType(); + if (parser.hasLatLon()) { + from->gps_lat = parser.getIntLat(); + from->gps_lon = parser.getIntLon(); + } + from->last_advert_timestamp = timestamp; + from->lastmod = getRTCClock()->getCurrentTime(); onDiscoveredContact(*from, is_new, packet->path_len, packet->path); // let UI know } diff --git a/src/helpers/BaseChatMesh.h b/src/helpers/BaseChatMesh.h index bfbf254e..5387d3dd 100644 --- a/src/helpers/BaseChatMesh.h +++ b/src/helpers/BaseChatMesh.h @@ -89,6 +89,7 @@ protected: } void resetContacts() { num_contacts = 0; } + void populateContactFromAdvert(ContactInfo& ci, const mesh::Identity& id, const AdvertDataParser& parser, uint32_t timestamp); ContactInfo* allocateContactSlot(); // helper to find slot for new contact // 'UI' concepts, for sub-classes to implement From df6687034a12793db019788575a24e8d0b530269 Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 13 Jan 2026 04:27:27 +1100 Subject: [PATCH 29/33] bootstrap RTC from contact.lastmod and improve slot overwrite logic slot overwrite logic can now safely use contact.lastmod to find oldest contact for overwrite --- examples/companion_radio/MyMesh.cpp | 1 + src/helpers/BaseChatMesh.cpp | 23 ++++++++++++++++------- src/helpers/BaseChatMesh.h | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 803e3b03..28d60a0f 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -862,6 +862,7 @@ void MyMesh::begin(bool has_display) { resetContacts(); _store->loadContacts(this); + bootstrapRTCfromContacts(); addChannel("Public", PUBLIC_GROUP_PSK); // pre-configure Andy's public channel _store->loadChannels(this); diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index b68f4805..98b40962 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -55,17 +55,29 @@ void BaseChatMesh::sendAckTo(const ContactInfo& dest, uint32_t ack_hash) { } } +void BaseChatMesh::bootstrapRTCfromContacts() { + uint32_t latest = 0; + for (int i = 0; i < num_contacts; i++) { + if (contacts[i].lastmod > latest) { + latest = contacts[i].lastmod; + } + } + if (latest != 0) { + getRTCClock()->setCurrentTime(latest + 1); + } +} + ContactInfo* BaseChatMesh::allocateContactSlot() { if (num_contacts < MAX_CONTACTS) { return &contacts[num_contacts++]; } else if (shouldOverwriteWhenFull()) { - // Find oldest non-favourite contact by last_advert_timestamp + // Find oldest non-favourite contact by oldest lastmod timestamp int oldest_idx = -1; - uint32_t oldest_timestamp = 0xFFFFFFFF; + uint32_t oldest_lastmod = 0xFFFFFFFF; for (int i = 0; i < num_contacts; i++) { bool is_favourite = (contacts[i].flags & 0x01) != 0; - if (!is_favourite && contacts[i].last_advert_timestamp < oldest_timestamp) { - oldest_timestamp = contacts[i].last_advert_timestamp; + if (!is_favourite && contacts[i].lastmod < oldest_lastmod) { + oldest_lastmod = contacts[i].lastmod; oldest_idx = i; } } @@ -750,9 +762,6 @@ bool BaseChatMesh::addContact(const ContactInfo& contact) { ContactInfo* dest = allocateContactSlot(); if (dest) { *dest = contact; - if (dest->last_advert_timestamp == 0) { // ensure non-zero timestamp to prevent contacts added from discover list being considered 'oldest' - dest->last_advert_timestamp = getRTCClock()->getCurrentTimeUnique(); - } dest->shared_secret_valid = false; // mark shared_secret as needing calculation return true; // success } diff --git a/src/helpers/BaseChatMesh.h b/src/helpers/BaseChatMesh.h index 5387d3dd..fd391b98 100644 --- a/src/helpers/BaseChatMesh.h +++ b/src/helpers/BaseChatMesh.h @@ -88,6 +88,7 @@ protected: memset(connections, 0, sizeof(connections)); } + void bootstrapRTCfromContacts(); void resetContacts() { num_contacts = 0; } void populateContactFromAdvert(ContactInfo& ci, const mesh::Identity& id, const AdvertDataParser& parser, uint32_t timestamp); ContactInfo* allocateContactSlot(); // helper to find slot for new contact From 11565673c37d0b89aea3c5e5d39f4edb9ede8a33 Mon Sep 17 00:00:00 2001 From: Rastislav Vysoky Date: Thu, 15 Jan 2026 15:39:44 +0100 Subject: [PATCH 30/33] fix: bump max contacts for v3 companion usb --- variants/heltec_v3/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index dcb2873c..6b61eff5 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -323,7 +323,7 @@ lib_deps = extends = Heltec_lora32_v3 build_flags = ${Heltec_lora32_v3.build_flags} - -D MAX_CONTACTS=140 + -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 ; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 ; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 From c61fde9328503c2e34677fc7e091c716bdaec2e5 Mon Sep 17 00:00:00 2001 From: taco Date: Fri, 16 Jan 2026 12:17:22 +1100 Subject: [PATCH 31/33] always send PUSH_CODE_NEW_ADVERT when advert was not added to contacts[] --- examples/companion_radio/MyMesh.cpp | 2 +- src/helpers/BaseChatMesh.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 28d60a0f..3d8798b2 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -323,7 +323,7 @@ void MyMesh::onContactsFull() { void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) { if (_serial->isConnected()) { - if (!shouldAutoAddContactType(contact.type) && is_new) { + if (is_new) { writeContactRespFrame(PUSH_CODE_NEW_ADVERT, contact); } else { out_frame[0] = PUSH_CODE_ADVERT; diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index 98b40962..aebfc1b6 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -133,7 +133,7 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id, } putBlobByKey(id.pub_key, PUB_KEY_SIZE, temp_buf, plen); - bool is_new = false; + bool is_new = false; // true = not in contacts[], false = exists in contacts[] if (from == NULL) { if (!shouldAutoAddContactType(parser.getType())) { ContactInfo ci; @@ -142,7 +142,6 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id, return; } - is_new = true; from = allocateContactSlot(); if (from == NULL) { ContactInfo ci; From b919119fafaa0ac46810fc1f4f0954eb1c4ec57f Mon Sep 17 00:00:00 2001 From: taco Date: Fri, 16 Jan 2026 13:14:51 +1100 Subject: [PATCH 32/33] only write contacts when changed --- examples/companion_radio/MyMesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 3d8798b2..c80e2869 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -358,7 +358,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path memcpy(p->path, path, p->path_len); } - dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); + if (!is_new) dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); // only schedule lazy write for contacts that are in contacts[] } static int sort_by_recent(const void *a, const void *b) { From ed5d2909fc91c3f1769e87a9b0f3350acd9e2bcf Mon Sep 17 00:00:00 2001 From: chrisdavis2110 Date: Sat, 17 Jan 2026 22:54:20 -0800 Subject: [PATCH 33/33] updated variant rak3401 --- boards/rak3401.json | 72 +++++++++++++++++++++++++++ variants/rak3401/RAK3401Board.cpp | 7 +-- variants/rak3401/RAK3401Board.h | 37 +++++--------- variants/rak3401/platformio.ini | 10 +--- variants/rak3401/target.cpp | 8 --- variants/rak3401/variant.cpp | 37 ++++++++------ variants/rak3401/variant.h | 82 ++++++++++++++----------------- 7 files changed, 147 insertions(+), 106 deletions(-) create mode 100644 boards/rak3401.json diff --git a/boards/rak3401.json b/boards/rak3401.json new file mode 100644 index 00000000..a2816a63 --- /dev/null +++ b/boards/rak3401.json @@ -0,0 +1,72 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v6.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_NRF52840_FEATHER -DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [ + [ + "0x239A", + "0x8029" + ], + [ + "0x239A", + "0x0029" + ], + [ + "0x239A", + "0x002A" + ], + [ + "0x239A", + "0x802A" + ] + ], + "usb_product": "WisCore RAK3401 Board", + "mcu": "nrf52840", + "variant": "WisCore_RAK3401_Board", + "bsp": { + "name": "adafruit" + }, + "softdevice": { + "sd_flags": "-DS140", + "sd_name": "s140", + "sd_version": "6.1.1", + "sd_fwid": "0x00B6" + }, + "bootloader": { + "settings_addr": "0xFF000" + } + }, + "connectivity": [ + "bluetooth" + ], + "debug": { + "jlink_device": "nRF52840_xxAA", + "svd_path": "nrf52840.svd" + }, + "frameworks": [ + "arduino" + ], + "name": "WisCore RAK3401 Board", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "speed": 115200, + "protocol": "nrfutil", + "protocols": [ + "jlink", + "nrfjprog", + "nrfutil", + "stlink" + ], + "use_1200bps_touch": true, + "require_upload_port": true, + "wait_for_upload_port": true + }, + "url": "https://www.rakwireless.com", + "vendor": "RAKwireless" +} diff --git a/variants/rak3401/RAK3401Board.cpp b/variants/rak3401/RAK3401Board.cpp index 50499dff..b9431c92 100644 --- a/variants/rak3401/RAK3401Board.cpp +++ b/variants/rak3401/RAK3401Board.cpp @@ -20,18 +20,13 @@ void RAK3401Board::begin() { Wire.begin(); - // Enable 3.3V periphery power rail (GPS, IO Module, etc.) pinMode(PIN_3V3_EN, OUTPUT); digitalWrite(PIN_3V3_EN, HIGH); - pinMode(SX126X_POWER_EN, OUTPUT); - digitalWrite(SX126X_POWER_EN, HIGH); - delay(10); // give sx1262 some time to power up - #ifdef P_LORA_PA_EN // Initialize RAK13302 1W LoRa transceiver module PA control pin pinMode(P_LORA_PA_EN, OUTPUT); digitalWrite(P_LORA_PA_EN, LOW); // Start with PA disabled delay(10); // Allow PA module to initialize #endif -} +} \ No newline at end of file diff --git a/variants/rak3401/RAK3401Board.h b/variants/rak3401/RAK3401Board.h index 5188f274..609393c3 100644 --- a/variants/rak3401/RAK3401Board.h +++ b/variants/rak3401/RAK3401Board.h @@ -4,45 +4,34 @@ #include #include -// LoRa radio module pins for RAK3401 with RAK13302 (uses SPI1) -#define P_LORA_DIO_1 10 +// LoRa radio module pins for RAK13302 +#define P_LORA_SCLK 3 +#define P_LORA_MISO 29 +#define P_LORA_MOSI 30 #define P_LORA_NSS 26 -#define P_LORA_RESET 4 +#define P_LORA_DIO_1 10 #define P_LORA_BUSY 9 -#define P_LORA_SCLK 3 // SPI1_SCK -#define P_LORA_MISO 29 // SPI1_MISO -#define P_LORA_MOSI 30 // SPI1_MOSI -#define SX126X_POWER_EN 21 +#define P_LORA_RESET 4 +#ifndef P_LORA_PA_EN + #define P_LORA_PA_EN 31 +#endif //#define PIN_GPS_SDA 13 //GPS SDA pin (output option) //#define PIN_GPS_SCL 14 //GPS SCL pin (output option) -//#define PIN_GPS_TX 16 //GPS TX pin -//#define PIN_GPS_RX 15 //GPS RX pin +// #define PIN_GPS_TX 16 //GPS TX pin +// #define PIN_GPS_RX 15 //GPS RX pin #define PIN_GPS_1PPS 17 //GPS PPS pin #define GPS_BAUD_RATE 9600 #define GPS_ADDRESS 0x42 //i2c address for GPS -// RAK13302 1W LoRa transceiver module PA control (WisBlock IO slot) -// The RAK13302 mounts to the IO slot and has an ANT_SW (antenna switch) pin that controls the PA -// This pin must be controlled during transmission to enable the 1W power amplifier -// -// According to RAK13302 datasheet: ANT_SW connects to IO3 on the IO slot -// RAK19007 base board pin mapping: IO3 = pin 31 (also available as AIN1/A1 for analog input) -// -// Default: Pin 31 (IO3) - ANT_SW pin from RAK13302 datasheet -// Override by defining P_LORA_PA_EN in platformio.ini if needed -#ifndef P_LORA_PA_EN - #define P_LORA_PA_EN 31 // ANT_SW pin from RAK13302 datasheet (IO3, pin 31 on RAK19007) -#endif - -#define SX126X_DIO2_AS_RF_SWITCH true +#define SX126X_DIO2_AS_RF_SWITCH #define SX126X_DIO3_TCXO_VOLTAGE 1.8 + // built-ins #define PIN_VBAT_READ 5 #define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000) -// 3.3V periphery enable (GPS, IO Module, etc.) #define PIN_3V3_EN (34) #define WB_IO2 PIN_3V3_EN diff --git a/variants/rak3401/platformio.ini b/variants/rak3401/platformio.ini index f1c4bd2d..30d35d0b 100644 --- a/variants/rak3401/platformio.ini +++ b/variants/rak3401/platformio.ini @@ -1,20 +1,12 @@ [rak3401] extends = nrf52_base -board = rak4631 +board = rak3401 board_check = true build_flags = ${nrf52_base.build_flags} ${sensor_base.build_flags} -I variants/rak3401 - -D RAK_4631 -D RAK_3401 -D RAK13302 - -D RAK_BOARD - -D PIN_BOARD_SCL=14 - -D PIN_BOARD_SDA=13 - -D PIN_GPS_TX=PIN_SERIAL1_RX - -D PIN_GPS_RX=PIN_SERIAL1_TX - -D PIN_GPS_EN=-1 - -D PIN_OLED_RESET=-1 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper -D LORA_TX_POWER=22 diff --git a/variants/rak3401/target.cpp b/variants/rak3401/target.cpp index ba827ad1..52f3a3d5 100644 --- a/variants/rak3401/target.cpp +++ b/variants/rak3401/target.cpp @@ -17,8 +17,6 @@ RAK3401Board board; #endif #endif -// RAK3401 uses SPI1 for the RAK13302 LoRa module -// Note: nRF52 doesn't have a separate SPI1 object, so we use SPI but configure it with SPI1 pins RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); WRAPPER_CLASS radio_driver(radio, board); @@ -36,12 +34,6 @@ AutoDiscoverRTCClock rtc_clock(fallback_clock); bool radio_init() { rtc_clock.begin(Wire); - - // Configure SPI with SPI1 pins for RAK13302 - // nRF52 uses the same SPI peripheral but with different pin assignments - SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); - SPI.begin(); - return radio.std_init(&SPI); } diff --git a/variants/rak3401/variant.cpp b/variants/rak3401/variant.cpp index db55920c..d562189f 100644 --- a/variants/rak3401/variant.cpp +++ b/variants/rak3401/variant.cpp @@ -7,37 +7,46 @@ modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "variant.h" -#include "nrf.h" #include "wiring_constants.h" #include "wiring_digital.h" +#include "nrf.h" -const uint32_t g_ADigitalPinMap[] = { - // P0 - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, +const uint32_t g_ADigitalPinMap[] = +{ + // P0 + 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , + 8 , 9 , 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + + // P1 + 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47 +}; - // P1 - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; void initVariant() { - // LED1 & LED2 - pinMode(PIN_LED1, OUTPUT); - ledOff(PIN_LED1); + // LED1 & LED2 + pinMode(PIN_LED1, OUTPUT); + ledOff(PIN_LED1); - pinMode(PIN_LED2, OUTPUT); - ledOff(PIN_LED2); + pinMode(PIN_LED2, OUTPUT); + ledOff(PIN_LED2); - // 3V3 Power Rail - pinMode(PIN_3V3_EN, OUTPUT); - digitalWrite(PIN_3V3_EN, HIGH); + // 3V3 Power Rail + pinMode(PIN_3V3_EN, OUTPUT); + digitalWrite(PIN_3V3_EN, HIGH); } diff --git a/variants/rak3401/variant.h b/variants/rak3401/variant.h index 03e9c2a8..9c182247 100644 --- a/variants/rak3401/variant.h +++ b/variants/rak3401/variant.h @@ -34,7 +34,8 @@ #include "WVariant.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif // __cplusplus // Number of pins defined in PinDescription array @@ -58,8 +59,8 @@ extern "C" { /* * Analog pins */ -#define PIN_A0 (5) -#define PIN_A1 (31) +#define PIN_A0 (5) //(3) +#define PIN_A1 (31) //(4) #define PIN_A2 (28) #define PIN_A3 (29) #define PIN_A4 (30) @@ -67,14 +68,14 @@ extern "C" { #define PIN_A6 (0xff) #define PIN_A7 (0xff) -static const uint8_t A0 = PIN_A0; -static const uint8_t A1 = PIN_A1; -static const uint8_t A2 = PIN_A2; -static const uint8_t A3 = PIN_A3; -static const uint8_t A4 = PIN_A4; -static const uint8_t A5 = PIN_A5; -static const uint8_t A6 = PIN_A6; -static const uint8_t A7 = PIN_A7; + static const uint8_t A0 = PIN_A0; + static const uint8_t A1 = PIN_A1; + static const uint8_t A2 = PIN_A2; + static const uint8_t A3 = PIN_A3; + static const uint8_t A4 = PIN_A4; + static const uint8_t A5 = PIN_A5; + static const uint8_t A6 = PIN_A6; + static const uint8_t A7 = PIN_A7; #define ADC_RESOLUTION 14 // Other pins @@ -92,6 +93,7 @@ static const uint8_t AREF = PIN_AREF; /* * Serial interfaces */ +// TXD1 RXD1 on Base Board #define PIN_SERIAL1_RX (15) #define PIN_SERIAL1_TX (16) @@ -108,15 +110,14 @@ static const uint8_t AREF = PIN_AREF; #define PIN_SPI_MOSI (44) #define PIN_SPI_SCK (43) -// SPI1 pins for RAK13302 1W LoRa module -#define PIN_SPI1_MISO (29) // (0 + 29) -#define PIN_SPI1_MOSI (30) // (0 + 30) -#define PIN_SPI1_SCK (3) // (0 + 3) +#define PIN_SPI1_MISO (29) +#define PIN_SPI1_MOSI (30) +#define PIN_SPI1_SCK (3) -static const uint8_t SS = 42; -static const uint8_t MOSI = PIN_SPI_MOSI; -static const uint8_t MISO = PIN_SPI_MISO; -static const uint8_t SCK = PIN_SPI_SCK; + static const uint8_t SS = 42; + static const uint8_t MOSI = PIN_SPI_MOSI; + static const uint8_t MISO = PIN_SPI_MISO; + static const uint8_t SCK = PIN_SPI_SCK; /* * Wire Interfaces @@ -127,6 +128,7 @@ static const uint8_t SCK = PIN_SPI_SCK; #define PIN_WIRE_SCL (WB_I2C1_SCL) // QSPI Pins +// QSPI occupied by GPIO's #define PIN_QSPI_SCK 3 #define PIN_QSPI_CS 26 #define PIN_QSPI_IO0 30 @@ -135,35 +137,25 @@ static const uint8_t SCK = PIN_SPI_SCK; #define PIN_QSPI_IO3 2 // On-board QSPI Flash +// No onboard flash #define EXTERNAL_FLASH_DEVICES IS25LP080D #define EXTERNAL_FLASH_USE_QSPI -// RAK13302 1W LoRa transceiver module (uses SPI1) -// LoRa radio module pins for RAK3401 with RAK13302 -#define P_LORA_DIO_1 10 -#define P_LORA_NSS 26 -#define P_LORA_RESET 4 -#define P_LORA_BUSY 9 -#define P_LORA_SCLK PIN_SPI1_SCK // 3 -#define P_LORA_MISO PIN_SPI1_MISO // 29 -#define P_LORA_MOSI PIN_SPI1_MOSI // 30 -#define SX126X_POWER_EN 21 +#define P_LORA_SCK PIN_SPI1_SCK +#define P_LORA_MISO PIN_SPI1_MISO +#define P_LORA_MOSI PIN_SPI1_MOSI +#define P_LORA_CS 26 -// RAK13302 1W LoRa transceiver module PA control (WisBlock IO slot) -// The RAK13302 mounts to the IO slot and has an ANT_SW (antenna switch) pin that controls the PA -// This pin must be controlled during transmission to enable the 1W power amplifier -// -// According to RAK13302 datasheet: ANT_SW connects to IO3 on the IO slot -// RAK19007 base board pin mapping: IO3 = pin 31 (also available as AIN1/A1 for analog input) -// -// Default: Pin 31 (IO3) - ANT_SW pin from RAK13302 datasheet -// Override by defining P_LORA_PA_EN in platformio.ini if needed -#ifndef P_LORA_PA_EN - #define P_LORA_PA_EN 31 // ANT_SW pin from RAK13302 datasheet (IO3, pin 31 on RAK19007) -#endif +#define USE_SX1262 +#define SX126X_CS (26) +#define SX126X_DIO1 (10) +#define SX126X_BUSY (9) +#define SX126X_RESET (4) -#define SX126X_DIO2_AS_RF_SWITCH true -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#define SX126X_POWER_EN (21) +// DIO2 controlls an antenna switch and the TCXO voltage is controlled by DIO3 +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 // enables 3.3V periphery like GPS or IO Module // Do not toggle this for GPS power savings @@ -178,8 +170,8 @@ static const uint8_t SCK = PIN_SPI_SCK; // Power is on the controllable 3V3_S rail #define PIN_GPS_PPS (17) // Pulse per second input from the GPS -#define GPS_RX_PIN PIN_SERIAL1_RX -#define GPS_TX_PIN PIN_SERIAL1_TX +#define PIN_GPS_RX PIN_SERIAL1_RX +#define PIN_GPS_TX PIN_SERIAL1_TX // Battery // The battery sense is hooked to pin A0 (5)