1

I'm trying to send and receive data from coordinator xbee connected to my computer. The router xbee is connected to my arduino and is supposed to send a message back upon receive.

Here's the code for my python script running on the computer:

#!/usr/bin/python
#this code runs on the xbee coordinator that is set to API mode 2

import serial
from xbee import ZigBee
from xbee.helpers.dispatch import Dispatch
import time

PORT = '/dev/tty.usbserial-A900UF4T'
BAUD_RATE = 9600

UNKNOWN = '\xff\xfe' 
WHERE = '\x00\x13\xA2\x00\x40\x98\xDA\x08'
dataString='Hello\n'

# Open serial port
ser = serial.Serial(PORT, BAUD_RATE, interCharTimeout=0.5)


#sends data to xbee address
def sendData(address, datatosend):
    zb.send('tx', dest_addr_long = address, dest_addr = UNKNOWN, data = datatosend)

def recvData (data):
    print data



zb = ZigBee(ser, callback=recvData)


#test data sending method
ack = '0013A2004098DA02'
while True:
    try:
        sendData(WHERE, dataString)

    except KeyboardInterrupt:
        break

zb.halt()
ser.close()

And here's the response I got:

{'retries': '\x00', 'frame_id': '\x01', 'deliver_status': '\x00', 'dest_addr': '\x03\xb1', 'discover_status': '\x00', 'id': 'tx_status'}
{'retries': '\x00', 'frame_id': '\x01', 'deliver_status': '\x00', 'dest_addr': '\x03\xb1', 'discover_status': '\x00', 'id': 'tx_status'}
{'retries': '\x00', 'frame_id': '\x01', 'deliver_status': '\x00', 'dest_addr': '\x03\xb1', 'discover_status': '\x00', 'id': 'tx_status'}
{'retries': '\x00', 'frame_id': '\x01', 'deliver_status': '\x00', 'dest_addr': '\x03\xb1', 'discover_status': '\x00', 'id': 'tx_status'}
{'retries': '\x00', 'frame_id': '\x01', 'deliver_status': '\x00', 'dest_addr': '\x03\xb1', 'discover_status': '\x00', 'id': 'tx_status'}
{'retries': '\x00', 'frame_id': '\x01', 'deliver_status': '\x00', 'dest_addr': '\x03\xb1', 'discover_status': '\x00', 'id': 'tx_status'}
{'retries': '\x00', 'frame_id': '\x01', 'deliver_status': '\x00', 'dest_addr': '\x03\xb1', 'discover_status': '\x00', 'id': 'tx_status'}
{'retries': '\x00', 'frame_id': '\x01', 'deliver_status': '\x00', 'dest_addr': '\x03\xb1', 'discover_status': '\x00', 'id': 'tx_status'}
{'retries': '\x00', 'frame_id': '\x01', 'deliver_status': '\x00', 'dest_addr': '\x03\xb1', 'discover_status': '\x00', 'id': 'tx_status'}
lws803
  • 907
  • 2
  • 10
  • 21

1 Answers1

0

Your callback receives a dictionary with the XBee frame converted to fields. In your case, you're seeing a tx_status response frames of successful delivery to the router device. You might want to try connecting the router device to your PC with XCTU (or a terminal program) to confirm that it's outputting data at the expected baud rate. And then you can confirm that any data you enter on the router arrives on the coordinator.

Once you've debugged that part of the puzzle, you can focus on why your Arduino code isn't working. Does the Arduino see the data from the coordinator? If the Arduino just sends a message every few seconds without waiting for data, does the coordinator receive it? Maybe you have your tx/rx pins swapped, or have a mismatch in your baud rate configurations on the XBee and Arduino. Or you configured the router XBee for API mode and the Arduino is expecting transparent serial mode.

tomlogic
  • 11,489
  • 3
  • 33
  • 59
  • Yes the arduino seems fine. I have it currently set up such there are two arduinos communicating with each other. When one receives, it will send back. Same for the other arduino. It all works fine. But just doesn’t work with the python script – lws803 Mar 14 '18 at 15:32
  • How did you configure the XBee modules on the Arduinos? If ATAP=0 and you're using ATDH/ATDL for addressing they'll only send to each other. Can you get debug output from an Arduino to see if it receives the frames? Have it dump the addresses it's using to reply? – tomlogic Mar 15 '18 at 19:04