Esempio n. 1
0
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)
Esempio n. 2
0
import struct

comm_port = "/dev/ttyUSB0" # can be swapped out for "/dev/ttyUSB0" for serial connection
baud_rate = "9600"

device = DigiMeshDevice(port=comm_port, baud_rate=baud_rate)
device.open()

network = device.get_network()
network.start_discovery_process()

while network.is_discovery_running():
    time.sleep(.01)

devices = {dev.get_node_id():dev._64bit_addr for dev in network.get_devices()}
devices[device.get_node_id()] = device._64bit_addr

print("This device's name: ", device.get_node_id())
print("Discovered ", devices)

geo_bounds = [Geofence(True, [LatLng(1,0),LatLng(0,1),LatLng(-1,0),LatLng(0,-1)])]
geo_bounds.append(Geofence(False, [LatLng(1,1),LatLng(2,1),LatLng(2,-1),LatLng(1,-1)]))

area = SearchArea([LatLng(1,0),LatLng(0,1),LatLng(-1,0),LatLng(0,-1)])

hiker_pos = LatLng(35.083519, -120.534821)

state = 1
stop = False

packet_buffers = {}
Esempio n. 3
0
# Callback for discovery finished. -----------------------
def callback_discovery_finished(status):
    if status == NetworkDiscoveryStatus.SUCCESS:
        print(
            "\n\t=-------- Discovery process finished successfully. --------=\n"
        )
    else:
        print("There was an error discovering devices: %s" %
              status.description)


# main execution code has to be runned into a try because of the open() and close() methods from ZigBeeDevice(device)
try:
    device.open()
    print("Aparelho Local: ", device.get_node_id(), "\n")

    # seting up and starting the xbee network discovery process
    xbee_network = device.get_network()

    info.start_timer()

    xbee_network.set_discovery_timeout(25)  # 25 seconds.
    xbee_network.clear()

    xbee_network.add_device_discovered_callback(callback_device_discovered)

    xbee_network.add_discovery_process_finished_callback(
        callback_discovery_finished)

    print("\t=-------- Starting Device discover process --------=\n")