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
This discussion has been closed.
Comments
That is more or less what I was doing but I'm getting two mayors problems:
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