2016-10-23 13 views
0

私はxbeeのための3ウェイコミュニケーションを研究しています。私は1コーディネーターと2ルーターの構成を理解しました。問題は、この通信をテストするためのコードを見つけることができないことです。私が必要とするのは、コーディネーターがルータに同時に異なるメッセージを送信するための簡単なコードです。私は正直に困惑しています。誰も助けることができますか?3xbeeの基本コード:1コーディネーターと2ルーター

答えて

0

まず、Digiによって提供されるXCTUが必要です。データを送受信する場合よりも、このソフトウェアを使用することができます。

独自のプログラムを作成する場合は、xbeeを使用することをおすすめします。このPythonモジュールには、ルータやエンドデバイスから送信されたパケットを読み取る方法と、コーディネータからリモートデバイスにリモートコマンドを送信する方法やその逆の例に関するサンプルが必要です。

例1 - リモートデバイスから送信されたパケットを読む:

from xbee import ZigBee 
import serial 

PORT = '/dev/ttyAMA0' #change AMA0 to USB0 or another port if is necessary 
BAUD_RATE = 9600 #the baudrate 

# Open serial port 
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(response) 
    except KeyboardInterrupt: 
     ser.colose() 
     break 

例2 - デバイスにリモートコマンドを送信:

from xbee import ZigBee 
import serial 

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

#send command to change Pin 4 of the Xbee to LOW 
xbee.send('remote_at', 
      frame_id='A', 
      dest_addr_long='\x00\x13\xA2\x00\x40\x24\x20\x7D', #this is the serial address(like the MAC address) of the device. You can read it with XCTU(SH and SL parameters) or you can read it from the back of the device 
      options='\x02', 
      command='D4', #pin4 
      parameter='\x04') #change status to low(\x05 for high status) 

#send 1 packet/second with the status of the pins 
xbee.send('remote_at', 
      frame_id='B', 
      dest_addr_long='\x00\x13\xA2\x00\x40\x24\x20\x7D', 
      options='\x02', 
      command='IR', #sample rate parameter 
      parameter='\x03\xE8') #1000 in hex 

#write the above changes 
xbee.send('remote_at', 
      frame_id='C', 
      dest_addr_long='\x00\x13\xA2\x00\x40\x24\x20\x7D', 
      options='\x02', 
      command='WR') 

私はこれが便利です願っています。

関連する問題