Logging with Python-SDK

I'm trying to do following with Python-SDK:

1. connect to multiple boards and get data from multiple sensors
2. I want to start logging at all boards at once and
- 2.1. pause logging
- 2.2. resume logging
- 2.3. pause logging
- 2.4. resume logging
- 2.5. pause logging
- 2.6. resume logging
3. stop logging
4. Then I want to download the raw data in my computer.

Using the multi_device.py example I was able to connect to multiple sensors, stream accelerometer data only and save the data (in realtime) in .csv format (haven't paused and resumed the streaming yet).

Any help on logging in python will be highly appreciated.

Thanks

Comments

  • Hello Akah,
    Like you I need to connect to multiple boards (10 MetamotionR boards) and get data from them by my PC. Do you have some example code that you can share with me? I don't find multi_device.py script, where is it?

    Some questions about bluetooth connection: what is the maximum number of bards that I can connect to PC bluetooth? I read 4, is it correct? Is there a difference between Windows and Linux OS? If you have experience about this circumnstance, how many bluetooth dongles I need?

    Thank you for your help.

  • edited January 2020

    Hi FiaSabba,

    sorry for the late reply. below you can find the multi_device.py.

    - what is the maximum number of bards that I can connect to PC bluetooth? I read 4, is it correct?
    --- You can ask mbientlab team about official reply. From our 2 years experience dealing with mbientlab devices, we can say that one can use 2 boards without problems at low sampling rates. 100+ Hz sampling rate and more than two baords is not possible (there are mistakes in the Mbientlab SDK code and the firmware).
    - Is there a difference between Windows and Linux OS?
    --- In Windows you can use only one BLE adapter (USB BLE dongles) and in Linux OS you can use multiple USB Adapters (USB BLE dongles) i.e. split data between multiple USB BLE dongles.
    - If you have experience about this circumnstance, how many bluetooth dongles I need?
    --- It depends on the use case. As I said the usage of more then 2 boards is not possible i.e. cannot be used for reliable and scientific work (only for hobby projects) as there are problems with the board conection and data loss. There are to many randomly errors occured during our tests in many scenarios.

    Hope this helps.

    ============================================================================

    # usage: python multi_device [mac1] [mac2] ... [mac(n)]
    from mbientlab.metawear import MetaWear, libmetawear, parse_value
    from mbientlab.metawear.cbindings import *
    from time import sleep
    from threading import Event
    
    import platform
    import sys
    
    if sys.version_info[0] == 2:
        range = xrange
    
    class State:
        def __init__(self, device):
            self.device = device
            self.samples = 0
            self.callback = FnVoid_VoidP_DataP(self.data_handler)
    
        def data_handler(self, ctx, data):
            print("%s -> %s" % (self.device.address, parse_value(data)))
            self.samples+= 1
    
    states = []
    for i in range(len(sys.argv) - 1):
        d = MetaWear(sys.argv[i + 1])
        d.connect()
        print("Connected to " + d.address)
        states.append(State(d))
    
    for s in states:
        print("configuring device")
        libmetawear.mbl_mw_settings_set_connection_parameters(s.device.board, 7.5, 7.5, 0, 6000)
        libmetawear.mbl_mw_acc_set_odr(s.device.board, 25.0)
        libmetawear.mbl_mw_acc_set_range(s.device.board, 16.0)
        libmetawear.mbl_mw_acc_write_acceleration_config(s.device.board)
    
        signal = libmetawear.mbl_mw_acc_get_acceleration_data_signal(s.device.board)
        libmetawear.mbl_mw_datasignal_subscribe(signal, None, s.callback)
    
        libmetawear.mbl_mw_acc_enable_acceleration_sampling(s.device.board)
        libmetawear.mbl_mw_acc_start(s.device.board)
    
    sleep(3.0)
    
    for s in states:
        libmetawear.mbl_mw_acc_stop(s.device.board)
        libmetawear.mbl_mw_acc_disable_acceleration_sampling(s.device.board)
    
        signal = libmetawear.mbl_mw_acc_get_acceleration_data_signal(s.device.board)
        libmetawear.mbl_mw_datasignal_unsubscribe(signal)
        libmetawear.mbl_mw_debug_disconnect(s.device.board)
    
    sleep(1.0)
    
    print("Total Samples Received")
    for s in states:
        print("%s -> %d" % (s.device.address, s.samples)) 
    

    ============================================================================

    • what is the maximum number of bards that I can connect to PC bluetooth? I read 4, is it correct?
      1 Dongle on PC. Up to 4 connections but only 100Hz total as per the BLE spec.

    • Is there a difference between Windows and Linux OS?
      Yes, Windows only allows one dongle. Linux you can put in multiple dongles and tell the OS which dongles to connect to which sensor (way more freedom in Linux)

    • If you have experience about this circumnstance, how many bluetooth dongles I need?
      One dongle per 100Hz of data. Could be 1 Dongle and two sensors at 50Hz OR 2 Dongles with two sensors at 100Hz.

Sign In or Register to comment.