Default to zero hop advert when booting

This commit is contained in:
João Brázio
2025-12-09 13:21:22 +00:00
parent 0307b64721
commit 802de27e03
11 changed files with 30 additions and 17 deletions

View File

@@ -769,10 +769,14 @@ bool MyMesh::formatFileSystem() {
#endif #endif
} }
void MyMesh::sendSelfAdvertisement(int delay_millis) { void MyMesh::sendSelfAdvertisement(int delay_millis, bool flood) {
mesh::Packet *pkt = createSelfAdvert(); mesh::Packet *pkt = createSelfAdvert();
if (pkt) { if (pkt) {
sendFlood(pkt, delay_millis); if (flood) {
sendFlood(pkt, delay_millis);
} else {
sendZeroHop(pkt, delay_millis);
}
} else { } else {
MESH_DEBUG_PRINTLN("ERROR: unable to create advertisement packet!"); MESH_DEBUG_PRINTLN("ERROR: unable to create advertisement packet!");
} }

View File

@@ -181,7 +181,7 @@ public:
void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override; void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override;
bool formatFileSystem() override; bool formatFileSystem() override;
void sendSelfAdvertisement(int delay_millis) override; void sendSelfAdvertisement(int delay_millis, bool flood = true) override;
void updateAdvertTimer() override; void updateAdvertTimer() override;
void updateFloodAdvertTimer() override; void updateFloodAdvertTimer() override;

View File

@@ -80,8 +80,8 @@ void setup() {
ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION); ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION);
#endif #endif
// send out initial Advertisement to the mesh // send out initial Zero Hop Advertisement to the mesh
the_mesh.sendSelfAdvertisement(16000); the_mesh.sendSelfAdvertisement(16000, false);
} }
void loop() { void loop() {

View File

@@ -675,10 +675,14 @@ bool MyMesh::formatFileSystem() {
#endif #endif
} }
void MyMesh::sendSelfAdvertisement(int delay_millis) { void MyMesh::sendSelfAdvertisement(int delay_millis, bool flood) {
mesh::Packet *pkt = createSelfAdvert(); mesh::Packet *pkt = createSelfAdvert();
if (pkt) { if (pkt) {
sendFlood(pkt, delay_millis); if (flood) {
sendFlood(pkt, delay_millis);
} else {
sendZeroHop(pkt, delay_millis);
}
} else { } else {
MESH_DEBUG_PRINTLN("ERROR: unable to create advertisement packet!"); MESH_DEBUG_PRINTLN("ERROR: unable to create advertisement packet!");
} }

View File

@@ -177,7 +177,7 @@ public:
void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override; void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override;
bool formatFileSystem() override; bool formatFileSystem() override;
void sendSelfAdvertisement(int delay_millis) override; void sendSelfAdvertisement(int delay_millis, bool flood = true) override;
void updateAdvertTimer() override; void updateAdvertTimer() override;
void updateFloodAdvertTimer() override; void updateFloodAdvertTimer() override;

View File

@@ -76,8 +76,8 @@ void setup() {
ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION); ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION);
#endif #endif
// send out initial Advertisement to the mesh // send out initial Zero Hop Advertisement to the mesh
the_mesh.sendSelfAdvertisement(16000); the_mesh.sendSelfAdvertisement(16000, false);
} }
void loop() { void loop() {

View File

@@ -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 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(); mesh::Packet* pkt = createSelfAdvert();
if (pkt) { if (pkt) {
sendFlood(pkt, delay_millis); if (flood) {
sendFlood(pkt, delay_millis);
} else {
sendZeroHop(pkt, delay_millis);
}
} else { } else {
MESH_DEBUG_PRINTLN("ERROR: unable to create advertisement packet!"); MESH_DEBUG_PRINTLN("ERROR: unable to create advertisement packet!");
} }

View File

@@ -60,7 +60,7 @@ public:
NodePrefs* getNodePrefs() { return &_prefs; } NodePrefs* getNodePrefs() { return &_prefs; }
void savePrefs() override { _cli.savePrefs(_fs); } void savePrefs() override { _cli.savePrefs(_fs); }
bool formatFileSystem() override; bool formatFileSystem() override;
void sendSelfAdvertisement(int delay_millis) override; void sendSelfAdvertisement(int delay_millis, bool flood = true) override;
void updateAdvertTimer() override; void updateAdvertTimer() override;
void updateFloodAdvertTimer() override; void updateFloodAdvertTimer() override;
void setLoggingOn(bool enable) override { } void setLoggingOn(bool enable) override { }

View File

@@ -110,8 +110,8 @@ void setup() {
ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION); ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION);
#endif #endif
// send out initial Advertisement to the mesh // send out initial Zero Hop Advertisement to the mesh
the_mesh.sendSelfAdvertisement(16000); the_mesh.sendSelfAdvertisement(16000, false);
} }
void loop() { void loop() {

View File

@@ -183,6 +183,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
if (memcmp(command, "reboot", 6) == 0) { if (memcmp(command, "reboot", 6) == 0) {
_board->reboot(); // doesn't return _board->reboot(); // doesn't return
} else if (memcmp(command, "advert", 6) == 0) { } 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 _callbacks->sendSelfAdvertisement(1500); // longer delay, give CLI response time to be sent first
strcpy(reply, "OK - Advert sent"); strcpy(reply, "OK - Advert sent");
} else if (memcmp(command, "clock sync", 10) == 0) { } else if (memcmp(command, "clock sync", 10) == 0) {
@@ -203,7 +204,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
uint32_t now = getRTCClock()->getCurrentTime(); uint32_t now = getRTCClock()->getCurrentTime();
DateTime dt = DateTime(now); DateTime dt = DateTime(now);
sprintf(reply, "%02d:%02d - %d/%d/%d UTC", dt.hour(), dt.minute(), dt.day(), dt.month(), dt.year()); 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 secs = _atoi(&command[5]);
uint32_t curr = getRTCClock()->getCurrentTime(); uint32_t curr = getRTCClock()->getCurrentTime();
if (secs > curr) { if (secs > curr) {

View File

@@ -57,7 +57,7 @@ public:
virtual const char* getBuildDate() = 0; virtual const char* getBuildDate() = 0;
virtual const char* getRole() = 0; virtual const char* getRole() = 0;
virtual bool formatFileSystem() = 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 updateAdvertTimer() = 0;
virtual void updateFloodAdvertTimer() = 0; virtual void updateFloodAdvertTimer() = 0;
virtual void setLoggingOn(bool enable) = 0; virtual void setLoggingOn(bool enable) = 0;