diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 5fb1a729f..d02d17768 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -629,6 +629,12 @@ bool MyMesh::onPeerPathRecv(mesh::Packet *packet, int sender_idx, const uint8_t #define CTL_TYPE_NODE_DISCOVER_RESP 0x90 void MyMesh::onControlDataRecv(mesh::Packet* packet) { + if (!packet->payload) { + MESH_DEBUG_PRINTLN("onControlDataRecv: packet->payload is null"); + return; + } + +#if !defined(STEALTH_MODE) 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())) { int i = 1; @@ -655,6 +661,7 @@ void MyMesh::onControlDataRecv(mesh::Packet* packet) { } } } +#endif } MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondClock &ms, mesh::RNG &rng, @@ -696,8 +703,8 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc _prefs.bw = LORA_BW; _prefs.cr = LORA_CR; _prefs.tx_power_dbm = LORA_TX_POWER; - _prefs.advert_interval = 1; // default to 2 minutes for NEW installs - _prefs.flood_advert_interval = 12; // 12 hours + _prefs.advert_interval = DEF_LOCAL_ADVERT_INTERVAL; + _prefs.flood_advert_interval = DEF_FLOOD_ADVERT_INTERVAL; _prefs.flood_max = 64; _prefs.interference_threshold = 0; // disabled @@ -769,10 +776,14 @@ bool MyMesh::formatFileSystem() { #endif } -void MyMesh::sendSelfAdvertisement(int delay_millis) { +void MyMesh::sendSelfAdvertisement(int delay_millis, bool flood) { mesh::Packet *pkt = createSelfAdvert(); if (pkt) { - sendFlood(pkt, delay_millis); + if (flood) { + sendFlood(pkt, delay_millis); + } else { + sendZeroHop(pkt, delay_millis); + } } else { MESH_DEBUG_PRINTLN("ERROR: unable to create advertisement packet!"); } diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index ed9f0c5fc..09745f9aa 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -181,7 +181,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override; bool formatFileSystem() override; - void sendSelfAdvertisement(int delay_millis) override; + void sendSelfAdvertisement(int delay_millis, bool flood = true) override; void updateAdvertTimer() override; void updateFloodAdvertTimer() override; diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 7387e77e7..7132d9a6a 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -80,8 +80,10 @@ void setup() { ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION); #endif - // send out initial Advertisement to the mesh - the_mesh.sendSelfAdvertisement(16000); +#if !defined(STEALTH_MODE) && !defined(NO_BOOT_ADVERT) + // send out initial Zero Hop Advertisement to the mesh + the_mesh.sendSelfAdvertisement(16000, false); +#endif } void loop() { diff --git a/examples/simple_room_server/MyMesh.cpp b/examples/simple_room_server/MyMesh.cpp index 60dd18407..63e2ea817 100644 --- a/examples/simple_room_server/MyMesh.cpp +++ b/examples/simple_room_server/MyMesh.cpp @@ -611,8 +611,8 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc _prefs.cr = LORA_CR; _prefs.tx_power_dbm = LORA_TX_POWER; _prefs.disable_fwd = 1; - _prefs.advert_interval = 1; // default to 2 minutes for NEW installs - _prefs.flood_advert_interval = 12; // 12 hours + _prefs.advert_interval = DEF_LOCAL_ADVERT_INTERVAL; + _prefs.flood_advert_interval = DEF_FLOOD_ADVERT_INTERVAL; _prefs.flood_max = 64; _prefs.interference_threshold = 0; // disabled #ifdef ROOM_PASSWORD @@ -675,10 +675,14 @@ bool MyMesh::formatFileSystem() { #endif } -void MyMesh::sendSelfAdvertisement(int delay_millis) { +void MyMesh::sendSelfAdvertisement(int delay_millis, bool flood) { mesh::Packet *pkt = createSelfAdvert(); if (pkt) { - sendFlood(pkt, delay_millis); + if (flood) { + sendFlood(pkt, delay_millis); + } else { + sendZeroHop(pkt, delay_millis); + } } else { MESH_DEBUG_PRINTLN("ERROR: unable to create advertisement packet!"); } diff --git a/examples/simple_room_server/MyMesh.h b/examples/simple_room_server/MyMesh.h index e7f1fee83..0c191dd0e 100644 --- a/examples/simple_room_server/MyMesh.h +++ b/examples/simple_room_server/MyMesh.h @@ -177,7 +177,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override; bool formatFileSystem() override; - void sendSelfAdvertisement(int delay_millis) override; + void sendSelfAdvertisement(int delay_millis, bool flood = true) override; void updateAdvertTimer() override; void updateFloodAdvertTimer() override; diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index 1a3b4d6e0..70af5dbe1 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -76,8 +76,10 @@ void setup() { ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION); #endif - // send out initial Advertisement to the mesh - the_mesh.sendSelfAdvertisement(16000); +#if !defined(STEALTH_MODE) && !defined(NO_BOOT_ADVERT) + // send out initial Zero Hop Advertisement to the mesh + the_mesh.sendSelfAdvertisement(16000, false); +#endif } void loop() { diff --git a/examples/simple_sensor/SensorMesh.cpp b/examples/simple_sensor/SensorMesh.cpp index 4995c55fc..fdae849bd 100644 --- a/examples/simple_sensor/SensorMesh.cpp +++ b/examples/simple_sensor/SensorMesh.cpp @@ -718,7 +718,7 @@ SensorMesh::SensorMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::Millise _prefs.bw = LORA_BW; _prefs.cr = LORA_CR; _prefs.tx_power_dbm = LORA_TX_POWER; - _prefs.advert_interval = 1; // default to 2 minutes for NEW installs + _prefs.advert_interval = DEF_LOCAL_ADVERT_INTERVAL; _prefs.flood_advert_interval = 0; // disabled _prefs.disable_fwd = true; _prefs.flood_max = 64; @@ -788,10 +788,14 @@ void SensorMesh::applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t revert_radio_at = futureMillis(2000 + timeout_mins*60*1000); // schedule when to revert radio params } -void SensorMesh::sendSelfAdvertisement(int delay_millis) { +void SensorMesh::sendSelfAdvertisement(int delay_millis, bool flood) { mesh::Packet* pkt = createSelfAdvert(); if (pkt) { - sendFlood(pkt, delay_millis); + if (flood) { + sendFlood(pkt, delay_millis); + } else { + sendZeroHop(pkt, delay_millis); + } } else { MESH_DEBUG_PRINTLN("ERROR: unable to create advertisement packet!"); } diff --git a/examples/simple_sensor/SensorMesh.h b/examples/simple_sensor/SensorMesh.h index c320eb447..4b4256496 100644 --- a/examples/simple_sensor/SensorMesh.h +++ b/examples/simple_sensor/SensorMesh.h @@ -60,7 +60,7 @@ class SensorMesh : public mesh::Mesh, public CommonCLICallbacks { NodePrefs* getNodePrefs() { return &_prefs; } void savePrefs() override { _cli.savePrefs(_fs); } bool formatFileSystem() override; - void sendSelfAdvertisement(int delay_millis) override; + void sendSelfAdvertisement(int delay_millis, bool flood = true) override; void updateAdvertTimer() override; void updateFloodAdvertTimer() override; void setLoggingOn(bool enable) override { } diff --git a/examples/simple_sensor/main.cpp b/examples/simple_sensor/main.cpp index a5fcc1484..76a161665 100644 --- a/examples/simple_sensor/main.cpp +++ b/examples/simple_sensor/main.cpp @@ -110,8 +110,10 @@ void setup() { ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION); #endif - // send out initial Advertisement to the mesh - the_mesh.sendSelfAdvertisement(16000); +#if !defined(STEALTH_MODE) && !defined(NO_BOOT_ADVERT) + // send out initial Zero Hop Advertisement to the mesh + the_mesh.sendSelfAdvertisement(16000, false); +#endif } void loop() { diff --git a/platformio.ini b/platformio.ini index 75d37e869..b21ae795d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -23,12 +23,16 @@ lib_deps = adafruit/RTClib @ ^2.1.3 melopero/Melopero RV3028 @ ^1.1.0 electroniccats/CayenneLPP @ 1.6.1 -build_flags = -w -DNDEBUG -DRADIOLIB_STATIC_ONLY=1 -DRADIOLIB_GODMODE=1 +build_flags = -w -DNDEBUG -D LORA_FREQ=869.525 -D LORA_BW=250 -D LORA_SF=11 + ; -D ENABLE_PRIVATE_KEY_IMPORT=1 ; NOTE: comment these out for more secure firmware -D ENABLE_PRIVATE_KEY_EXPORT=1 + ; + -D RADIOLIB_STATIC_ONLY=1 + -D RADIOLIB_GODMODE=1 -D RADIOLIB_EXCLUDE_CC1101=1 -D RADIOLIB_EXCLUDE_RF69=1 -D RADIOLIB_EXCLUDE_SX1231=1 @@ -43,6 +47,15 @@ build_flags = -w -DNDEBUG -DRADIOLIB_STATIC_ONLY=1 -DRADIOLIB_GODMODE=1 -D RADIOLIB_EXCLUDE_BELL=1 -D RADIOLIB_EXCLUDE_RTTY=1 -D RADIOLIB_EXCLUDE_SSTV=1 + ; + -D MIN_LOCAL_ADVERT_INTERVAL=60 + -D MAX_LOCAL_ADVERT_INTERVAL=240 + -D DEF_LOCAL_ADVERT_INTERVAL=1 ; default to 2 minutes for NEW installs + -D MIN_FLOOD_ADVERT_INTERVAL=3 + -D MAX_FLOOD_ADVERT_INTERVAL=48 + -D DEF_FLOOD_ADVERT_INTERVAL=12 ; default to 12 hours for NEW installs + ; -D NO_BOOT_ADVERT=1 ; disable boot advertisement + ; -D STEALTH_MODE=1 ; disable all advertisements and DISCOVER_REQ build_src_filter = +<*.cpp> + diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index a3de990aa..b6431f48b 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -157,8 +157,6 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) { } } -#define MIN_LOCAL_ADVERT_INTERVAL 60 - void CommonCLI::savePrefs() { if (_prefs->advert_interval * 2 < MIN_LOCAL_ADVERT_INTERVAL) { _prefs->advert_interval = 0; // turn it off, now that device has been manually configured @@ -183,6 +181,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch if (memcmp(command, "reboot", 6) == 0) { _board->reboot(); // doesn't return } else if (memcmp(command, "advert", 6) == 0) { + // Keep "advert" as flood for backward compatibility _callbacks->sendSelfAdvertisement(1500); // longer delay, give CLI response time to be sent first strcpy(reply, "OK - Advert sent"); } else if (memcmp(command, "clock sync", 10) == 0) { @@ -203,7 +202,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch uint32_t now = getRTCClock()->getCurrentTime(); DateTime dt = DateTime(now); sprintf(reply, "%02d:%02d - %d/%d/%d UTC", dt.hour(), dt.minute(), dt.day(), dt.month(), dt.year()); - } else if (memcmp(command, "time ", 5) == 0) { // set time (to epoch seconds) + } else if (memcmp(command, "time ", 5) == 0) { // set time (to epoch seconds) uint32_t secs = _atoi(&command[5]); uint32_t curr = getRTCClock()->getCurrentTime(); if (secs > curr) { @@ -371,8 +370,9 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch strcpy(reply, "OK"); } else if (memcmp(config, "flood.advert.interval ", 22) == 0) { int hours = _atoi(&config[22]); - if ((hours > 0 && hours < 3) || (hours > 48)) { - strcpy(reply, "Error: interval range is 3-48 hours"); + if ((hours > 0 && hours < MIN_FLOOD_ADVERT_INTERVAL) || (hours > MAX_FLOOD_ADVERT_INTERVAL)) { + sprintf(reply, "Error: interval range is %d-%d hours", MIN_FLOOD_ADVERT_INTERVAL, + MAX_FLOOD_ADVERT_INTERVAL); } else { _prefs->flood_advert_interval = (uint8_t)(hours); _callbacks->updateFloodAdvertTimer(); @@ -381,8 +381,9 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch } } else if (memcmp(config, "advert.interval ", 16) == 0) { int mins = _atoi(&config[16]); - if ((mins > 0 && mins < MIN_LOCAL_ADVERT_INTERVAL) || (mins > 240)) { - sprintf(reply, "Error: interval range is %d-240 minutes", MIN_LOCAL_ADVERT_INTERVAL); + if ((mins > 0 && mins < MIN_LOCAL_ADVERT_INTERVAL) || (mins > MAX_LOCAL_ADVERT_INTERVAL)) { + sprintf(reply, "Error: interval range is %d-%d minutes",MIN_LOCAL_ADVERT_INTERVAL, + MAX_LOCAL_ADVERT_INTERVAL); } else { _prefs->advert_interval = (uint8_t)(mins / 2); _callbacks->updateAdvertTimer(); diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index 068783ab1..785d4f0cf 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -57,7 +57,7 @@ class CommonCLICallbacks { virtual const char* getBuildDate() = 0; virtual const char* getRole() = 0; virtual bool formatFileSystem() = 0; - virtual void sendSelfAdvertisement(int delay_millis) = 0; + virtual void sendSelfAdvertisement(int delay_millis, bool flood = true) = 0; virtual void updateAdvertTimer() = 0; virtual void updateFloodAdvertTimer() = 0; virtual void setLoggingOn(bool enable) = 0;