Skip to content

This project provides a C++ implementation of the LoRaWAN protocol using the CH341 USB-to-SPI converter to interface with a RFM95/SX1276 LoRa radio module.

License

Notifications You must be signed in to change notification settings

serper/LoRaWANCH341

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LoRaWAN CH341 Implementation

This project provides a C++ implementation of the LoRaWAN protocol using the CH341 USB-to-SPI converter to interface with a RFM95/SX1276 LoRa radio module.

Documentation: Full API documentation is available at https://serper.github.io/LoRaWANCH341

Features

  • Full LoRaWAN 1.0.3 protocol implementation
  • Support for Class A and Class C devices
  • OTAA and ABP activation methods
  • Support for multiple regions (EU868, US915, etc.)
  • MAC commands implementation
  • Adaptive Data Rate (ADR) support
  • Channel management
  • Duty cycle management
  • Confirmed/unconfirmed messages
  • Linux and Windows support via CH341 USB interface

Hardware Requirements

  • CH341A/CH341F USB adapter
  • RFM95W, SX1276, or compatible LoRa module
  • Any USB-capable device running Linux or Windows

You can use this library with a reference board design that is available at: https://oshwlab.com/serper/lora-usb-adapter

This design provides a complete USB-to-LoRa adapter using the CH341 chip and RFM95 module, allowing for easy integration with this software library.

Dependencies

  • libusb-1.0
  • OpenSSL (for AES encryption)
  • cJSON (for configuration and session management)
  • C++17 compatible compiler

Building

Current Implementation Status

The project currently supports the following LoRaWAN features:

  • Network Activation

    • Over-the-Air Activation (OTAA)
    • Activation By Personalization (ABP)
  • Message Handling

    • Uplink and downlink communication
    • Class A and Class C device operation
  • Network Management

    • Regional channel and power restrictions
    • Adaptive Data Rate (ADR) with performance statistics
    • Duty cycle management

The implementation adheres to LoRaWAN protocol specifications and continues to evolve with additional features.

Configuration

The project uses a JSON configuration file (config.json) to set up device parameters and connection settings. A sample configuration file (config.json.sample) is provided as reference.

Configuration Structure

{
    "device": {
        "devEUI": "Device Extended Unique Identifier",
        "appEUI": "Application Extended Unique Identifier",
        "appKey": "Application Key"
    },
    "connection": {
        "spi_type": "ch341",
        "device_index": 0,
        "spi_device": "/dev/spidev0.0",
        "spi_speed": 1000000
    },
    "options": {
        "force_reset": false,
        "send_interval": 30,
        "verbose": false
    }
}

Use

Implementation Examples

CH341 SPI Interface

// Create SPI interface using CH341
auto spi_interface = SPIFactory::createCH341SPI(device_index, true);
LoRaWAN lorawan(std::move(spi_interface));

or more easy

LoRaWAN lorawan();

Native Linux SPI Interface

// Create SPI interface using native Linux SPI
auto spi_interface = SPIFactory::createLinuxSPI(spi_device, spi_speed);
LoRaWAN lorawan(std::move(spi_interface));

The SPIFactory class provides factory methods to create appropriate SPI interfaces based on your hardware configuration. Choose the implementation that matches your setup.

Parameters

Device Settings

  • devEUI: Device Extended Unique Identifier (16 characters)
  • appEUI: Application Extended Unique Identifier (16 characters)
  • appKey: Application Key (32 characters)

Connection Settings

  • spi_type: SPI interface type (currently supports "ch341")
  • device_index: Device index number
  • spi_device: SPI device path
  • spi_speed: SPI communication speed in Hz

Options

  • force_reset: Enable/disable force reset
  • send_interval: Message sending interval in seconds
  • verbose: Enable/disable verbose logging

Getting Started

  1. Copy config.json.sample to config.json
  2. Update the configuration with your device credentials
  3. Configure the connection settings according to your setup
  4. Adjust options as needed

Requirements

  • CH341 compatible hardware or native linux SPI
  • Access to LoRaWAN network
  • Proper device registration with network server

Dependencies

  • libusb-dev (for CH341 communication)
  • libjson-cpp-dev (for JSON configuration parsing)
  • libspi-dev (for SPI communication)
  • libopenssl
  • C++17 compatible compiler
  • CMake build system (version 3.10 or higher)

Documentation

Complete API documentation is generated using Doxygen and available online at https://serper.github.io/LoRaWANCH341.

The documentation includes:

  • Detailed class and function descriptions
  • Code examples
  • Implementation details
  • UML diagrams of class relationships
  • Call graphs for complex functions

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

This project provides a C++ implementation of the LoRaWAN protocol using the CH341 USB-to-SPI converter to interface with a RFM95/SX1276 LoRa radio module.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages