Luckiliy you don't need to compile a new image because this function is already implemented in the deepsleep function of module esp.
(don't use deepsleep from machine). This parameter is not documented but if you look at the source code you see system_deep_sleep_set_option is called with the second parameter of deepsleep..
So here are the steps to switch of the RF circuit while processor is running normally ( this means at about 15 mA)
1. Run this code once (it switches off the RF station/ap and will store these settings)
Code: Select all
import network
ap = network.WLAN(network.AP_IF)
ap.active(False) # Disable access point
sta_if = network.WLAN(network.STA_IF)
sta_if.active(False) # Disable station interface
Code: Select all
from esp import deepsleep
from machine import reset_cause, DEEPSLEEP_RESET
if not reset_cause() == DEEPSLEEP_RESET:
# call 'system_deep_sleep_set_option' with value 4 and go to sleep for 1 uS
deepsleep(1, 4)
else:
print("Low power !!)
# Here the start of your program, running at ~ 15mA
# for example:
import myapp
myapp.run()
# Do not put code here otherwise deepsleep will not be called !!
One thing to remember is that you have to connect the reset pin with gpio16 (to wake up the processor after deepsleep)