An open API service indexing awesome lists of open source software.

https://github.com/love4yzp/loracap

LoRaCAP - LoRaE5_Python | Seeed LoRa E5 module Python Library on Raspberry Pi
https://github.com/love4yzp/loracap

lora lora-e5 lorawan lorawan-application wio-e5

Last synced: 3 months ago
JSON representation

LoRaCAP - LoRaE5_Python | Seeed LoRa E5 module Python Library on Raspberry Pi

Awesome Lists containing this project

README

        

# LoRaE5 Python Code for P2P Communication

This Python code is designed to facilitate P2P communication using a LoRaE5 module on a Raspberry Pi OS (Linux), leveraging the UART functionality for serial communication. The code provides a framework for sending and receiving data over LoRa, including setup, message formatting, and handling.

## Prerequisites

- A Raspberry Pi with Raspberry Pi OS installed.
- A LoRaE5 module connected to the Raspberry Pi via UART.
- Python 3.x installed on the Raspberry Pi.

## Key Components of the Code

- **Serial Communication Setup**: Establishes communication with the LoRaE5 module using the `serial` library.

### Steps to Implement P2P Communication

1. **Hardware Setup**:
- Connect the LoRaE5 module to the Raspberry Pi via the UART pins.
- Ensure the module is powered and correctly wired to the Pi's GPIO pins for serial communication.

2. **Software Setup**:
- Install necessary Python libraries: `pySerial` for serial communication and `threading` for concurrent operations.
- Define the communication parameters, such as the baud rate and serial port, matching your hardware setup.

3. **Send a Message**:
- Use the `fetch` or `command` method to send a message.

## Example Use Case

### Switch Mode
```Python
from loracap.LoRaMode import *

class Switch(LoRaMode):
def __init__(self):
super(LoRaMode, self).__init__()
def handle_line(self, line):
"""
We don't need any events for this example.
"""
self.responses.put(line)

ser = serial.serial_for_url('/dev/ttyS0', baudrate=9600, timeout=1)
with serial.threaded.ReaderThread(ser, Switch) as lorae5:
print(f"Current Mode: {lorae5.mode}")

print("Change to LWOTAA Mode")
lorae5.mode = 'LWOTAA'

print("Change to LWABP Mode")
lorae5.mode = 'LWABP'

print("Change to TEST Mode")
lorae5.mode = 'TEST'
print(f"Current Mode: {lorae5.mode}")
```
```shell
Current Mode: LWOTAA
Change to LWOTAA Mode
Change to LWABP Mode
Change to TEST Mode
Current Mode: TEST
```
### Update Credential of LoRa-E5
```Python
from loracap.LoRaMode import *

ser = serial.serial_for_url('/dev/ttyS0', baudrate=9600, timeout=1)
read_thread = serial.threaded.ReaderThread(ser, LoRaTESTMode)
read_thread.start()
_thread, lorae5 = read_thread.connect()

print("Credentials: \n{}\n".format(lorae5))

print("Updating credentials...")
# lorae5.DevEui = '2CF7F12053700006'
lorae5.DevEui = '2C:F7:F1:20:53:70:00:06'
# lorae5.DevAddr = '3230C9A3'
lorae5.DevAddr = '32:30:C9:A3'
# lorae5.AppEui = '8000000000000009'
lorae5.AppEui = '80:00:00:00:00:00:00:09'

print("Credentials updated!\n{}".format(lorae5))
```
```shell
Credentials:
DevEui: 2C:F7:F1:20:53:77:88:99, DevAddr: 42:33:55:A4, AppEui: 80:00:00:00:FF:00:00:10

Updating credentials...
Credentials updated!
DevEui: 2C:F7:F1:20:53:70:00:06, DevAddr: 32:30:C9:A3, AppEui: 80:00:00:00:00:00:00:09
```

## Virtual Environment Usage

This project is managed with Poetry, which supports both virtual environments for isolation and direct system-wide installation. You can choose the approach that best fits your workflow.

### Without Using a Virtual Environment

If you prefer not to use a virtual environment, ensure your system has the required Python version and dependencies. This method may lead to conflicts with other Python projects or system packages.

### Install Poetry

To install Poetry, execute:

```shell
curl -sSL https://install.python-poetry.org | python3 -
```

### Setup the Project with a Virtual Environment

1. **Install Dependencies**: In the project directory, run:

```shell
poetry install
```

This command installs dependencies and optionally sets up a virtual environment.

2. **Activate the Virtual Environment**: To avoid conflicts with the system-wide Python interpreter and ensure project dependencies are managed separately, activate the virtual environment:

```shell
poetry shell
```

Using a virtual environment is recommended to isolate project dependencies, providing a controlled development environment and minimizing potential conflicts.

For more details, visit [Poetry's official documentation](https://python-poetry.org/docs/).