This is an improved LoRaWAN v1.0 implementation in python.
It works with a Raspberry Pi 4 and the Adafruit LoRa Radio Bonnet with OLED - RFM95W @ 868MHz.
Based on the work of ❤️
For reference on LoRa see: lora-alliance: specification
This fork improves the support for the Adafruit LoRA Radio Bonnet with OLED - RFM95W @ 868MHz.
You can find the access to the Helium Network in the repository of ryanzav.
- Install relevant libraries: adafruit instructions
- Rename
keys_example.py
tokeys.py
and enter your device information from the TTN Console. - Setup your Raspberry Pi
- Connect the Adafruit Lora Bonnet
- Add an antenna to the Lora Bonnet p.e. "simple" Wire Antenna
- Check your environment and look for a public Lora Gateway
$ python3 tx_ttn.py
Sends an uplink to your TTN-Application.
$ python3 rx_ttn.py
Receives a downlink from your TTN-Application. Attention: LoRaWAN does not send downlinks fulltime.
$ python3 txrx_ttn.py
Sends an uplink and receives directly after a downlink.
Now we use this library as a python package.
Move the folder to your project: $ mv ~/LoRaPy ~/your-project/LoRaPy
.
Copy the keys_example.py
to your project: $ cp ~/LoRaPy ~/your-project/keys.py
and set the correct keys from your TTN-Console.
from LoRaPy.lorapy import LoRaPy
import keys
import time
def receive_callback(payload):
print(payload)
"""
LoRaPy takes
:param dev_addr: list. The "Device address" from your device, given by thethings.network.
:param nw_key: list. The "NwkSKey" from your device, given by thethings.network.
:param app_key: list. The "AppSKey" from your device, given by thethings.network.
:param verbose: bool. True if verbose informations should be printed to the console.
:param callback: function. Callback-function to handle downlinks out of the the things stack.
"""
lora = LoRaPy(keys.devaddr, keys.nwskey, keys.appskey, True, receive_callback)
while True:
"""
lora.send(message: string, spreading_factor: integer)
"""
lora.send('this is your payload-string', 7)
time.sleep(900)
from LoRaPy.lorapy import LoRaPy
import keys
import time
last_send = 0
def receive_callback(payload):
global last_send
print(payload)
# reset time
last_send = time.time()
def try_to_send(message):
# wait at least 900s before sending next message.
if last_send + 900 > time.time():
return
# more than 900s since the last sending.
lora.send(message, 7)
lora = LoRaPy(keys.devaddr, keys.nwskey, keys.appskey, True, receive_callback)
while True:
time.sleep(30)
try_to_send('this is your payload-string')
- Add a constant uplink-sender
- Add a constant uplink-sender with short downlink-check.
- Remove Helium
- TTN v3
- Check OTAA for TTN
- Prepare as python-library (p.e. PIP)
- move
./LoRaWAN
&./SX127x
to git submodule (if possible...)