Get battery charge script

Would it be possible to have a simple Python script that allows you to read the battery status (signal creation, subscribe, read, unsubscribe and callback function), working?
In the API documentation and examples (including testing), even readjusting (obviously) the procedure seems not to work.
The battery is charged: checked with nRFconnect and official matewear app.
Attached is the file I'm working on (rename with .py extension).
Thanks in advance!

Comments

  • def test_read_battery_state(self):
        expected= [0x11, 0xcc]
    
        battery_signal= self.libmetawear.mbl_mw_settings_get_battery_state_data_signal(self.board)
        self.libmetawear.mbl_mw_datasignal_read(battery_signal)
        self.assertEqual(self.command, expected)
    
    def test_read_battery_component(self):
        expected_cmds= [
            [0x11, 0xcc],
            [0x11, 0x8c]
        ]
    
        signal= self.libmetawear.mbl_mw_settings_get_battery_state_data_signal(self.board)
        voltage = self.libmetawear.mbl_mw_datasignal_get_component(signal, Const.SETTINGS_BATTERY_VOLTAGE_INDEX)
        charge = self.libmetawear.mbl_mw_datasignal_get_component(signal, Const.SETTINGS_BATTERY_CHARGE_INDEX)
    
        self.libmetawear.mbl_mw_datasignal_subscribe(charge, None, self.sensor_data_handler)
        self.libmetawear.mbl_mw_datasignal_read(voltage)
        self.libmetawear.mbl_mw_datasignal_read(charge)
    
  • @Laura said:
    def test_read_battery_state(self):
    expected= [0x11, 0xcc]

        battery_signal= self.libmetawear.mbl_mw_settings_get_battery_state_data_signal(self.board)
        self.libmetawear.mbl_mw_datasignal_read(battery_signal)
        self.assertEqual(self.command, expected)
    
    def test_read_battery_component(self):
        expected_cmds= [
            [0x11, 0xcc],
            [0x11, 0x8c]
        ]
    
        signal= self.libmetawear.mbl_mw_settings_get_battery_state_data_signal(self.board)
        voltage = self.libmetawear.mbl_mw_datasignal_get_component(signal, Const.SETTINGS_BATTERY_VOLTAGE_INDEX)
        charge = self.libmetawear.mbl_mw_datasignal_get_component(signal, Const.SETTINGS_BATTERY_CHARGE_INDEX)
    
        self.libmetawear.mbl_mw_datasignal_subscribe(charge, None, self.sensor_data_handler)
        self.libmetawear.mbl_mw_datasignal_read(voltage)
        self.libmetawear.mbl_mw_datasignal_read(charge)
    

    I had seen this example before and tried to implement it, but didn't read the values.

  • I recommend reading up on Python scripting.

  • Did you solve the problem? I have the same situation, I don´t understand the example in https://github.com/mbientlab/MetaWear-SDK-Cpp/blob/master/test/test_settings.py#L66

Sign In or Register to comment.