-
Notifications
You must be signed in to change notification settings - Fork 2
/
receive_example.py
56 lines (48 loc) · 2.31 KB
/
receive_example.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Author: Renzo Mischianti
# Website: www.mischianti.org
#
# Description:
# This script demonstrates how to use the E22 LoRa module with RaspberryPi.
# It includes examples of sending and receiving string using both transparent and fixed transmission modes.
# The code also configures the module's address and channel for fixed transmission mode.
# Address and channel of this receiver:
# ADDH = 0x00
# ADDL = 0x01
# CHAN = 23
#
# Can be used with the send_fixed_string and send_transparent_string scripts
#
# Note: This code was written and tested using RaspberryPi on an ESP32 board.
# It works with other boards, but you may need to change the UART pins.
import serial
import time
from lora.lora_e22 import LoRaE22, Configuration
from lora.lora_e22_operation_constant import ResponseStatusCode
from lora.lora_e22_constants import FixedTransmission, RssiEnableByte
# Initialize the LoRaE22 module
loraSerial = serial.Serial('/dev/tty.usbserial-110') #, baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)
lora = LoRaE22('400T33D', loraSerial, aux_pin=0, m0_pin=0, m1_pin=0)
code = lora.begin()
print("Initialization: {}", ResponseStatusCode.get_description(code))
# Set the configuration to default values and print the updated configuration to the console
# Not needed if already configured
configuration_to_set = Configuration('400T33D')
# configuration_to_set.ADDH = 0x00 # Address of this receive no sender
# configuration_to_set.ADDL = 0x01 # Address of this receive no sender
# configuration_to_set.CHAN = 23 # Address of this receive no sender
# configuration_to_set.TRANSMISSION_MODE.fixedTransmission = FixedTransmission.FIXED_TRANSMISSION
# To enable RSSI, you must also enable RSSI on sender
configuration_to_set.TRANSMISSION_MODE.enableRSSI = RssiEnableByte.RSSI_ENABLED
code, confSetted = lora.set_configuration(configuration_to_set)
print("Set configuration: {}", ResponseStatusCode.get_description(code))
print("Waiting for messages...")
while True:
if lora.available() > 0:
# If the sender not set RSSI
# code, value = lora.receive_message()
# If the sender set RSSI
code, value, rssi = lora.receive_message(rssi=True)
print('RSSI: ', rssi)
print(ResponseStatusCode.get_description(code))
print(value)
time.sleep(2)