首页 > 解决方案 > multi nRF52840如何连接rpi4?

问题描述

我想连接两个 nrf52840 设备和树莓派。连接到单个设备时,它工作正常。但是,当连接两个设备时,会发生错误并停止。

两个设备的 rx uuid 不同。

这是我的代码

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

            

如果我连接另一台设备,则会发生此错误并停止

            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

我该如何解决这个错误?

标签: bluetoothraspberry-pibluetooth-lowenergynrf52tx

解决方案


推荐阅读