-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add function wifi.sleep #725
Conversation
I like the idea here, but it feels like there's a mismatch between the exposed Lua API and the underlying SDK API. Using wifi.sleep(1) will only put the radio to sleep for a maximum of 268 seconds (less than 5min) if I'm reading this correctly. The expectation I would have as a user would be that the wifi is put to sleep until I call wifi.sleep(0). |
Judging by what the SDK programming guide(v 1.4.0) says on page 86 under the function Also, I've found that in my own testing the wifi radio stays asleep much longer than 268.4 seconds. |
That's what I get for not RTFM'ing the full thing and only looking at user_interface.h. This is looking pretty good then! My only question is whether there is any particular reason why the new flag variable isn't declared static? Unless someone has objections, I'd be happy to merge this in this week. |
+1 It should be |
Added static keyword to a variable
Oops, I forgot to add the keyword, thanks for pointing that out. I was thinking of adding code to return an error if Any other ideas or suggestions? |
As a general rule if a system routine returns a status, then we should not ignore this, as doing so causes silent failures that are incredibly difficult to debug. So either a lua_error() or a return status IMO, and the latter is probably easier for everybody. |
how about adding the return value so it is also returned with current wifi status similar to this: |
My ideas was similar. Why not follow the new_wifi_sleep_state = wifi.sleep(1) |
This pull request adds functionality to force wifi radio into sleep mode without restart.
This is also workaround for the deep sleep issue #721 where executing
node.dsleep(us, 4)
does not disable radio upon waking upwifi.sleep()
Description
Force wifi radio into sleep mode.
Note:
Syntax
wifi.sleep()
wifi.sleep(desired_sleep_state)
Parameters
desired_sleep_state: (if sleep state was changed, return new sleep state. otherwise return current sleep state)
Returns
Current WiFi sleep mode
Example