This driver/python module was based on the official Dragino LoRa/GPS HAT example code, for the Dragino LoRa/GPS hat for Raspberry Pi. This source code is provided as is and is granted with no warranty of any kind. Use at your own risk.
The installation is pretty easy and has a few requirements.
- Raspberry Pi 2+ with Dragino LoRa/GPS HAT
- Python 3.6+
- CMake 3.16+
- WiringPi (Probably already installed on your Raspberry Pi.)
- Clone this repository
- Move to the cloned directory
- Run
sudo chmod +x ./setup.sh && sudo ./setup.sh
This will give you access to the lora module in Python. Since the driver is written in C, you may also write your application in C/C++ as depicted in the Sample directory.
The lorapy module has a few features that you can use to interact with the LoRa/GPS HAT. lorapy exports one class : LoRaCom.
This class is the main and only class of the lorapy module. It is used to interact with the LoRa/GPS HAT.
The constructor takes 2 arguments:
- frequency: The frequency to use for the LoRa communication. This is an integer value in Hz. For Europe you can set 868000000.
- sf: The spreading factor to use for the LoRa communication. This is an integer value. You could simply use 7.
-
set_on_receive: This method is used to set the callback function that will be called when a message is received. It thus takes one argument:
- on_receive: The callback function that will be called when a message is received. This function takes 1 argument:
- payload: The payload of the received message as a Python string.
- on_receive: The callback function that will be called when a message is received. This function takes 1 argument:
-
listen_once: This method is used to listen once, returning the received message as plain text. It takes no argument.
-
send: This method is used to send a message. It takes 1 argument:
- payload: The payload to send as a Python string.
-
stop: This method is used to stop listening. It takes no argument.
The simplest ways is to just use the listen_once method which returns the message as plain text.
from lorapy import LoRaCom
com = LoRaCom(868_000_000, 7)
msg = com.listen_once()The simplest way to send a message is to use the send method.
from lorapy import LoRaCom
com = LoRaCom(868_000_000, 7)
com.send("Hello world!")⛔ The send function is currently not stable and might not work as expected! ⛔