2013-12-15 2 views

답변

1

위대한 python-xbee 라이브러리와 Digi의 examples.digi.com을 XBee를 처음 사용하는 사람에게 훌륭한 자료로 보자. 이 두 사이트 사이에서 (두 번째 링크를 사용하여) 서로 조인 된 XBee 라디오를 가져올 수 있어야하고 첫 번째 링크가있는 Python에서 작동하도록 할 수 있어야합니다. 코디네이터 API 모드 -

첫 번째 장치 :

0

다른 작업을 수행하기 전에 당신이 장치를 사용 XCTU 소프트웨어를 구성 할 필요가 - 7777 ID (또는 임의의 값) 을 - DL이 FFFF

로 설정

번째 장치 - 라우터 AT 모드 : - DL 0

공동 세트 - 7777 ID가 (모든 장치에 대해 동일해야한다) 코디네이터 드 (를 대기 모드) : 원격 장치에 대한

import serial 
import time 
from xbee import ZigBee 

PORT = "COM1" #change the port if you are not using Windows to whatever port you are using 
BAUD_RATE = 9600 
ser = serial.Serial(PORT, BAUD_RATE) 

# Create API object 

xbee = ZigBee(ser) 

# Continuously read and print packets 
while True: 
    try: 
     response = xbee.wait_read_frame() 

     print("\nPacket received at %s : %s" %(time.time(), response)) 

    except KeyboardInterrupt: 
     ser.close() 
     break 

코드 :

import serial 

PORT = "COM1" #change the port if you are not using Windows to whatever port you are using 
BAUD_RATE = 9600 
ser = serial.Serial(PORT, BAUD_RATE) 

while True: 
try: 
    data = raw_input("Send:") 
    ser.write(data) #if you are using python 3 replace data with data.encode() 
except KeyboardInterrupt: 
    ser.close() 
    break 

코드를 실행하고 코디네이터에게 원격 장치에서 데이터를 전송합니다. 콘솔에 인쇄 된 패킷을 볼 수 있으며 rx_data 필드에서 페이로드가됩니다.

도움이되기를 바랍니다.

관련 문제