packet_buffers[dev_addr] += data if packet_counters[dev_addr] is 0: with xbee.read_lock: # Acquire lock to read command data from GCS telemetry_data = ToGCS.deserialize(packet_buffers[dev_addr]) print(packet.remote_device.get_node_id(), ": ", telemetry_data) device.add_data_received_callback(packet_received) try: while True: cmd = input("Enter command (+,-,s,e,m): ") if cmd is '+': state += 1 print("New state", state) if cmd is '-': state -= 1 print("New state", state) if cmd is 's': stop = not stop if cmd is 'e': ToERU(stop, state, hiker_pos, geo_bounds, LatLng(5,5), LatLng(5.5,5.5), False, None, True).serialize().transmit(device, devices['eru']) if cmd is 'm': ToMAC(None, state, hiker_pos, geo_bounds, [area], LatLng(5,5), LatLng(5.5,5.5), True).serialize().transmit(device, devices['mac']) except KeyboardInterrupt: print('Stopping') finally: device.del_data_received_callback(packet_received)
import time from digi.xbee.devices import DigiMeshDevice import xbee comm_port = "/dev/ttyUSB0" baud_rate = "9600" device = DigiMeshDevice(port=comm_port, baud_rate=baud_rate) device.open() print("This device's name: ", device.get_node_id()) def sample_callback(message): print('Received: ', message.data, '\nFrom:', message.remote_device.get_node_id()) print(xbee.ToGCS.deserialize(message.data)) device.add_data_received_callback(sample_callback) try: while True: print('Waiting....') time.sleep(1) except KeyboardInterrupt: print('stopping') finally: device.del_data_received_callback(sample_callback)