When is Electron Powered By Battery

For me this builds.
Have you got an Electron selected as target?
What system version are you targeting on that Electron?

1 Like

Gah.
My USB hub disconnected and it dropped back to photon and I didn’t spot it, cheers for the pointer.

Happy days.

2 Likes

Hello. I am an absolute newbie, and I have been searching for an answer to this very problem. I was beginning to think I was going to have to start from scratch. Thank you, all of you, especially @rickkas7 for generously sharing your work. It works perfectly! Now all I have to learn about is web hooks, and I just might get my boat’s powerfail alarm notifications!!

Hi @rickkas7 I’m attempting as a complete noob to understand this language. I need to add a delay in notification so that a power loss of a couple of seconds down’t trigger the Publish. Will a simple Wait() somewhere do it?

Do you know if it is possible to determine if power is coming from VIN or if it is coming from USB individually?

It’s possible to tell if you’re connected to a USB host (a computer, for example).

I’m pretty sure it’s not possible to tell the difference between being powered by a USB charger (not a host) and VIN.

2 Likes

@rickkas7,

Is there a version of PowerCheck I can use with the Boron? The version I have now will only compile for the Electron.

Awesome work BTW!

Chip

The battery interrupt code above is built into device OS now, and it’s much better to get the is battery powered state from device diagnostics. This code can be used instead of the code above:

@rickkas7,

OK, I understand. One question and please forgive me if it is obvious. The PowerSource code for the Electron could also determine whether the battery was charging or discharging. Do I need to use the getChargeCurrent() API call (for which there is not much in the docs) or is there an easier way to determine “charging” or “discharging”?

Just trying to match the functionality I have now on the Electron.

Thanks,

Chip

You can use DIAG_ID_SYSTEM_BATTERY_STATE for that. The valid values are:

typedef enum {
    BATTERY_STATE_UNKNOWN = 0,
    BATTERY_STATE_NOT_CHARGING = 1,
    BATTERY_STATE_CHARGING = 2,
    BATTERY_STATE_CHARGED = 3,
    BATTERY_STATE_DISCHARGING = 4,
    BATTERY_STATE_FAULT = 5,
    BATTERY_STATE_DISCONNECTED = 6
} battery_state_t;
3 Likes

Is there a way to get the charge amperage? I can charge with USB or Solar but if the input current is high enough (usb) I don’t wan’t the unit to go into power saving mode.