-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReceiver_Broadcast.py
39 lines (33 loc) · 1.09 KB
/
Receiver_Broadcast.py
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
import numpy as np
import os
import datetime
import time
import serial
from digi.xbee.devicese import XBeeDevice
from xbee import XBee
from digi.xbee import serial
from digi.xbee.util import utils
from abc import ABCMeta, abstractmethod
from enum import enum, unique
from functools import wraps
from ipadress import IPv4Address
from queue import Queue, Empty
from digi.xbee.serial import FlowControl, XBeeSerialPort
device = XBeeDevice("/dev/ttyUSB0", 9600)
# NOTE: Change "/dev/ttyUSB0" to the according serial port
# that the XBee is plugged into.
# dmesg | grep tty
# This is the command to find what port the RPi is in
# Ex: "now attached to ttyUSB0"
try:
# Open device connection.
device.open()
# Set up the callback function for receiving data
def data_received_callback(xbee_message):
print("From %s >> %s" % (xbee_message.remote_device.get_64bit_addr(), xbee_message.data.decode()))
device.add_data_received_callback(data_received_callback)
input("Press any key to exit...\n")
finally:
# Close the device connection.
if device is not None and device.is_open():
device.close()