2

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.

Community
  • 1
  • 1
loreb
  • 23
  • 1
  • 4

2 Answers2

1

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.

tomlogic
  • 11,489
  • 3
  • 33
  • 59
0

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

Thanatheos
  • 76
  • 8
  • That helps a lot! Do you know anything about setting a symmetric key in API mode? – loreb Nov 18 '14 at 06:05
  • In Xctu you must have an encryption key value to set. – Thanatheos Nov 18 '14 at 08:15
  • 1
    You can set `ATKY` with X-CTU or a "AT Command" frame (type 0x08). – tomlogic Nov 19 '14 at 06:06
  • I will be calling a function in C to generate that key, my symmetric key, so I can't pre-configure it in X-CTU. This project is for my security class, the objective is to authenticate each xbee with an ECC encryption key exchange. – loreb Nov 22 '14 at 22:14
  • the "AT Command" is an internal instruction that can be called from the Tx, Rx pins. In fact it's like saying my key is directly to the Xbee without running Xctu. Xctu is just an interface to set the Xbee but you can do your own program to do it :) – Thanatheos Nov 23 '14 at 22:04
  • poor zelda :/ just kidding. Here's something similar http://knowledge.digi.com/articles/Knowledge_Base_Article/Digi-XBee-RF-Gateway-and-Python-Development-Resource-page/?q=api+library&l=en_US&fs=Search&pn=1 I can't remember the exact page 2 year after it ^^ but there is an python library – Thanatheos May 10 '16 at 07:11