sleep(0) in V2.1 doesn't sleep indefinitely anymore. Used to powerdown and sleep in V1.5
-
For battery powered nodes that need to completely sleep between events sleep(0) could be used in V1.5 in conjunction with the pin change interrupts on portC of an ATmega 328p. It would gracefully power down the radio and then enter the CPU into sleep mode until a pin change event on port C woke it up. In V2.1 sleep(0) simply returns. PortC pin-change mode is needed because INT0 and INT1 only work on either falling or raising level changes but not on either edge at the same time on the 328p .
I modified the file MyHwAVR.cpp as follows to restore the missing functionality back into V2.1 : Lines 150 and up:
int8_t hwSleep(unsigned long ms) { if (ms>0) { // sleep for defined time hwInternalSleep(ms); return MY_WAKE_UP_BY_TIMER; } else { // Fix for missing feature that allowed (in 1.5.1) to use the pin chnage interrupt with a sleep(0) to completely power down the system // sleep until ext interrupt triggered hwPowerDown(SLEEP_FOREVER); return 0; } }
Let me know if this is the correct venue to bring this to the attention of the code maintainers, or if I should go and furnish a git pull request or something like that.
Or if this has been addressed in post V2.1.1 releases
Thanks
gary
-
Thanks @garystofer
Looks to me like this was fixed in https://github.com/mysensors/MySensors/pull/1113
You seem to be using very old code
-
@mfalkvidd No, the issue with sleep(0) still exists in V2.3.2. That is the version that the ArDuino Library installer installs currently . -- Work around is to call hwPowerDown(WDTO_SLEEP_FOEREVER) as in above code if you want the battery to last more than a day.
GS
Suggested Topics
-
Code for beta-testing?
Controllers • 24 Mar 2014, 20:48 • andriej 9 Aug 2014, 10:44 -
Making WiFiManager compatible with MySensors 2.3.2
Bug Reports • 12 Feb 2020, 21:43 • pihome 1 Jun 2022, 16:02 -
RFM95W sleep() directly after send() often doesn't sleep radio
Bug Reports • 1 Jan 2023, 18:41 • prawnpie 8 Jan 2023, 05:36 -
Sensor presentation failure
Bug Reports • 31 Jul 2016, 19:23 • Sergio Rius 3 Mar 2021, 18:48 -
some differences between serial- and tcp-gateways.
Bug Reports • 15 Mar 2023, 09:26 • Branther 30 Mar 2023, 15:40 -
Missing "__libc_init_array();" wenn using samd without USB
Bug Reports • 6 Jul 2022, 08:36 • ltigges 7 Jul 2022, 22:43