Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracker role wakeup and sleep cycle when power.is_power_saving true #2846

Merged
merged 15 commits into from
Oct 1, 2023

Conversation

thebentern
Copy link
Contributor

@thebentern thebentern commented Sep 28, 2023

Current flow if device is Tracker role and power.is_power_saving is enabled is as follows:

  1. Remove delayed startup for PositionModule so that we start the thread immediately

  2. Clear last node->position.lat / lon to zero, so that we don't just immediately broadcast the last (stale) position

  3. Upon valid position and successful send (which should happen as soon as we get a fix), go to sleep for position_broadcast_secs.

  4. Wake up and start the process over again.

@thebentern thebentern marked this pull request as ready for review September 29, 2023 21:29
@thebentern
Copy link
Contributor Author

thebentern commented Sep 29, 2023

Addresses part of #2845
I tested primarily with the RAK+GPS and the Heltec Wireless Tracker. The S3's super deep sleep current was expectedly low. Lower than I can measure with any equipment here.

NRF's low power mode (NRF_POWER_MODE_LOWPWR) which @andrekir discovered I believe, turned out to be a really neat find. I was able to get the RAK down to between 0.8-0.9mA after it went through normal the shutdown sequence to turn off peripherals and drop into this mode. I'm curious to see how the T-Echo might fare with the same sequence.
image

Also, would like someone to test on T-Beam and other hardware as well.

A good configuration is:
meshtastic --set device.role TRACKER --set power.is_power_saving true --set position.position_broadcast_secs 60

@andrekir
Copy link
Member

wow! well done!

ran a quick test on a T-Echo with suggested settings and power cycle works perfect.

only issue is when the GPS fix is quick, it enters deep sleep before broadcasting the position:

//\ E S H T /\ S T / C

DEBUG | ??:??:?? 4 Filesystem files:
DEBUG | ??:??:?? 4  db.proto (501 Bytes)
DEBUG | ??:??:?? 4  config.proto (87 Bytes)
DEBUG | ??:??:?? 4  module.proto (72 Bytes)
DEBUG | ??:??:?? 4  channels.proto (275 Bytes)
DEBUG | ??:??:?? 4 Using analog input 4 for battery level
INFO  | ??:??:?? 4 Scanning for i2c devices...
DEBUG | ??:??:?? 4 Scanning for i2c devices on port 1
DEBUG | ??:??:?? 4 I2C device found at address 0x51
INFO  | ??:??:?? 4 PCF8563 RTC found
INFO  | ??:??:?? 4 1 I2C devices found
DEBUG | ??:??:?? 4 acc_info = 0
INFO  | ??:??:?? 4 Meshtastic hwvendor=7, swver=2.2.10.0333fe0
DEBUG | ??:??:?? 4 Reset reason: 0x0
DEBUG | ??:??:?? 4 Setting random seed 1239140252
INFO  | ??:??:?? 4 Initializing NodeDB
INFO  | ??:??:?? 4 Loading /prefs/db.proto
INFO  | ??:??:?? 4 Loaded saved devicestate version 22
INFO  | ??:??:?? 4 Loading /prefs/config.proto
INFO  | ??:??:?? 4 Loaded saved config version 22
INFO  | ??:??:?? 4 Loading /prefs/module.proto
INFO  | ??:??:?? 4 Loaded saved moduleConfig version 22
INFO  | ??:??:?? 4 Loading /prefs/channels.proto
INFO  | ??:??:?? 4 Loaded saved channelFile version 22
INFO  | ??:??:?? 4 No /oem/oem.proto preferences found
DEBUG | ??:??:?? 4 cleanupMeshDB purged 0 entries
INFO  | ??:??:?? 4 Wanted region 1, using US
DEBUG | ??:??:?? 4 region=1, NODENUM=0x5a4989b0, dbsize=4
DEBUG | ??:??:?? 4 Read RTC time from PCF8563 as 536901508
INFO  | 22:33:52 4 Setting GPS power=1
INFO  | 22:33:52 4 Waking GPSWANT GPS=1
INFO  | 22:33:52 4 Setting GPS power=1
INFO  | 22:33:52 4 Waking GPSClearing position on startup for sleepy tracker (?????????) zzz
DEBUG | 22:33:52 4 NeighborInfoModule is disabled
INFO  | 22:33:52 4 External Notification Module Disabled
INFO  | 22:33:52 4 Doing EInk init
INFO  | 22:33:52 4 Turning on screen
DEBUG | 22:33:52 4 Updating E-Paper... done
DEBUG | 22:33:54 7 Module wants a UI Frame
WARN  | 22:33:54 7 SX126xInterface(cs=24, irq=20, rst=25, busy=17)
DEBUG | 22:33:55 7 SX126X_DIO3_TCXO_VOLTAGE defined, using DIO3 as TCXO reference voltage at 1.800000 V
INFO  | 22:33:55 7 Starting meshradio init...
DEBUG | 22:33:55 7 (bw=250, sf=11, cr=4/8) packet symLen=8 ms, payloadSize=0, time 231 ms
DEBUG | 22:33:55 7 (bw=250, sf=11, cr=4/8) packet symLen=8 ms, payloadSize=253, time 3246 ms
INFO  | 22:33:55 7 Radio freq=927.625, config.lora.frequency_offset=0.000
INFO  | 22:33:55 7 Set radio: region=US, name=Primary1, config=0, ch=102, power=30
INFO  | 22:33:55 7 Radio myRegion->freqStart -> myRegion->freqEnd: 902.000000 -> 928.000000 (26.000000 mhz)
INFO  | 22:33:55 7 Radio myRegion->numChannels: 104 x 250.000kHz
INFO  | 22:33:55 7 Radio channel_num: 103
INFO  | 22:33:55 7 Radio frequency: 927.625000
INFO  | 22:33:55 7 Slot time: 42 msec
INFO  | 22:33:55 7 Set radio: final power level=22
INFO  | 22:33:55 7 SX126x init result 0
INFO  | 22:33:55 7 Frequency set to 927.625000
INFO  | 22:33:55 7 Bandwidth set to 250.000000
INFO  | 22:33:55 7 Power output set to 22
DEBUG | 22:33:55 7 Current limit set to 140.000000
DEBUG | 22:33:55 7 Current limit set result 0
DEBUG | 22:33:55 7 Setting DIO2 as RF switch
DEBUG | 22:33:55 7 SX126X_RXEN not defined, defaulting to RADIOLIB_NC
DEBUG | 22:33:55 7 SX126X_TXEN not defined, defaulting to RADIOLIB_NC
DEBUG | 22:33:55 7 Using MCU pin -1 as RXEN and pin -1 as TXEN to control RF switching
INFO  | 22:33:55 7 Set RX gain to power saving mode (boosted mode off); result: 0
INFO  | 22:33:55 7 SX1262 Radio init succeeded, using SX1262 radio
DEBUG | 22:33:55 7 (bw=250, sf=11, cr=4/8) packet symLen=8 ms, payloadSize=237, time 3057 ms
DEBUG | 22:33:55 7 LoRA bitrate = 77.526985 bytes / sec
INFO  | 22:33:55 7 PowerFSM init, USB power=0
DEBUG | 22:33:55 7 Enter state: BOOT
DEBUG | 22:33:55 7 [Power] Battery: usbPower=1, isCharging=1, batMv=4690, batPct=100
DEBUG | 22:33:55 7 [Screen] Screen: Started...
DEBUG | 22:33:55 7 [Screen] Updating E-Paper... done
DEBUG | 22:33:58 10 [GPS] Probing for GPS at 9600 
INFO  | 22:33:58 10 [GPS] L76K GNSS init succeeded, using L76K GNSS Module
INFO  | 22:33:59 11 [RangeTestModule] Range Test Module - Disabled
DEBUG | 22:33:59 11 [PowerFSM] Enter state: ON
INFO  | 22:33:59 11 [PowerFSM] Initialize the Bluefruit nRF52 module
INFO  | 22:33:59 11 [PowerFSM] Bluetooth pin set to '299406'
INFO  | 22:33:59 11 [PowerFSM] Configuring the Device Information Service
INFO  | 22:33:59 11 [PowerFSM] Configuring the Battery Service
INFO  | 22:33:59 11 [PowerFSM] Configuring the Mesh bluetooth service
INFO  | 22:33:59 11 [PowerFSM] Setting up the advertising payload(s)
INFO  | 22:33:59 11 [PowerFSM] Advertising
DEBUG | 22:33:59 11 [Screen] Updating E-Paper... done
DEBUG | 22:34:02 14 [GPS] NMEA GPS time 2023-09-29 22:34:03
DEBUG | 22:34:02 14 [GPS] Upgrading time to quality 4
DEBUG | 22:34:03 14 [GPS] PCF8563_RTC setDateTime 2023-09-29 22:34:03 536953672
DEBUG | 22:34:03 14 [GPS] Read RTC time from PCF8563 as 536901508
DEBUG | 22:34:03 14 [GPS] hasValidLocation RISING EDGE
DEBUG | 22:34:03 14 [GPS] WANT GPS=0
DEBUG | 22:34:03 14 [GPS] GPS Lock took 10, average 0
INFO  | 22:34:03 14 [GPS] Setting GPS power=0
INFO  | 22:34:03 14 [GPS] GPS entering sleeppublishing pos@651750db:2, hasVal=1, Sats=8, GPSlock=1
DEBUG | 22:34:03 14 [GPS] New GPS pos@651750db:3 lat=XX.XXXXXX, lon=XX.XXXXXX, alt=504, pdop=2.67, track=0.00, speed=0.00, sats=8
DEBUG | 22:34:03 14 [GPS] onGPSChanged() pos@651750db, time=1696026843, lat=XXXXXXXXX, lon=XXXXXXXXX, alt=504
INFO  | 22:34:03 14 [GPS] updatePosition LOCAL pos@651750db, time=1696026843, latI=XXXXXXXXX, lonI=XXXXXXXXX, alt=504
DEBUG | 22:34:03 14 [GPS] Node status update: 2 online, 4 total
INFO  | 22:34:03 14 [GPS] Sending smart pos@651750db:6 to mesh (distanceTraveled=5581046.500000m, minDistanceThreshold=100m, timeElapsed=14414ms)
INFO  | 22:34:03 14 [GPS] Providing time to mesh 1696026843
INFO  | 22:34:03 14 [GPS] Position reply: time=1696026843, latI=XXXXXXXXX, lonI=XXXXXXXXX
DEBUG | 22:34:03 14 [GPS] Initial packet id 121779358, numPacketId 4294967295
DEBUG | 22:34:03 14 [GPS] Update DB node 0x5a4989b0, rx_time=1696026843, channel=0
DEBUG | 22:34:03 14 [GPS] handleReceived(LOCAL) (id=0x074234a0 fr=0xb0 to=0xff, WantAck=0, HopLim=3 Ch=0x0 Portnum=3 WANTRESP rxtime=1696026843 priority=70)
DEBUG | 22:34:03 14 [GPS] No modules interested in portnum=3, src=LOCAL
DEBUG | 22:34:03 14 [GPS] localSend to channel 0
DEBUG | 22:34:03 14 [GPS] Add packet record (id=0x074234a0 fr=0xb0 to=0xff, WantAck=0, HopLim=3 Ch=0x0 Portnum=3 WANTRESP rxtime=1696026843 priority=70)
DEBUG | 22:34:03 14 [GPS] Using AES256 key!
DEBUG | 22:34:03 14 [GPS] Software encrypt fr=5a4989b0, num=74234a0, numBytes=24!
DEBUG | 22:34:03 14 [GPS] enqueuing for send (id=0x074234a0 fr=0xb0 to=0xff, WantAck=0, HopLim=3 Ch=0xc2 encrypted rxtime=1696026843 priority=70)
DEBUG | 22:34:03 14 [GPS] txGood=0,rxGood=0,rxBad=0
DEBUG | 22:34:03 14 [GPS] Using channel 0 (hash 0xc2)
DEBUG | 22:34:03 14 [GPS] Using AES256 key!
DEBUG | 22:34:03 14 [GPS] Software encrypt fr=5a4989b0, num=74234a0, numBytes=24!
DEBUG | 22:34:03 14 [GPS] decoded message (id=0x074234a0 fr=0xb0 to=0xff, WantAck=0, HopLim=3 Ch=0x0 Portnum=3 WANTRESP rxtime=1696026843 priority=70)
DEBUG | 22:34:03 14 [GPS] Sleeping for 60000ms, then awaking to send position again.
INFO  | 22:34:03 14 [GPS] Entering deep sleep for 60 seconds
INFO  | 22:34:03 14 [GPS] Disable NRF52 bluetooth
DEBUG | 22:34:03 14 [GPS] SX126x entering sleep mode (FIXME, don't keep config)
DEBUG | 22:34:03 14 [GPS] Starting low level send (id=0x074234a0 fr=0xb0 to=0xff, WantAck=0, HopLim=3 Ch=0xc2 encrypted rxtime=1696026843 priority=70)
DEBUG | 22:34:03 14 [GPS] (bw=250, sf=11, cr=4/8) packet symLen=8 ms, payloadSize=40, time 714 ms
DEBUG | 22:34:03 14 [GPS] AirTime - Packet transmitted : 714ms
DEBUG | 22:34:03 14 [GPS] Completed sending (id=0x074234a0 fr=0xb0 to=0xff, WantAck=0, HopLim=3 Ch=0xc2 encrypted rxtime=1696026843 priority=70)
INFO  | 22:34:03 14 [GPS] GPS deep sleep!
DEBUG | 22:34:03 14 [GPS] Updating E-Paper... done
INFO  | 22:34:05 17 [GPS] Turning off screen
INFO  | 22:34:06 17 [GPS] Saving /prefs/db.proto
INFO  | 22:34:07 18 [GPS] Saving /prefs/config.proto
INFO  | 22:34:08 19 [GPS] Saving /prefs/module.proto
INFO  | 22:34:09 20 [GPS] Saving /prefs/channels.proto
INFO  | 22:34:10 21 [GPS] Setting GPS power=0

@thebentern
Copy link
Contributor Author

thebentern commented Sep 30, 2023

only issue is when the GPS fix is quick, it enters deep sleep before broadcasting the position:

wow! well done!

ran a quick test on a T-Echo with suggested settings and power cycle works perfect.

only issue is when the GPS fix is quick, it enters deep sleep before broadcasting the position:

Thanks! 😄
I'll look into the race condition with the position broadcast. Oddly enough something I want to circle back to is that when I didn't skip the preflight code, it would never sleep, because the lora txqueue was never indicated as empty. Not sure why... maybe a bug in the queue implementation. I'll do some more digging

@github-actions
Copy link
Contributor

🤖 Pull request artifacts

file commit
pr2846-firmware-2.2.10.92081a2.zip 92081a2

thebentern added a commit to meshtastic/artifacts that referenced this pull request Sep 30, 2023
@thebentern thebentern merged commit 1552aa0 into master Oct 1, 2023
@thebentern thebentern deleted the sleepy-trackers branch October 1, 2023 02:09
jp-bennett pushed a commit that referenced this pull request Oct 2, 2023
…2846)

* WIP

* Sleepy sleepy low power tracker

* Sleepy tracker clear

* NRF52 PoC

* Simplify NRF52 "sleep"

* Trackers aren't polite

* Remove unnecessary include

* Removed accidental commit

* Fixed not-so-sleepy T-Beam due to button gpio mask precendence

* Added sleepOnNextExecution for allowing fulfillment of pending messages before shutting down

* Cleanup

* Don't wantResponse for trackers

* Heltec wireless tracker doesn't like the button interrupt (maybe all s3 because user button press doubles as bootloader mode trigger?)
@rpsainio
Copy link

rpsainio commented Oct 3, 2023

Just updated one TBeam with above mentioned pr-2.2.10 and it seems to go properly DeepSleep. I wil let it run longer time to see that also devicetelemetry comes to my MQTT-server. If that one works I can plot a battery curve for different position_broadcast_secs values

@meshtastic-bot
Copy link

This pull request has been mentioned on Meshtastic. There might be relevant details there:

https://meshtastic.discourse.group/t/hardware-for-an-animal-tracker-dog-collar/10924/14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants