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

[Feature Request] Handle Light Sleep or Deep Sleep #75

Open
txf- opened this issue Feb 28, 2024 · 7 comments
Open

[Feature Request] Handle Light Sleep or Deep Sleep #75

txf- opened this issue Feb 28, 2024 · 7 comments

Comments

@txf-
Copy link

txf- commented Feb 28, 2024

Is your feature request related to an issue you've encountered? If so, please elaborate.
Given the fact that there are several tasks running in parallel it is hard to determine as to where one can put the device to sleep. Should each task be suspended one-by-one and then sleep should be handled in the MQTT process loop? presumably if one would like to opportunistically enter light sleep MQTT keep alives periods should be considered.

Describe the new feature request
In the example it would be nice to have a hint, or have special events to indicate when the best time would be to sleep, if desired. As there are a lot of abstractions away from a single loop, there could be a central way to trigger it, possibly in the agent?

@archigup
Copy link
Member

Hi, could you explain the use case a bit more?

If I understand correctly, the intent is to get the device to go into sleep between receiving MQTT messages?

@txf-
Copy link
Author

txf- commented Feb 29, 2024

Actually, in my specific case is the device will have periods of activity where they're sending lots of sensor messages, and then variable periods of inactivity, where they're not taking any readings or sending anything.

However the device needs to be able to wake up from an external gpio interrupt and resume taking readings and sending that data.

If my device needs to receive any data I will schedule it to fetch it during periods of activity.

I'm just looking for any guidance as to what tasks I should suspend and where would be the best place to call light sleep. In my case, deep sleep is probably out of the question as it would take too long to reboot, but light sleep with the modem off would be a reasonable compromise.

@archigup
Copy link
Member

archigup commented Mar 5, 2024

For either sleep, you should not need to suspend any tasks. No tasks will run while the device is sleeping.

@txf-
Copy link
Author

txf- commented Mar 6, 2024

For example, would MQTT keep alives be scheduled to be sent by the device if it enters light sleep? Or would I need to set up a wake timer?

@ActoryOu
Copy link
Member

Hi @txf-,

It depends on the definition of light sleep. As @archigup mentioned, if all tasks are suspended, no tasks will run. Referring to the example provided in this repository, a separate MQTT agent manager task handles all commands by calling MQTTAgent_CommandLoop. In that case, this task must be running to send the MQTT keep-alive ping message to the server when necessary. @archigup, Please correct me if I'm wrong.

Thank you.

@txf-
Copy link
Author

txf- commented Mar 28, 2024

In that case, this task must be running to send the MQTT keep-alive ping message to the server when necessary.

Yes that is the kind of thing I'm mostly concerned about. Does automatic light sleep (the Freertos tickless idle) contemplate the scheduling necessary for the device to wake in time for the command loop to send these messages?

@ActoryOu
Copy link
Member

ActoryOu commented Apr 1, 2024

The behavior may depend on the receive timeout setting, which is 1s by default. If the receive timeout is configured to be shorter than the keep-alive period, it could trigger the process to maintain the MQTT session active.

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

No branches or pull requests

3 participants