pythonxbeezigbee

Digi-Xbee Packet Backlog when receiving on windows


we ran into a weird issue when receiving ZigBee packets on Windows. We are currently sending packets from a drone every 0.8s, but on Windows we are receiving only every ~5s. We aren't loosing packets, as the received packet ID's increment correctly. The strange thing is, when using an Ubuntu VM on the same computer it works perfectly, and we receive at about ~0.8s.

We are using Digi-Xbee 1.4 and a "Xbee SMT Grove Dev Board" connected by USB for both sending and receiving.

Here is the code were using to receive on both Windows and Ubuntu:

def connect(self):
        self._device = XBeeDevice(self._port, self._baudRate)
        self._device.open()
        self._device.set_16bit_addr(XBee16BitAddress(utils.int_to_bytes(int(self._address))))
        self._network = self._device.get_network()
        self._device.add_packet_received_callback(self._packetReceivedCallback)

def _packetReceivedCallback(self, packet):
        print("Received!")
        #Processing after this

Has anyone encountered this behavior before?


Solution

  • Ok, in case anyone runs into the same issue, we solved it by basically implementing our own serial interface. This method is extremely basic and if you need more advanced features of Digi-Xbee Python, it probably won't help you. In our case we are sending json.dumps() as the data, so we can seperate it by the {}. You might need to change it for other data types.

    from digi.xbee.models.options import TransmitOptions
    from digi.xbee.models.address import XBee64BitAddress
    from digi.xbee.exception import XBeeException
    from digi.xbee.packets.raw import TX64Packet
    from threading import Thread
    
    
    
    import serial
    
    class ZigbeeConnection():
        def __init__(self, port, baudRate = 230400):
            self._port = port
            self._baudRate = baudRate
            self._packetID = 0
            self._serialPort = serial.Serial(port=self._port,baudrate= self._baudRate )
            self._readActive = True
            self._T = Thread(target=self._startReading, daemon=True)
            self._T.start()
            
    
        def _startReading(self):
            while(self._readActive):
                    rawbytes = self._serialPort.read_until(expected=b"\x02")
                    data=(str(rawbytes)[2:str(rawbytes).rfind("}")+1])
                    print(data)
    
        def sendBroadCastMessage(self,msg:str):
            try:
                msg = msg.encode("utf-8")
                packet = TX64Packet(self._packetID, XBee64BitAddress.BROADCAST_ADDRESS,
                                    TransmitOptions.NONE.value, rf_data=msg)
                self._serialPort.write(packet.output())
                self._packetID += 1
            except XBeeException as e:
                pass