3

I hope you'll help me to find out what's wrong with my configuration.

I have to ZigBee nodes, one connected via usb to my mac and one connected via tx/rx ports to the raspberry pi 3.

I wrote two scripts, one that sends Xee Api frame packets (from mac) and one that reads packets (to the pi). The two scripts are based on the python-xbee library.

The scripts are the following - on mac:

import serial
from xbee import XBee, ZigBee 

serial_port = serial.Serial('/dev/tty.usbserial-A5025UGJ', 9600) 
xbee = ZigBee(serial_port, escaped=True) 

# coordinator = 00 13 A2 00 40 8B B1 5A 

while True: 
    try: 
        # Send AT packet 
        xbee.send('tx',frame_id='A', dest_addr_long='\x00\x13\xA2\x00\x40\x8B\xB1\x5A', data='test') 
        parameter = xbee.wait_read_frame() 
        print 'parameter=' 
        print parameter 

    except KeyboardInterrupt: 
        break 

serial_port.close()

On Pi:

import serial
from xbee import XBee, ZigBee 

serial_port = serial.Serial('/dev/serial0', 9600) 
xbee = ZigBee(serial_port, escaped=True) 

while True: 
    try: 

        # Receive AT packet 
        parameter = xbee.wait_read_frame() 
        print 'parameter=' 
        print parameter 

    except KeyboardInterrupt: 
        break 

serial_port.close()

The output of the first script is the following (the sender):

parameter= {'retries': '\x00', 'frame_id': 'A', 'deliver_status': '\x00', 'dest_addr': '\x00\x00', 'discover_status': '\x00', 'id': 'tx_status'}

The output of the second script is the following (the receiver):

parameter= {'source_addr_long': '\x00\x13\xa2\x00@\x8b\xb1L', 'rf_data': 'test', 'source_addr': '\xa3\x19', 'id': 'rx', 'options': '\x01'}

Now if I start Node-Red 0.17.3 and I use the "serial input" module, connected to a debug output module, i cannot see anything incoming if the newline is base on the char "\n". The port is the same of the script (/dev/serial0).

[
    {
        "id": "e6aa5379.9fd8c",
        "type": "debug",
        "z": "35e84ae.5ae88b6",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "true",
        "x": 432.5,
        "y": 213,
        "wires": []
    },
    {
        "id": "63563843.bba178",
        "type": "serial in",
        "z": "35e84ae.5ae88b6",
        "name": "",
        "serial": "fbf0b4fa.9b2918",
        "x": 209.5,
        "y": 201,
        "wires": [
            [
                "e6aa5379.9fd8c"
            ]
        ]
    },
    {
        "id": "fbf0b4fa.9b2918",
        "type": "serial-port",
        "z": "",
        "serialport": "/dev/serial0",
        "serialbaud": "9600",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "newline": "\\n",
        "bin": "false",
        "out": "char",
        "addchar": false
    }
]

If I change the configuration of "serial in" node, setting the split "after a timeour of 5000 ms" and deliver "binary buffers", this is the result in debug view:

[126,0,125,49,144,0,125,51,162,0,64,139,177,76,163,25,1,112,114,111,118,97,13]

Does anyone know how to find the correct way to split input with XBee API frames?

micstr
  • 5,080
  • 8
  • 48
  • 76
  • Your data looks to be terminated with a /r (return or 13) not a /n (newline or 10) – hardillb Jul 06 '17 at 09:02
  • Hi @hardillb, the last char can actually change because the last char in a ZigBee API frame is the checksum. Is there a way to escape it like in the python script? `xbee = ZigBee(serial_port, escaped=True) ` Otherwise I'll have to use the timeout function – Diego Braga Jul 06 '17 at 13:23
  • OK, then the best way will probably to look on npm for a node to unpack zigbee frames and wrap that to create a new Node-RED node. – hardillb Jul 06 '17 at 13:38

1 Answers1

0

I don't know anything about node-red, but you need to parse the stream of bytes to extract the frames. It would require more work to escape the data going in and out, but I think you can use API mode 2 (ATAP = 2) where the start of frame byte (0x7E) is escaped when appearing in the frame, so you could potentially split on that byte.

tomlogic
  • 11,489
  • 3
  • 33
  • 59
  • This would work if I receive at least two frames, but my case is with just one frame every 5 minutes – Diego Braga Jul 06 '17 at 18:21
  • I think my idea is a more robust solution, since the XBee can generate additional frames (Modem Status, Transmit Status) outside of the data you're expecting. Look at the XBee documentation for information on the API frame format and how to parse it. Can you use https://www.npmjs.com/package/xbee-api to parse the frames? – tomlogic Jul 06 '17 at 19:05