Detecting and Reporting power outage via Electron?

It is possible to programmatically recognize when the power from the USB port is removed and the system switches to battery power on the Electron? My project will be plugged in 24/7 but it will also have a Lipo battery (which should always be fully charged via the wall power) and when the power goes out I would like to publish an event that notes that wall power is gone.

I believe if power is withdrawn from the USB port, the Electron automatically switches to battery power if available. But is there someway of detecting in code when that switch occurs so an event can be fired? Does VIN go to zero or switch to the value being provided by the battery? If the latter, I guess I could check for sudden changes in the VIN value but that seems fraught.

Have you hit the search button for this yet? There are several topics about this already.

2 Likes

Thank you for the link to this topic. I tried searching for ‘power outage’ and ‘electron’ with no luck but I will try harder next time. This looks like it will do the trick.

3 Likes