Skip to content

Commit 0102b95

Browse files
authored
Merge pull request #60 from bablokb/deep_sleep
added deep_sleep()
2 parents a26ab4e + dc1efd2 commit 0102b95

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

adafruit_espatcontrol/adafruit_espatcontrol.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,3 +657,18 @@ def hard_reset(self) -> None:
657657
time.sleep(3) # give it a few seconds to wake up
658658
self._uart.reset_input_buffer()
659659
self._initialized = False
660+
661+
def deep_sleep(self, duration_ms: int) -> bool:
662+
"""Execute deep-sleep command.
663+
Passing zero as argument will put the chip into deep-sleep forever
664+
until the RST-pin is pulled low (method hard_reset()).
665+
This is the typical use-case for an ESP8266 as coprocessor.
666+
667+
Note that a similar method in the Arduino-libs expects microseconds.
668+
"""
669+
cmd = "AT+GSLP=" + str(duration_ms)
670+
try:
671+
self.at_response(cmd, retries=1)
672+
return True
673+
except OKError:
674+
return False

0 commit comments

Comments
 (0)