34 __author__ =
"astambler@willowgarage.com (Adam Stambler)"
42 from optparse
import OptionParser
47 %prog [options] port my_adr
49 setup_xbee.py is a configuration script for Xbees. It takes
50 factory fresh xbee and programs it to work with your rosserial network.
51 If XBee is not factory fresh, use Digi's X-CTU software to program it.
53 port : serial port of port of the xbee (/dev/ttyUSB0)
54 my_adr: MY address is the 16 bit address of this xbee in the
55 network. This must be a unique address in the network.
56 This address is always 0 for the coordinator. """
57 parser = OptionParser(usage=help)
60 parser.add_option(
'-P',
'--pan_id', action=
"store", type=
"int", dest=
"pan_id", default=1331, help=
"Pan ID of the xbee network. This ID must be the same for all XBees in your network.")
61 parser.add_option(
'-c',
'--channel', action=
"store", type=
"string", dest=
"channel", default=
"0D", help=
"Frequency channel for the xbee network. The channel value must be the same for all XBees in your network.")
62 parser.add_option(
'-C',
'--coordinator', action=
"store_true", dest=
"coordinator", default=
False, help=
"Configures the XBee as Coordinator for the network. Only make the XBee connected to the computer a coordiantor.")
81 baud_lookup= { 1200 : 0,
98 if port.read(2) ==
'OK':
103 if __name__ ==
'__main__':
105 opts, args = parser.parse_args()
108 print(
"Not enough arguments!")
113 my_address = int(args[1])
115 port = serial.Serial(port_name, baud, timeout=1.5)
118 print(
"Connected to the XBee")
120 print(
"Failed to connect to the XBee")
125 if (opts.coordinator):
128 cmd +=
'MY%d,'%int(args[1])
129 cmd +=
'BD%d,'%baud_lookup[57600]
130 cmd +=
'ID%d,'%opts.pan_id
131 cmd +=
'CH%s,'%opts.channel
138 if setAT(port,
'RE'):
141 print(
"Reset failed")
145 print(
"Sending command : ", cmd)
148 print(
"XBee sucessfully programed!")
150 print(
"XBee programming failed. Try again and then investigate using X-CTU")