Get Battery Level and RSSI in JavaScript

I need to query the Battery Level after the MetaMotionR is found. I also want to query the RSSI value each second.

How can I do this using JavaScript?

Comments

  • edited July 2018

    Thanks Eric, but it´s still not clear to me how to realize it in JavaScript.

    Regarding the battery, this is my approach:

    function batteryHandler(board, onDataCallback){
      battery_signal = MetaWear.mbl_mw_settings_get_battery_state_data_signal(board);
      MetaWear.mbl_mw_datasignal_subscribe(battery_signal, MetaWear.FnVoid_DataP.toPointer(onDataCallback));
      MetaWear.mbl_mw_datasignal_read(battery_signal);
    }
    
    let onBatteryDataCallback = (data) => {
        let state = data.deref().value;
            console.log(state);     // prints another Buffer <Buffer@0x1a2e3d8 >
    };
    ServiceMeMoHardware.batteryHandler(newMeMo.board, onBatteryDataCallback);
    

    How can I realize the inner part?

    auto state = (MblMwBatteryState*) data->value;
    printf("{voltage: %dmV, charge: %d}\n", state->voltage, state->charge);
    
  • Ok, I was thinking too quick, got the battery query work now:

          let onBatteryDataCallback = (dataPtr) => {
            let data = dataPtr.deref();
            let MblMwBatteryState = data.parseValue();
            /* MblMwBatteryState Public Attributes
                voltage: Voltage level [mV]
                charge: 0-100 [%]
            */
            console.log('Charge ' + MblMwBatteryState.charge + '%');
          };
          ServiceMeMoHardware.batteryHandler(newMeMo.board, onBatteryDataCallback);
    

    For the RSSI issue I don't really see any approach... I need to get the new RSSi value each time it changes...

        peripheral.once('rssiUpdate', callback(rssi));
        peripheral.updateRssi([callback(error, rssi)]);
    

    How can I use the Noble functions? Could someone please provide a quick JavaScript example?

  • You should check the Noble GtiHub repo for code examples / ask Noble specific questions there.

  • Hi Eric,

    Is there is a simple way to get the one time off battery level of sensor, without subscribing to periodic updates? I've noticed the MetaWear.BatteryState but haven't figured out how to use it... I noticed above that you referencing to C++ API but I don't understand how to use examples from C++ in JavaScript...

  • @mraxn said:
    Hi Eric,

    Is there is a simple way to get the one time off battery level of sensor, without subscribing to periodic updates? I've noticed the MetaWear.BatteryState but haven't figured out how to use it... I noticed above that you referencing to C++ API but I don't understand how to use examples from C++ in JavaScript...

    Look at the code posted in this thread.

Sign In or Register to comment.