Some Problems with MMS download and with 'packed mode'

edited January 2022 in Python

I am using MMS with Python codes, but I have many problems:

  • the sensors have bluetooth connection problems. In fact, some sensors are able to stream data up to about 1 m from the dongle, while others lose the connection already if they are moved away a few cm. Can you tell me if it is a problem of the specific sensors or if I can do something to improve the connection ?

  • When I use the sensors in streaming mode I would like to send the data in packets and I saw that there is a function (packed) to send multiple samples in one bluetooth packet. However, if I use the code that is among the examples (the one of the gyroscopes) it gives me as error "segmentation fault". Can you tell me how I can solve ? also I would like to know if the packed mode is usable also in logging mode (I tried but I failed).

  • When I use the sensors in logging mode I usually do quite long tests (more than 1h). Downloading the data, the time is almost double the time of the test (I sample accelerometers and gyroscopes at 100 Hz). I would like to know if there is a way to download them faster.
    To do this I tried to connect the sensor via usb (I saw that there is the new function for MMS with python scripts). However every time I connect the sensor it takes more than a minute to connect and when disconnected it is no longer detected by bluetooth (I was able to connect only after doing 2 resets manually and this method does not always work). Also, even with USB the data download time is similar to bluetooth. can you tell me if I'm doing something wrong ?


  • Anyone who can help me?
    Do you need more information?

    1. You can use our tx power setting to improve the bluetooth. Also removing the pcb from the case helps as well.
    2. Can't comment without seeing the code and knowing if its used correctly.
    3. You are not doing anything wrong, unfortunately USB and Bluetooth just both take time since our sensor doesn't work like a flash drive.
  • edited April 2022

    from mbientlab.metawear import MetaWear, libmetawear, parse_value, create_voidp, create_voidp_int
    from mbientlab.warble import *
    from mbientlab.metawear.cbindings import *
    from ctypes import c_void_p, cast, POINTER
    from time import sleep
    from threading import Event
    import six
    import platform
    import sys
    from sys import argv
    import csv
    import numpy as np
    import matplotlib.pyplot as plt
    from datetime import datetime;

    def retry_connection(d):
    print("----------------------------------Trying CONNECTION---------------------------------------------------")
    return retry_connection(d)

    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)
    self.analog_callback = FnVoid_VoidP_DataP(self.analog_data_handler)
    self.an_signal = signal = libmetawear.mbl_mw_multi_chnl_temp_get_temperature_data_signal(self.device.board, MetaWearRProChannel.ON_BOARD_THERMISTOR)
    self.processor = None
    # Acc Gyr Callback
    def data_handler(self, ctx, data):
    values = parse_value(data, n_elem = 2)
    with open('./Data/dataacc_'+self.device.address+'.csv', 'a+', newline='') as file:
    writer = csv.writer(file, delimiter=';')
    writer.writerow([ datetime.timestamp(, values])
    # with open('./Data/datagyr_'+self.device.address+'.csv', 'a+', newline='') as file:
    # writer = csv.writer(file, delimiter=';')
    # writer.writerow([ datetime.timestamp(, values[1].x, values[1].y, values[1].z])
    self.samples+= 1

    # Asnalog1 Callback
    def analog_data_handler(self, ctx, data):
    with open('./Data/analog_'+self.device.address+'.csv', 'a+', newline='') as file:
    writer = csv.writer(file, delimiter=';')
    writer.writerow([datetime.timestamp(, values])

    def setup(self):
        # ble settings
        libmetawear.mbl_mw_settings_set_connection_parameters(self.device.board, 7.5, 7.5, 0, 6000)
        # events
        e = Event()
        # processor callback fxn
        def processor_created(context, pointer):
            self.processor = pointer
        # processor fxn ptr
        fn_wrapper = FnVoid_VoidP_VoidP(processor_created)
        # setup acc
        libmetawear.mbl_mw_acc_bmi270_set_odr(self.device.board, AccBmi270Odr._100Hz)
        libmetawear.mbl_mw_acc_bosch_set_range(self.device.board, AccBoschRange._2G)
        # get acc signal
        acc = libmetawear.mbl_mw_acc_get_packed_acceleration_data_signal(self.device.board)
        # setup gyr
        libmetawear.mbl_mw_gyro_bmi270_set_range(s.device.board, GyroBoschRange._125dps);
        libmetawear.mbl_mw_gyro_bmi270_set_odr(s.device.board, GyroBoschOdr._100Hz);
        # get gyro signal - MMRl, MMR, MMc ONLY
        gyro = libmetawear.mbl_mw_gyro_bmi270_get_packed_rotation_data_signal(self.device.board)
        # get gyro signal - MMRS ONLY
        #gyro = libmetawear.mbl_mw_gyro_bmi270_get_rotation_data_signal(self.device.board)
        # create signals variable
        signals = (c_void_p * 1)()
        signals[0] = gyro
        libmetawear.mbl_mw_dataprocessor_fuser_create(acc, signals, 1, None, fn_wrapper)
        # wait for fuser to be created
        # subscribe to the fused signal
        libmetawear.mbl_mw_datasignal_subscribe(self.processor, None, self.callback)
        libmetawear.mbl_mw_datasignal_subscribe(self.an_signal, None, self.analog_callback)
        self.timer = create_voidp(lambda fn: libmetawear.mbl_mw_timer_create_indefinite(self.device.board, 50, 0, None, fn), resource = "timer", event = self.e)
        # create event based on timer - read temp when timer fires
        create_voidp_int(lambda fn: libmetawear.mbl_mw_event_end_record(self.timer, None, fn), event = self.e)
    def start(self):
        # start gyro sampling - MMRL, MMC, MMR only
        # start gyro sampling - MMS ONLY
        # start acc sampling
        # start gyro - MMRL, MMC, MMR only
        # start gyro sampling - MMS ONLY
        # start acc
    def stop(self):

    # ricerca dispositivi nelle vicinanze
    devices = None
    array = sys.argv
    del array[0]
    states = []
    # connect

    for a in array:
    device = MetaWear(a)
    print("Connecting to " + device.address)
    print("CONNECTION STATE " + str(device.is_connected))

    # configure
    for s in states:
    # print("Configuring %s" % (s.device.address))

    # start
    for s in states:

    print("Streaming data")
    stop = -1
    while stop == -1:
    msg = "Press s to stop data recording: "
    selection = raw_input(msg) if platform.python_version_tuple()[0] == '2' else input(msg)
    if selection == "s":
    stop = 0
    print("-----STOP STREAMING-----")

    for s in states:
    if s.device.is_connected:
    print("connected to " + device.address)
    while(not s.device.is_connected):

    # reset
    print("Resetting devices")
    events = []
    for s in states:
    e = Event()
    s.device.on_disconnect = lambda s: e.set()

    for e in events:

    # recap
    print("Total Samples Received")
    for s in states:
    print("%s -> %d" % (s.device.address, s.samples))

  • this is my code. Unfortunately i can't dowload and stream data in packed mode to have a faster download.

  • @giovanni_dq

    Make sure that you install the latest version of MetaWear Python on PyPi to be sure your devices are connecting over USB. The example scripts have also been updated to indicate what type of connection has been established and you may want to add something similar to your script. Here is an example:

    The packed mode is meant only for streaming, and will have a detrimental effect if logged. For an application that needs to switch between modes, you can log the unpacked version and stream the packed version. It is still advisable not to stream while downloading, as it may result in packet loss, but if this is a hard requirement you can try to test it in your setup. If the total throughput is not too high, it may work okay for you, especially if operating with USB downloads.

  • Hi, the same thing happens to me with packed mode. What I mean is that when I use the code provided in the examples of the gyro streaming with packed mode, it gives me: "segmentation fault" that does not allow me to use the MMS sensor gyro with this mode.
    I checked all updates. However, this error persists when I acquire the gyro. Whereas everything seems to work fine when I acquire the accelerometer.

  • Anyone can help us??

Sign In or Register to comment.