@@ -790,6 +790,18 @@ class STM32LoRaWAN : public Stream {
790790 */
791791 void setMaintainNeededCallback (std::function<void (void )> callback) { this ->maintain_needed_callback = callback; }
792792
793+ /* *
794+ * Registers a callback that is called whenever there is a DevStatusReq.
795+ *
796+ * BAT_LEVEL_EXT_SRC - The end-device is connected to an external power source
797+ * BAT_LEVEL_EMPTY - The battery is empty
798+ * 1..254 - The battery level, 1 being at minimum and 254 being at maximum
799+ * BAT_LEVEL_FULL - The battery is full
800+ * BAT_LEVEL_NO_MEASURE - The end-device was not able to measure the battery level
801+ *
802+ * \NotInMKRWAN
803+ */
804+ void setBatteryLevelCallback (std::function<uint8_t (void )> callback) { this ->battery_level_callback = callback; }
793805 // / @}
794806
795807 /* *
@@ -957,6 +969,7 @@ class STM32LoRaWAN : public Stream {
957969 static void MacMlmeConfirm (MlmeConfirm_t *MlmeConfirm);
958970 static void MacMlmeIndication (MlmeIndication_t *MlmeIndication, LoRaMacRxStatus_t *RxStatus);
959971 static void MacProcessNotify ();
972+ static uint8_t GetBatteryLevel ();
960973
961974 static STM32LoRaWAN *instance;
962975
@@ -968,7 +981,7 @@ class STM32LoRaWAN : public Stream {
968981 };
969982
970983 LoRaMacCallback_t LoRaMacCallbacks = {
971- .GetBatteryLevel = nullptr ,
984+ .GetBatteryLevel = GetBatteryLevel ,
972985 .GetTemperatureLevel = nullptr ,
973986 .GetUniqueId = nullptr , // Not needed, we just explicitly set the deveui in begin()
974987 .GetDevAddress = nullptr , // Not needed, user explicitly configures devaddr
@@ -1046,6 +1059,7 @@ class STM32LoRaWAN : public Stream {
10461059 uint32_t fcnt_down = 0 ;
10471060
10481061 std::function<void (void )> maintain_needed_callback;
1062+ std::function<uint8_t (void )> battery_level_callback;
10491063
10501064 bool mac_process_pending = false ;
10511065
0 commit comments