Multiple Meta Motion R

Hello everyone!
I have just started working with new Meta Motion R. We are trying to build an application that records from two Meta Motion R contemporary.

Does anyone has used multiple devices with Pymetawear?Is it possible?Is there some sample code  that do so?

What do you use for multiple devices applications? 

Thank you
Lucia

Comments

  • The pymetawear project is not maintained by Mbientlab; it is a community provided API by user @hbldh.  I do not know how often he checks this forum so you may be better asking him directly by filing a question on the project's GitHub page.

    The README and project provide examples on connecting to one device.  Have you tried writing a script that replicates the MetaWearClient example code twice in a single Python script?
  • edited January 2017
    It isn't more complicated than this:
    import time
    from pymetawear.client import MetaWearClient

    address_1 = 'DD:3A:7D:4D:56:F0'
    address_2 = 'FF:...'
    client_1 = MetaWearClient(str(address_1), debug=True)
    client_2 = MetaWearClient(str(address_2), debug=True)

    print("Blinking 10 times with green LED on client 1...")
    pattern = client_1.led.load_preset_pattern('blink', repeat_count=10)
    client_1.led.write_pattern(pattern, 'g')
    client_1.led.play()

    print("Blinking 10 times with red LED on client 2...")
    pattern = client_2.led.load_preset_pattern('blink', repeat_count=10)
    client_2.led.write_pattern(pattern, 'r')
    client_2.led.play()

    time.sleep(5.0)

    client_1.disconnect()
    client_2.disconnect()
    Just create a new client for each board and address them separately.
  • Added the code above as an example in the new 0.7.0 release of PyMetaWear today: https://github.com/hbldh/pymetawear/blob/master/examples/two_clients.py
  • Thank you!

    That is more or less what I was doing but I'm getting two mayors problems:
    •  I have lots of pygatt.exceptions.NotConnectedError after calling
       MetaWearClient(str(address_1), debug=False)
        if i set debug to true it gets stuck at INFO Connecting GATTTool...
    • When the connection happens the first device that connects send far more data than the second one. This is the code that I am using:

    class HandleAccelerometer(object):

        def __init__(self, mac_address, data_rate=50.0, data_range=8):
            self._mac_address = mac_address
            self._data_rate = data_rate
            self._data_range = data_range
            self._nrec = 0
            # self.connect()

        def callback(self, data):
            print('Received from: ', self._mac_address, self._nrec)
            # print("Epoch time: [{0}] - X: {1}, Y: {2}, Z: {3}".format(data[0], *data[1]))
            self._nrec += 1

        def connect(self, time_out=25, tries=105):
            for i in range(tries):
                try:
                    print('Trying to connect: %s, #%d' % (self._mac_address, i))
                    # must be saved as self
                    self.c = MetaWearClient(self._mac_address, timeout=time_out, debug=True)
                    self.c.accelerometer.set_settings(data_rate=self._data_rate,
                                                      data_range=self._data_range)
                except Exception as e:
                    print('Exception', type(e), self._mac_address)
                else:
                    print('Connected')
                    self.connected = True
                    # self.c.accelerometer.notifications(self.callback)
                    break

        def associate_callback(self):
            self.c.accelerometer.notifications(self.callback)

        def run_all(self):
            self.connect()


    def foo(mac_address):
        ha = HandleAccelerometer(mac_address)
        ha.connect()
        time.sleep(150)
        ha.associate_callback()
        while True:
            pass

    mac_address = ['EE:08:AC:39:24:F7', 'E1:DA:57:F1:3B:27']
    from multiprocessing import Process
    all_p = []
    for mc in mac_address:
        p = Process(target=foo, args=(mc, ))
        p.start()


    time.sleep(300)
    for i in all_p:
        p.join()


    has = [HandleAccelerometer(i) for i in mac_address]

    for i in has:
        print('Starting ', i._mac_address)
        _thread.start_new_thread(i.run_all, tuple())


    Any advice?

    Lucia

This discussion has been closed.