The Wirnet iStation gateway includes an internal backup battery allowing to detect power loss.
Level of battery charge can be monitored through VCC_BACKUP ADC sensor. This backup battery is charged on main power called 12V_POE so taking into account hardware implementation, maximum value of VCC_BACKUP is around 11.8V (main 12V - 0.2V).
In the following example, a few time after a cold boot, we can see that Backup battery is charging (5.9V instead 11.8V).
root@klk-wiis-05005E:~# sensors | egrep 'POE|BACKUP' 12V_POE: +12.03 V VCC_BACKUP: +5.93 V
As examples, power loss could be detected by these 2 methods (to be adapted depending on the application and use-case):
The first thing to do in power-down sequence is to power down lora modem as soon as possible to disable its power consumption.
The voltage values can be obtained with the following methods:
root@klk-wiis-05005E:~# sensors | egrep 'POE|BACKUP' 12V_POE: +12.02 V VCC_BACKUP: +11.89 V
Examples with power loss early detected
or, in C with lmsensors library:
#include <sensors/sensors.h> static int get_sensor_voltage(const char * pName, double * pVoltage) { const sensors_chip_name *chip; const sensors_feature *feature; const sensors_subfeature * subfeature; int chip_nr, i; char *label = NULL; double voltage = 0; int result = -1; int ret; ret = sensors_init(NULL); if (ret != 0) { syslog(LOG_ERR, "[%s:%d] err %d in sensors_init\n", __FUNCTION__, __LINE__, ret); return result; } chip_nr = 0; while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) { i = 0; while ((feature = sensors_get_features(chip, &i))) { label = sensors_get_label(chip, feature); if (label != NULL) { subfeature = sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_IN_INPUT); if ((strcmp(pName, label) == 0) && (subfeature != NULL)) { if (sensors_get_value(chip, subfeature->number, &voltage) == 0) { *pVoltage = voltage; result = 0; } } free(label); label = NULL; } } } sensors_cleanup(); return result; } double voltage = 0; get_sensor_voltage("12V_POE", &voltage);
All internal voltage measurement can be obtained using the following tool:
root@klk-wiis-05005E:~# sensors klk_wiis_adc-isa-0000 Adapter: ISA adapter VDD_CORE: +1.39 V NVCC_DRAM: +1.34 V VCC_DIG_1V8: +1.85 V NVCC_3V3: +3.29 V 12V_POE: +12.03 V VCC_BACKUP: +11.53 V VCC_5V: +4.94 V VCC_RF: +1.93 V