How to understand which power source is active, battery or grid?

On my MkrWan 1310 board I am using battery and external power source. Normally, MkrWan1310 charges the battery when there is no power outage on line. I want to get which one of these power source is active currently to understand power outages on grid. Is it possible ?

You need to make a simple pencil drawing showing how everything is connected and post a photo of the drawing. See this Simple Image Posting Guide

Assuming you have a mains to DC power unit and if the battery cannot back-feed to the DC power then you should be able to tell if the DC power is active by monitoring its voltage.

...R

Just run a relay off the mains side , so relay energised if the mains supply is on . Use the contacts as a digital input .

@hammy you are right, it can be detected by using relay but is it possible to understand from software without any relay ?

Instead of a relay, you could power a lightbulb from the mains, and detect whether it is lit or not. Or if the filament has failed.

vbulbul:
@hammy you are right, it can be detected by using relay but is it possible to understand from software without any relay ?

Have you considered Reply #1?

I must say that I like the relay idea.

...R

As I understand there is no way to undertsand the source of power from sorftware( battery or DC Power Unit), I will work with relay. Thanks to everyone.