Beispiel #1
0
def send_remote_at_command():
    global packets
    p = create_base_arg_parser()
    p.add_argument("xbee_mac_address", type=str)
    p.add_argument("at_command", type=str)
    p.add_argument("paramater", type=str, nargs='?', default=None)
    p.add_argument("--write",
                   const=True,
                   default=False,
                   action='store_const',
                   help="Send write (WR) AT command as well.")
    args = p.parse_args()
    configuration = get_config(args)

    ser = serial.Serial(configuration.port,
                        configuration.baud,
                        timeout=configuration.timeout,
                        parity=configuration.parity,
                        stopbits=configuration.stop_bits)

    radio = ZigBee(ser, escaped=True)

    data = []
    for i in args.xbee_mac_address.split(":"):
        data.append(int(i, 16))
    address = struct.pack("BBBBBBBB", *data)
    radio._callback = radio_callback
    radio._thread_continue = True
    radio.setDaemon(True)
    radio.start()
    radio.send("at", command="AI", frame_id="\x11")
    packets["\x11"] = True
    if args.paramater is None:
        radio.send("remote_at",
                   command=args.at_command,
                   frame_id="\x12",
                   dest_addr_long=address)
        packets["\x12"] = True
    else:
        radio.send("remote_at",
                   command=args.at_command,
                   frame_id="\x13",
                   dest_addr_long=address,
                   parameter=encode_paramater(args.at_command, args.paramater))
        packets["\x13"] = True
    if args.write:
        radio.send("remote_at",
                   command="WR",
                   frame_id="\x14",
                   dest_addr_long=address)
        packets["\x14"] = True
Beispiel #2
0
def network_discover():
    p = create_base_arg_parser()

    args = p.parse_args()
    configuration = get_config(args)

    ser = serial.Serial(configuration.port,
                        configuration.baud,
                        timeout=configuration.timeout,
                        parity=configuration.parity,
                        stopbits=configuration.stop_bits)

    radio = ZigBee(ser, escaped=True)

    radios = {}
    sleep_time = None

    def radio_callback(frame):

        if frame['frame_id'] == '\x02':
            global sleep_time
            sleep_time = struct.unpack(">H", frame['parameter'])[0] * 100
            print sleep_time
        if frame['frame_id'] == '\x03':
            if frame['parameter']['source_addr_long'] not in radios:
                radios[frame['parameter']['source_addr_long']] = ""
                print "Found Radio: %s" % ":".join([
                    format(ord(x), "02x")
                    for x in frame['parameter']['source_addr_long']
                ])
        # else:
        #     print frame

    radio._callback = radio_callback
    radio._thread_continue = True
    radio.setDaemon(True)
    radio.start()
    radio.send("at", command="AI", frame_id="\x01")
    radio.send("at", command="NT", frame_id="\x02")
    radio.send("at", command="ND", frame_id="\x03")

    while True:
        if sleep_time is None:
            time.sleep(1)
        else:
            time.sleep(float(sleep_time) / 1000)
            print "Searching again..."
            radio.send("at", command="ND", frame_id="\x03")
Beispiel #3
0
def send_at_command():
    global packets
    p = create_base_arg_parser()
    p.add_argument("at_command", type=str)
    p.add_argument("paramater", type=str, nargs='?', default=None)
    p.add_argument("--write",
                   const=True,
                   default=False,
                   action='store_const',
                   help="Send write (WR) AT command as well.")
    args = p.parse_args()
    configuration = get_config(args)

    ser = serial.Serial(configuration.port,
                        configuration.baud,
                        timeout=configuration.timeout,
                        parity=configuration.parity,
                        stopbits=configuration.stop_bits)

    radio = ZigBee(ser, escaped=True)

    radio._callback = radio_callback
    radio._thread_continue = True
    radio.setDaemon(True)
    radio.start()
    radio.send("at", command="AI", frame_id="\x11")
    packets["\x11"] = True
    if args.paramater is None:
        radio.send("at", command=args.at_command, frame_id="\x12")
        packets["\x12"] = True
    else:
        radio.send("at",
                   command=args.at_command,
                   frame_id="\x13",
                   parameter=encode_paramater(args.at_command, args.paramater))
        packets["\x13"] = True
    if args.write:
        radio.send("at", command="WR", frame_id="\x14")
        packets["\x14"] = True