1

I want to connect two nrf52840 device and raspberry pi. When connecting to a single device, it works fine. However, when connecting with two devices, an error occurs and stops.

The rx uuids of the two devices are different.

Here is my code

def read_left_data(self):
    left_thread = threading.Thread(target=self.left_data)
    left_thread.start()

def left_data(self):
    try:
        left_adapter.start()

        #left mac address : DF:BB:3A:13:EE:1D
        #right mac address : C4:78:6A:80:D7:A7

        left_device = left_adapter.connect('DF:BB:3A:13:EE:1D', address_type=pygatt.BLEAddressType.random)

        #read value nordic tx uuid
        while True:
            #left tx uuid : 6e40ABCD-b5a3-f393-e0a9-e50e24dcca9e
            #right tx uuid : 6e400003-b5a3-f393-e0a9-e50e24dcca9e

            value = left_device.char_read("6e40ABCD-b5a3-f393-e0a9-e50e24dcca9e")
            receive_data = hexlify(value) #get value
            receive_data = receive_data.decode('utf-8')    #remove hex 'b'
            
            #do something with receive_data

            

if I connect another device this error occurs and stops

            Exception in thread Thread-3:
    Traceback (most recent call last):
      File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
          self.run()
        File "/usr/local/lib/python3.6/threading.py", line 864, in run
          self._target(*self._args, **self._kwargs)
        File "qttest_right.py", line 91, in rightData
          value = rightDevice.char_read("6e40ABCD-b5a3-f393-e0a9-e50e24dcca9e")
        File "/usr/local/lib/python3.6/site-packages/pygatt/backends/gatttool/device.py", line 17, in wrapper
          return func(self, *args, **kwargs)
        File "/usr/local/lib/python3.6/site-packages/pygatt/backends/gatttool/device.py", line 40, in char_read
          return self._backend.char_read(self, uuid, *args, **kwargs)
        File "/usr/local/lib/python3.6/site-packages/pygatt/backends/gatttool/gatttool.py", line 50, in wrapper
          return func(self, *args, **kwargs)
        File "/usr/local/lib/python3.6/site-packages/pygatt/backends/gatttool/gatttool.py", line 593, in char_read
          self.sendline('char-read-uuid %s' % uuid)
        File "/usr/local/lib/python3.6/contextlib.py", line 88, in __exit__
          next(self.gen)
        File "/usr/local/lib/python3.6/site-packages/pygatt/backends/gatttool/gatttool.py", line 191, in event
          self.wait(event, timeout)
        File "/usr/local/lib/python3.6/site-packages/pygatt/backends/gatttool/gatttool.py", line 157, in wait
          raise NotificationTimeout()
      pygatt.exceptions.NotificationTimeout: None

How can I solve this error?

carly
  • 11
  • 1

0 Answers0