• Well, I can't find the info - googling GATT_Specification_Supplement_v8-1 doesn't return anything, so I can't really confirm if it's right or not, but as far as I can see what you're doing looks good.

    However the use of Uint16Array in build_battery_status does look a bit suspect, as that's going to create 6 bytes of data (when I assume that wasn't what was needed).

    You might need:

    new Uint8Array([battery_status_flags, power_state_flags>>8, power_state_flags&255, battery_level]).buffer
    

    Which would give you 4 bytes (with power_state_flags as little endian 16 bit) - but again I'm not sure what's required so I'm just guessing.

  •     new Uint8Array([battery_status_flags, power_state_flags>>8, power_state_flags&255, battery_level]).buffer
    

    Are you sure this is correct? It seems like you're encoding it in big endian, wouldn't the correct encoding be

        new Uint8Array([battery_status_flags, power_state_flags&0xff, power_state_flags>>8, battery_level]).buffer