Two Xbee in API mode - Python

4.4k views Asked by At

First, I tested the communication of 2 XBee (series 2) in AT mode and all worked correctly.

Then I changed the Coordinator to API mode and ran the below script while the router was in AT mode. I was successful and received the routers message. However, I can't get the router to be in API mode and send messages to the coordinator. I'm not sure if i can just do simple send command or if I need to specify the address or if the fames have to be formatted.

Each xbee is connected to a PC. I'm using python 3.4.

Coordinator in API mode to receive messages:

Continuously read the serial port and process IO data received from a remote XBee.

from xbee import XBee,ZigBee
import serial

ser = serial.Serial('/dev/...', 9600)
xbee = ZigBee(ser)

while True:
    try:
        response = xbee.wait_read_frame()
        print(response)
    except KeyboardInterrupt:
        break
        
ser.close()

Has someone else done this or know of a site that could help me explain how the router in API works? All I want to do is to send messages from the router to the coordinator.

2

There are 2 answers

6
Thanatheos On BEST ANSWER

To communicate in API mode, you must send frame.

A frame is compose by a header and a footer.

There is some library to help you communicate in API

http://ftp1.digi.com/support/utilities/digi_apiframes2.htm

this web site show you how to communicate in API

0
tomlogic On

API mode works the same whether the device is configured as coordinator, router or end device. If your router is always sending data to the coordinator, there's no need to run it in API mode -- just keep it in AT mode with DH and DL set to 0. It will automatically send frames to the coordinator containing all data that comes in on the serial port.

If you need to use API mode on the router for some reason, just use the python-xbee library you're already using on the coordinator.