ausocean / cloud

GNU General Public License v3.0
1 stars 1 forks source link

broadcast.go: modify how device shutdown is performed at broadcast end #31

Open saxon-milton opened 5 months ago

saxon-milton commented 5 months ago

We’d like to start safely shutting down devices i.e. perform an OS shutdown before cutting power. To do this, we’ll need to evolve the methodology currently in use by the broadcast functionality for dealing with shutdown of devices, that is, a list of variable-value pairs that indicate what variables to set and to what values on shutdown time.

Up until this point, this has generally been setting of the ESP’s pin for device power control to false i.e. a hard powering off of the device. In doing so, we risk corrupting the device. It’s therefore proposed that the broadcast functionality instead uses a “Shutdown” response code, as available through the shutdown button on the devices page. We may need to modify this functionality so that not only does an OS shutdown happen, but additionally powering off of the peripheral power supply through the ESP. For this purpose, it’s proposed that we add a variable to devices (unused by the device) that contains the ID of the ESP pin that controls power for the device. This variable we’ll be used to set the ESP pin to false after the OS shutdown has occurred.

If we enclose this functionality into a function, the crons functionality could also adopt this i.e. add as a “call” action option. Then, even crons can safely power down devices.

scruzin commented 4 months ago

Setting the mode var to Shutdown can already be used to perform a graceful shutdown. The missing functionality is waiting for the shutdown to take effect before turning off the relay that powers the device. Therefore, introducing the notion of a pause between camera on/off actions might be sufficient.

That said, having a 'shutdown' function that could be called either by the broadcast manager or crons alike is also attractive.