@@ -790,6 +790,18 @@ class STM32LoRaWAN : public Stream {
790
790
*/
791
791
void setMaintainNeededCallback (std::function<void (void )> callback) { this ->maintain_needed_callback = callback; }
792
792
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; }
793
805
// / @}
794
806
795
807
/* *
@@ -957,6 +969,7 @@ class STM32LoRaWAN : public Stream {
957
969
static void MacMlmeConfirm (MlmeConfirm_t *MlmeConfirm);
958
970
static void MacMlmeIndication (MlmeIndication_t *MlmeIndication, LoRaMacRxStatus_t *RxStatus);
959
971
static void MacProcessNotify ();
972
+ static uint8_t GetBatteryLevel ();
960
973
961
974
static STM32LoRaWAN *instance;
962
975
@@ -968,7 +981,7 @@ class STM32LoRaWAN : public Stream {
968
981
};
969
982
970
983
LoRaMacCallback_t LoRaMacCallbacks = {
971
- .GetBatteryLevel = nullptr ,
984
+ .GetBatteryLevel = GetBatteryLevel ,
972
985
.GetTemperatureLevel = nullptr ,
973
986
.GetUniqueId = nullptr , // Not needed, we just explicitly set the deveui in begin()
974
987
.GetDevAddress = nullptr , // Not needed, user explicitly configures devaddr
@@ -1046,6 +1059,7 @@ class STM32LoRaWAN : public Stream {
1046
1059
uint32_t fcnt_down = 0 ;
1047
1060
1048
1061
std::function<void (void )> maintain_needed_callback;
1062
+ std::function<uint8_t (void )> battery_level_callback;
1049
1063
1050
1064
bool mac_process_pending = false ;
1051
1065
0 commit comments