This repository was archived by the owner on Apr 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.py
More file actions
69 lines (49 loc) · 1.96 KB
/
commands.py
File metadata and controls
69 lines (49 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from digi.xbee.devices import XBeeDevice
import os
'''
Define the functions/methods that we are going to use. This file
is split up between the functions to format and send our own data
and interpret the received data
'''
###############################################################
#-------------------------------------------------------------#
# Send Methods #
#-------------------------------------------------------------#
###############################################################
# TODO: Replace with the serial port where your local module is connected to.
PORT = "COM5"
# TODO: Replace with the baud rate of your local module.
BAUD_RATE = 115200
DATA_TO_SEND = "Hello XBee!"
REMOTE_NODE_ID = "REMOTE"
def send():
device = XBeeDevice(PORT, BAUD_RATE)
try:
device.open()
# Obtain the remote XBee device from the XBee network.
xbee_network = device.get_network()
remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
if remote_device is None:
print("Could not find the remote device")
exit(1)
print("Sending data asynchronously to %s >> %s..." % (remote_device.get_64bit_addr(), DATA_TO_SEND))
device.send_data_async(remote_device, DATA_TO_SEND)
print("Success")
finally:
if device is not None and device.is_open():
device.close()
def receive():
from digi.xbee.devices import XBeeDevice
device = XBeeDevice(PORT, BAUD_RATE)
print(device.get_network())
try:
device.open()
def data_receive_callback(xbee_message):
print("From %s >> %s" % (xbee_message.remote_device.get_64bit_addr(),
xbee_message.data1))
device.add_data_received_callback(data_receive_callback)
print("Waiting for data...\n")
input()
finally:
if device is not None and device.is_open():
device.close()