Power saving sensor (#2865)

* Trunk

* Again

* This thing just keeps updating itself

* Ignore tools

* Sleepy sensor

* Batrunkadunk
This commit is contained in:
Ben Meadors 2023-10-05 12:42:03 -05:00 committed by GitHub
parent fc06754e1f
commit 950d5f0946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 21 deletions

2
.trunk/.gitignore vendored
View File

@ -2,7 +2,7 @@
*logs *logs
*actions *actions
*notifications *notifications
*tools
plugins plugins
user_trunk.yaml user_trunk.yaml
user.yaml user.yaml
tools

View File

@ -1,48 +1,48 @@
version: 0.1 version: 0.1
cli: cli:
version: 1.13.0 version: 1.16.2
plugins: plugins:
sources: sources:
- id: trunk - id: trunk
ref: v1.1.1 ref: v1.2.5
uri: https://github.com/trunk-io/plugins uri: https://github.com/trunk-io/plugins
lint: lint:
enabled: enabled:
- bandit@1.7.5 - bandit@1.7.5
- checkov@2.4.1 - checkov@2.5.0
- terrascan@1.18.3 - terrascan@1.18.3
- trivy@0.44.1 - trivy@0.45.1
- trufflehog@3.48.0 - trufflehog@3.59.0
- taplo@0.8.1 - taplo@0.8.1
- ruff@0.0.284 - ruff@0.0.292
- yamllint@1.32.0 - yamllint@1.32.0
- isort@5.12.0 - isort@5.12.0
- markdownlint@0.35.0 - markdownlint@0.37.0
- oxipng@8.0.0 - oxipng@8.0.0
- svgo@3.0.2 - svgo@3.0.2
- actionlint@1.6.25 - actionlint@1.6.26
- flake8@6.1.0 - flake8@6.1.0
- hadolint@2.12.0 - hadolint@2.12.0
- shfmt@3.6.0 - shfmt@3.6.0
- shellcheck@0.9.0 - shellcheck@0.9.0
- black@23.7.0 - black@23.9.1
- git-diff-check - git-diff-check
- gitleaks@8.17.0 - gitleaks@8.18.0
- clang-format@16.0.3 - clang-format@16.0.3
- prettier@3.0.2 - prettier@3.0.3
disabled: disabled:
- taplo@0.8.1 - taplo@0.8.1
- shellcheck@0.9.0 - shellcheck@0.9.0
- shfmt@3.6.0 - shfmt@3.6.0
- oxipng@8.0.0 - oxipng@8.0.0
- actionlint@1.6.22 - actionlint@1.6.22
- markdownlint@0.35.0 - markdownlint@0.37.0
- hadolint@2.12.0 - hadolint@2.12.0
- svgo@3.0.2 - svgo@3.0.2
runtimes: runtimes:
enabled: enabled:
- python@3.10.8 - python@3.10.8
- go@1.19.5 - go@1.21.0
- node@18.12.1 - node@18.12.1
actions: actions:
disabled: disabled:

View File

@ -178,9 +178,9 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t cha
service.sendToMesh(p, RX_SRC_LOCAL, true); service.sendToMesh(p, RX_SRC_LOCAL, true);
if (config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER && config.power.is_power_saving) { if (config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER && config.power.is_power_saving) {
LOG_DEBUG("Starting next execution in 3 seconds and then going to sleep.\n"); LOG_DEBUG("Starting next execution in 5 seconds and then going to sleep.\n");
sleepOnNextExecution = true; sleepOnNextExecution = true;
setIntervalFromNow(3000); setIntervalFromNow(5000);
} }
} }

View File

@ -8,6 +8,8 @@
#include "configuration.h" #include "configuration.h"
#include "main.h" #include "main.h"
#include "power.h" #include "power.h"
#include "sleep.h"
#include "target_specific.h"
#include <OLEDDisplay.h> #include <OLEDDisplay.h>
#include <OLEDDisplayUi.h> #include <OLEDDisplayUi.h>
@ -51,6 +53,13 @@ SHT31Sensor sht31Sensor;
int32_t EnvironmentTelemetryModule::runOnce() int32_t EnvironmentTelemetryModule::runOnce()
{ {
if (sleepOnNextExecution == true) {
sleepOnNextExecution = false;
uint32_t nightyNightMs = getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval);
LOG_DEBUG("Sleeping for %ims, then awaking to send metrics again.\n", nightyNightMs);
doDeepSleep(nightyNightMs, true);
}
uint32_t result = UINT32_MAX; uint32_t result = UINT32_MAX;
/* /*
Uncomment the preferences below if you want to use the module Uncomment the preferences below if you want to use the module
@ -266,6 +275,12 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
} else { } else {
LOG_INFO("Sending packet to mesh\n"); LOG_INFO("Sending packet to mesh\n");
service.sendToMesh(p, RX_SRC_LOCAL, true); service.sendToMesh(p, RX_SRC_LOCAL, true);
if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR && config.power.is_power_saving) {
LOG_DEBUG("Starting next execution in 5 seconds and then going to sleep.\n");
sleepOnNextExecution = true;
setIntervalFromNow(5000);
}
} }
} }
return valid; return valid;

View File

@ -180,15 +180,19 @@ void cpuDeepSleep(uint32_t msecToWake)
digitalWrite(AQ_SET_PIN, LOW); digitalWrite(AQ_SET_PIN, LOW);
#endif #endif
#endif #endif
// FIXME, use system off mode with ram retention for key state? // Sleepy trackers or sensors can low power "sleep"
// FIXME, use non-init RAM per // Don't enter this if we're sleeping portMAX_DELAY, since that's a shutdown event
// https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled if (msecToWake != portMAX_DELAY &&
(config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER ||
if (config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER && config.power.is_power_saving == true) { config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR) &&
config.power.is_power_saving == true) {
sd_power_mode_set(NRF_POWER_MODE_LOWPWR); sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
delay(msecToWake); delay(msecToWake);
NVIC_SystemReset(); NVIC_SystemReset();
} else { } else {
// FIXME, use system off mode with ram retention for key state?
// FIXME, use non-init RAM per
// https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled
auto ok = sd_power_system_off(); auto ok = sd_power_system_off();
if (ok != NRF_SUCCESS) { if (ok != NRF_SUCCESS) {
LOG_ERROR("FIXME: Ignoring soft device (EasyDMA pending?) and forcing system-off!\n"); LOG_ERROR("FIXME: Ignoring soft device (EasyDMA pending?) and forcing system-off!\n");