Update MeshCore features and OTA layout handling
This commit is contained in:
1 parent
0c4619bcc3
commit
47993d178e
74 files changed
+1696
-1169
No files matched your search
@@ -6,6 +6,13 @@
|
||||
#include <helpers/AtomicFileWriter.h>
|
||||
#endif
|
||||
|
||||
// Linked presence of this symbol is the authoritative signal that this firmware actually mounts the
|
||||
// internal 0xD4000 ExtraFS. OTA layout code references it weakly, so non-companion roles can reclaim the
|
||||
// reserved range even though nrf52_base defines EXTRAFS globally.
|
||||
#if defined(NRF52_PLATFORM) && defined(EXTRAFS) && !defined(QSPIFLASH)
|
||||
extern "C" __attribute__((used)) const uint8_t g_meshcore_internal_extrafs = 1u;
|
||||
#endif
|
||||
|
||||
#if defined(EXTRAFS) || defined(QSPIFLASH)
|
||||
#define MAX_BLOBRECS 100
|
||||
#else
|
||||
|
||||
@@ -1354,7 +1354,7 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
|
||||
_prefs.tx_power_dbm = LORA_TX_POWER;
|
||||
_prefs.buzzer_quiet = DEFAULT_BUZZER_QUIET ? 1 : 0;
|
||||
_prefs.gps_enabled = 0; // GPS disabled by default
|
||||
_prefs.gps_interval = 0; // No automatic GPS updates by default
|
||||
_prefs.gps_interval = 0; // Use the default 1-second fix-processing interval
|
||||
_prefs.autoadd_config = DEFAULT_AUTOADD_CONFIG;
|
||||
_prefs.path_hash_mode = DEFAULT_PATH_HASH_MODE;
|
||||
_prefs.radio_fem_txgain = 0;
|
||||
@@ -4665,6 +4665,11 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
|| strcmp(command, "get powersaving") == 0) {
|
||||
Serial.printf(" powersaving %s\r\n",
|
||||
_prefs.powersaving_enabled ? "on" : "off");
|
||||
#if MESH_USB_LOGGING_AVAILABLE
|
||||
} else if (strcmp(command, "get usb.logging") == 0) {
|
||||
Serial.printf(" usb.logging %s\r\n",
|
||||
mesh::isUsbLoggingEnabled() ? "on" : "off");
|
||||
#endif
|
||||
} else if (strncmp(command, "powersaving ", 12) == 0) {
|
||||
char reply[160];
|
||||
applyAndSavePowerSaving(command + 12, reply);
|
||||
@@ -4709,6 +4714,22 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
}
|
||||
} else if (strncmp(command, "set ", 4) == 0) {
|
||||
const char* config = command + 4;
|
||||
#if MESH_USB_LOGGING_AVAILABLE
|
||||
if (strncmp(config, "usb.logging", 11) == 0
|
||||
&& (config[11] == 0 || config[11] == ' '
|
||||
|| config[11] == '\t')) {
|
||||
const char* value = config + 11;
|
||||
while (*value == ' ' || *value == '\t') value++;
|
||||
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
|
||||
Serial.print(" ERROR: use set usb.logging <on|off>\r\n");
|
||||
} else {
|
||||
const bool enabled = strcmp(value, "on") == 0;
|
||||
mesh::setUsbLoggingEnabled(enabled);
|
||||
Serial.printf(" OK - USB logging %s until reboot\r\n",
|
||||
enabled ? "on" : "off");
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
if (strncmp(config, "powersaving ", 12) == 0) {
|
||||
char reply[160];
|
||||
applyAndSavePowerSaving(config + 12, reply);
|
||||
@@ -4803,6 +4824,10 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
Serial.print("Commands:\r\n");
|
||||
Serial.print(" set {name|lat|lon|freq|tx|af} {value}\r\n");
|
||||
Serial.print(" powersaving [on|off]\r\n");
|
||||
#if MESH_USB_LOGGING_AVAILABLE
|
||||
Serial.print(" get usb.logging\r\n");
|
||||
Serial.print(" set usb.logging <on|off>\r\n");
|
||||
#endif
|
||||
#if defined(ESP32) && defined(WIFI_SSID)
|
||||
Serial.print(" get wifi.powersave\r\n");
|
||||
Serial.print(" set wifi.powersave <none|min|max>\r\n");
|
||||
|
||||
@@ -253,11 +253,9 @@ public:
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
void applyGpsPrefs() {
|
||||
sensors.setSettingValue("gps", _prefs.gps_enabled ? "1" : "0");
|
||||
if (_prefs.gps_interval > 0) {
|
||||
char interval_str[12]; // Max: 24 hours = 86400 seconds (5 digits + null)
|
||||
sprintf(interval_str, "%u", _prefs.gps_interval);
|
||||
sensors.setSettingValue("gps_interval", interval_str);
|
||||
}
|
||||
char interval_str[12]; // Max: 24 hours = 86400 seconds (5 digits + null)
|
||||
sprintf(interval_str, "%u", _prefs.gps_interval);
|
||||
sensors.setSettingValue("gps_interval", interval_str);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ struct CompanionNodePrefs { // persisted to file
|
||||
uint8_t advert_loc_policy;
|
||||
uint8_t buzzer_quiet;
|
||||
uint8_t gps_enabled; // GPS enabled flag (0=disabled, 1=enabled)
|
||||
uint32_t gps_interval; // GPS read interval in seconds
|
||||
uint32_t gps_interval; // GPS read interval in seconds; 0 uses the 1-second default
|
||||
uint8_t autoadd_config; // bitmask for auto-add contacts config
|
||||
uint8_t rx_boosted_gain; // SX126x RX boosted gain mode (0=power saving, 1=boosted)
|
||||
uint8_t radio_fem_rxgain; // LoRa FEM RX gain setting
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
|
||||
#ifdef ESP32_PLATFORM
|
||||
#include "esp_bt.h"
|
||||
#include "esp_pm.h"
|
||||
#include "esp_sleep.h"
|
||||
#if defined(CONFIG_PM_ENABLE) && CONFIG_PM_ENABLE
|
||||
#define COMPANION_IDF_PM_AVAILABLE 1
|
||||
#else
|
||||
#define COMPANION_IDF_PM_AVAILABLE 0
|
||||
#endif
|
||||
#if defined(COMPANION_RADIO_FULL)
|
||||
#include <esp_heap_caps.h>
|
||||
#endif
|
||||
@@ -174,12 +181,39 @@ static uint32_t companionNominalCpuMhz() {
|
||||
|
||||
static bool applyCompanionPowerSaving(bool enabled) {
|
||||
const uint32_t nominal_mhz = companionNominalCpuMhz();
|
||||
const uint32_t target_mhz = enabled && nominal_mhz > 80 ? 80 : nominal_mhz;
|
||||
if (!setCpuFrequencyMhz(target_mhz)) {
|
||||
Serial.printf("Device power saving failed: CPU %lu MHz is unsupported\r\n",
|
||||
(unsigned long)target_mhz);
|
||||
const uint32_t max_mhz = enabled && nominal_mhz > 80 ? 80 : nominal_mhz;
|
||||
|
||||
#if COMPANION_IDF_PM_AVAILABLE
|
||||
const uint32_t min_mhz = enabled && max_mhz > 40 ? 40 : max_mhz;
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
esp_pm_config_esp32c3_t pm_config;
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
esp_pm_config_esp32s3_t pm_config;
|
||||
#elif CONFIG_IDF_TARGET_ESP32
|
||||
esp_pm_config_esp32_t pm_config;
|
||||
#else
|
||||
esp_pm_config_t pm_config;
|
||||
#endif
|
||||
pm_config.max_freq_mhz = max_mhz;
|
||||
pm_config.min_freq_mhz = min_mhz;
|
||||
pm_config.light_sleep_enable = enabled;
|
||||
|
||||
esp_err_t pm_result = esp_pm_configure(&pm_config);
|
||||
if (pm_result != ESP_OK) {
|
||||
Serial.printf("Device power saving failed: %s\r\n",
|
||||
esp_err_to_name(pm_result));
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
// Arduino's prebuilt ESP-IDF normally has CONFIG_PM_ENABLE disabled, in
|
||||
// which case esp_pm_configure() is a stub returning ESP_ERR_NOT_SUPPORTED.
|
||||
// Keep frequency throttling functional instead of retrying that stub.
|
||||
if (!setCpuFrequencyMhz(max_mhz)) {
|
||||
Serial.printf("Device power saving failed: CPU %lu MHz is unsupported\r\n",
|
||||
(unsigned long)max_mhz);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BLE_PIN_CODE) && !CONFIG_IDF_TARGET_ESP32C6
|
||||
esp_err_t bt_result = enabled ? esp_bt_sleep_enable()
|
||||
@@ -191,8 +225,14 @@ static bool applyCompanionPowerSaving(bool enabled) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if COMPANION_IDF_PM_AVAILABLE
|
||||
Serial.printf("Device power saving %s: CPU %lu-%lu MHz, automatic light sleep %s\r\n",
|
||||
enabled ? "on" : "off", (unsigned long)min_mhz,
|
||||
(unsigned long)max_mhz, enabled ? "on" : "off");
|
||||
#else
|
||||
Serial.printf("Device power saving %s: CPU %lu MHz\r\n",
|
||||
enabled ? "on" : "off", (unsigned long)target_mhz);
|
||||
enabled ? "on" : "off", (unsigned long)max_mhz);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1147,7 +1187,29 @@ void loop() {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
board.sleep(0); // nrf ignores seconds param, sleeps whenever possible
|
||||
#elif defined(ESP32_PLATFORM)
|
||||
vTaskDelay(pdMS_TO_TICKS(10)); // attempt to sleep
|
||||
#if COMPANION_IDF_PM_AVAILABLE
|
||||
// Yield long enough for ESP-IDF automatic light sleep to enter when no
|
||||
// driver holds a power-management lock.
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
#elif defined(ENABLE_USB_INTERFACE) \
|
||||
&& defined(ARDUINO_USB_CDC_ON_BOOT) && ARDUINO_USB_CDC_ON_BOOT \
|
||||
&& !defined(BLE_PIN_CODE) && !defined(WIFI_SSID) \
|
||||
&& !defined(ETHERNET_ENABLED) && !defined(SERIAL_RX)
|
||||
// The stock Arduino core has no automatic light sleep. A short timer
|
||||
// slice gives native-USB-only battery builds real light sleep without
|
||||
// delaying radio, GPS, button, or newly attached USB work by more than the
|
||||
// normal 10 ms loop cadence. can_sleep already proved no USB host is up.
|
||||
if (esp_sleep_enable_timer_wakeup(10000ULL) != ESP_OK
|
||||
|| esp_light_sleep_start() != ESP_OK) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
#else
|
||||
// Connected transports need their own modem sleep and must retain the
|
||||
// normal FreeRTOS idle behavior.
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
#endif
|
||||
#elif defined(RP2040_PLATFORM) || defined(STM32_PLATFORM)
|
||||
board.sleep(0); // event-driven idle; interrupts wake the main loop
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -154,6 +154,9 @@ void loop() {
|
||||
board.feedWatchdog();
|
||||
#endif
|
||||
modem->loop();
|
||||
// GPS acquisition, cache refresh, and delayed shutdown are driven by the
|
||||
// sensor manager loop even though KISS itself is normally host powered.
|
||||
sensors.loop();
|
||||
|
||||
if (!modem->isActuallyTransmitting() && !modem->isHostOutputBackedUp()) {
|
||||
if (!modem->isTxBusy()) {
|
||||
|
||||
@@ -1016,11 +1016,13 @@ const char *MyMesh::getLogDateTime() {
|
||||
|
||||
void MyMesh::logRxRaw(float snr, float rssi, const uint8_t raw[], int len) {
|
||||
#if MESH_PACKET_LOGGING && !defined(MESH_COMPACT_PACKET_LOGGING)
|
||||
// Logging builds prefer backpressure over silently losing a packet record.
|
||||
Serial.print(getLogDateTime());
|
||||
Serial.print(" RAW: ");
|
||||
mesh::Utils::printHex(Serial, raw, len);
|
||||
Serial.println();
|
||||
if (mesh::isUsbLoggingEnabled()) {
|
||||
// Logging builds prefer backpressure over silently losing a packet record.
|
||||
Serial.print(getLogDateTime());
|
||||
Serial.print(" RAW: ");
|
||||
mesh::Utils::printHex(Serial, raw, len);
|
||||
Serial.println();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
@@ -9510,9 +9512,8 @@ void MyMesh::formatClockSyncStatus(const char* args, char* reply, size_t reply_l
|
||||
|
||||
#else
|
||||
|
||||
// Portable MQTT observers use their bridge's NTP source. Flash-constrained
|
||||
// repeaters can also omit mesh consensus while retaining manual clock setting
|
||||
// and scheduled radio changes.
|
||||
// Builds without mesh consensus retain manual clock setting and scheduled
|
||||
// radio changes. MQTT observers use their bridge's NTP source.
|
||||
static const char* clockSyncMeshSuppressionName(uint8_t source) {
|
||||
(void)source;
|
||||
return "unavailable";
|
||||
@@ -10408,9 +10409,8 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *
|
||||
#endif
|
||||
|
||||
#if defined(PORTABLE_MQTT_OBSERVER)
|
||||
// Neighbor refresh is a core repeater operation, not an MQTT feature. Keep
|
||||
// it ahead of the portable observer's reduced CommonCLI handoff so every
|
||||
// repeater build exposes the same command.
|
||||
// Legacy PORTABLE_MQTT_OBSERVER builds kept neighbor refresh ahead of their
|
||||
// reduced role handoff. Current build.sh profiles never define this macro.
|
||||
if (discover_neighbors_match != mesh::cli::NoArgCommandMatch::NoMatch) {
|
||||
if (discover_neighbors_match ==
|
||||
mesh::cli::NoArgCommandMatch::HasArguments) {
|
||||
@@ -10422,9 +10422,8 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *
|
||||
return;
|
||||
}
|
||||
|
||||
// Reply-path overrides are core remote-client routing controls. Keep them
|
||||
// available before the portable observer hands the remaining commands to
|
||||
// its reduced CommonCLI parser.
|
||||
// Legacy PORTABLE_MQTT_OBSERVER builds kept reply-path overrides ahead of
|
||||
// their reduced role handoff. Current build.sh profiles use FULL instead.
|
||||
if (classifyClientPathCommand(command) != CLIENT_PATH_NONE) {
|
||||
if (sender && !sender->isAdmin()) {
|
||||
bool allowed = (sender->isRegionMgr() || sender->isFilterMgr())
|
||||
@@ -10438,9 +10437,8 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *
|
||||
return;
|
||||
}
|
||||
|
||||
// The portable observer exposes its MQTT/WiFi/update controls through
|
||||
// CommonCLI. Omit the repeater's large remote-administration command tree;
|
||||
// its mesh behavior remains fixed by the selected build profile.
|
||||
// Compatibility path for manually defined legacy portable builds. Current
|
||||
// release builds use FULL and do not enter this branch.
|
||||
_cli.handleCommand(sender_timestamp, command, reply);
|
||||
return;
|
||||
#endif
|
||||
|
||||
@@ -822,6 +822,9 @@ protected:
|
||||
void applyGpsPrefs() {
|
||||
sensors.setPowerSavingEnabled(_prefs.powersaving_enabled != 0);
|
||||
sensors.setSettingValue("gps", _prefs.gps_enabled?"1":"0");
|
||||
char interval_str[12];
|
||||
sprintf(interval_str, "%u", _prefs.gps_interval);
|
||||
sensors.setSettingValue("gps_interval", interval_str);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -264,11 +264,13 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
|
||||
|
||||
void MyMesh::logRxRaw(float snr, float rssi, const uint8_t raw[], int len) {
|
||||
#if MESH_PACKET_LOGGING
|
||||
// Logging builds prefer backpressure over silently losing a packet record.
|
||||
Serial.print(getLogDateTime());
|
||||
Serial.print(" RAW: ");
|
||||
mesh::Utils::printHex(Serial, raw, len);
|
||||
Serial.println();
|
||||
if (mesh::isUsbLoggingEnabled()) {
|
||||
// Logging builds prefer backpressure over silently losing a packet record.
|
||||
Serial.print(getLogDateTime());
|
||||
Serial.print(" RAW: ");
|
||||
mesh::Utils::printHex(Serial, raw, len);
|
||||
Serial.println();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
|
||||
@@ -331,6 +331,9 @@ protected:
|
||||
void applyGpsPrefs() {
|
||||
sensors.setPowerSavingEnabled(_prefs.powersaving_enabled != 0);
|
||||
sensors.setSettingValue("gps", _prefs.gps_enabled?"1":"0");
|
||||
char interval_str[12];
|
||||
sprintf(interval_str, "%u", _prefs.gps_interval);
|
||||
sensors.setSettingValue("gps_interval", interval_str);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -818,8 +818,10 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
|
||||
bool SensorMesh::handleIncomingMsg(ClientInfo& from, uint32_t timestamp, uint8_t* data, uint8_t flags, size_t len) {
|
||||
MESH_DEBUG_PRINT("handleIncomingMsg: unhandled msg from ");
|
||||
#ifdef MESH_DEBUG
|
||||
mesh::Utils::printHex(Serial, from.id.pub_key, PUB_KEY_SIZE);
|
||||
Serial.printf(": %s\n", data);
|
||||
if (mesh::isUsbLoggingEnabled()) {
|
||||
mesh::Utils::printHex(Serial, from.id.pub_key, PUB_KEY_SIZE);
|
||||
Serial.printf(": %s\n", data);
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@@ -1286,3 +1288,79 @@ void SensorMesh::loop() {
|
||||
dirty_contacts_expiry = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool SensorMesh::isMillisTimerDue(unsigned long timestamp) const {
|
||||
return timestamp && millisHasNowPassed(timestamp);
|
||||
}
|
||||
|
||||
uint32_t SensorMesh::limitSleepToMillisTimer(unsigned long timestamp,
|
||||
uint32_t sleep_secs) const {
|
||||
if (!timestamp || sleep_secs == 0) return sleep_secs;
|
||||
|
||||
unsigned long now = millis();
|
||||
if ((long)(now - timestamp) >= 0) return 0;
|
||||
|
||||
uint32_t remaining_secs = (timestamp - now + 999UL) / 1000UL;
|
||||
return remaining_secs < sleep_secs ? remaining_secs : sleep_secs;
|
||||
}
|
||||
|
||||
bool SensorMesh::hasPendingWork() const {
|
||||
if (_cli.hasActiveUserGpioTimer()) return true;
|
||||
if (radio_driver.isWatchdogObserving()) return true;
|
||||
if (radio_driver.isCalibratingNoiseFloor()) return true;
|
||||
if (hasQueuedWorkDue() || hasRetryWorkDue()) return true;
|
||||
if (isMillisTimerDue(next_flood_advert)
|
||||
|| isMillisTimerDue(next_local_advert)
|
||||
|| isMillisTimerDue(dirty_contacts_expiry)) return true;
|
||||
if (num_alert_tasks > 0
|
||||
&& isMillisTimerDue(alert_tasks[0]->send_expiry)) return true;
|
||||
|
||||
const bool radio_apply_backoff = radio_apply_retry_at
|
||||
&& !millisHasNowPassed(radio_apply_retry_at);
|
||||
if (!radio_apply_backoff
|
||||
&& (isMillisTimerDue(set_radio_at) || isMillisTimerDue(revert_radio_at)
|
||||
|| (saved_radio_apply_pending && !temp_radio_applied))) return true;
|
||||
|
||||
uint32_t now_secs = getRTCClock()->getCurrentTime();
|
||||
return now_secs >= last_read_time + SENSOR_READ_INTERVAL_SECS;
|
||||
}
|
||||
|
||||
uint32_t SensorMesh::getPowerSaveSleepSeconds(uint32_t max_secs) const {
|
||||
if (max_secs == 0 || hasPendingWork()) return 0;
|
||||
|
||||
uint32_t sleep_secs = max_secs;
|
||||
uint32_t wake_delay_ms;
|
||||
if (getNextQueueWakeDelay(wake_delay_ms)) {
|
||||
uint32_t wake_delay_secs = (wake_delay_ms + 999UL) / 1000UL;
|
||||
if (wake_delay_secs < sleep_secs) sleep_secs = wake_delay_secs;
|
||||
}
|
||||
if (getNextRetryWakeDelay(wake_delay_ms)) {
|
||||
uint32_t wake_delay_secs = (wake_delay_ms + 999UL) / 1000UL;
|
||||
if (wake_delay_secs < sleep_secs) sleep_secs = wake_delay_secs;
|
||||
}
|
||||
|
||||
sleep_secs = limitSleepToMillisTimer(next_flood_advert, sleep_secs);
|
||||
sleep_secs = limitSleepToMillisTimer(next_local_advert, sleep_secs);
|
||||
sleep_secs = limitSleepToMillisTimer(dirty_contacts_expiry, sleep_secs);
|
||||
if (num_alert_tasks > 0) {
|
||||
sleep_secs = limitSleepToMillisTimer(alert_tasks[0]->send_expiry,
|
||||
sleep_secs);
|
||||
}
|
||||
|
||||
const bool radio_apply_backoff = radio_apply_retry_at
|
||||
&& !millisHasNowPassed(radio_apply_retry_at);
|
||||
if (radio_apply_backoff) {
|
||||
sleep_secs = limitSleepToMillisTimer(radio_apply_retry_at, sleep_secs);
|
||||
} else {
|
||||
sleep_secs = limitSleepToMillisTimer(set_radio_at, sleep_secs);
|
||||
sleep_secs = limitSleepToMillisTimer(revert_radio_at, sleep_secs);
|
||||
}
|
||||
|
||||
uint32_t now_secs = getRTCClock()->getCurrentTime();
|
||||
uint32_t sensor_due = last_read_time + SENSOR_READ_INTERVAL_SECS;
|
||||
if (now_secs < sensor_due) {
|
||||
uint32_t sensor_delay = sensor_due - now_secs;
|
||||
if (sensor_delay < sleep_secs) sleep_secs = sensor_delay;
|
||||
}
|
||||
return sleep_secs;
|
||||
}
|
||||
@@ -66,6 +66,7 @@ public:
|
||||
const char* getRole() override { return FIRMWARE_ROLE; }
|
||||
const char* getNodeName() { return _prefs.node_name; }
|
||||
NodePrefs* getNodePrefs() { return &_prefs; }
|
||||
uint32_t getPowerSaveSleepSeconds(uint32_t max_secs) const;
|
||||
void savePrefs(
|
||||
PrefsSaveRouting::Scope scope = PrefsSaveRouting::Scope::Common) override {
|
||||
_cli.savePrefs(_fs, scope);
|
||||
@@ -213,6 +214,10 @@ private:
|
||||
uint8_t radio_apply_failures;
|
||||
|
||||
bool applySavedRadioParams();
|
||||
bool isMillisTimerDue(unsigned long timestamp) const;
|
||||
uint32_t limitSleepToMillisTimer(unsigned long timestamp,
|
||||
uint32_t sleep_secs) const;
|
||||
bool hasPendingWork() const;
|
||||
|
||||
uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood);
|
||||
uint8_t handleRequest(uint8_t perms, uint32_t sender_timestamp, uint8_t req_type, uint8_t* payload, size_t payload_len);
|
||||
@@ -226,6 +231,9 @@ private:
|
||||
void applyGpsPrefs() {
|
||||
sensors.setPowerSavingEnabled(_prefs.powersaving_enabled != 0);
|
||||
sensors.setSettingValue("gps", _prefs.gps_enabled?"1":"0");
|
||||
char interval_str[12];
|
||||
sprintf(interval_str, "%u", _prefs.gps_interval);
|
||||
sensors.setSettingValue("gps_interval", interval_str);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
@@ -56,6 +56,7 @@ void halt() {
|
||||
}
|
||||
|
||||
static char command[160];
|
||||
static const unsigned long POWERSAVING_FIRST_SLEEP_SECS = 120;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
@@ -179,4 +180,21 @@ void loop() {
|
||||
#ifdef HAS_EXTERNAL_WATCHDOG
|
||||
external_watchdog.loop();
|
||||
#endif
|
||||
|
||||
if (the_mesh.getNodePrefs()->powersaving_enabled
|
||||
&& !board.isUsbDataConnected()) {
|
||||
uint32_t sleep_secs = the_mesh.getPowerSaveSleepSeconds(30);
|
||||
#ifdef HAS_EXTERNAL_WATCHDOG
|
||||
if (sleep_secs > 0) external_watchdog.feed();
|
||||
#endif
|
||||
#if defined(NRF52_PLATFORM)
|
||||
if (sleep_secs > 0) board.sleep(0);
|
||||
#else
|
||||
if (sleep_secs > 0
|
||||
&& the_mesh.millisHasNowPassed(
|
||||
POWERSAVING_FIRST_SLEEP_SECS * 1000UL)) {
|
||||
board.sleep(sleep_secs);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user