LoRaWANCH341 Library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros
LoRaWAN.cpp File Reference

Implementation of the LoRaWAN protocol for communication with LoRaWAN networks. More...

#include <openssl/evp.h>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include "LoRaWAN.hpp"
#include "RFM95.hpp"
#include "AES-CMAC.hpp"
#include "SessionManager.hpp"
#include <iostream>
#include <thread>
#include <chrono>
#include <queue>
#include <mutex>
#include <array>
#include <deque>
#include <bitset>
Include dependency graph for LoRaWAN.cpp:

Classes

struct  LoRaWAN::Impl
 

Macros

#define DEBUG_PRINT(x)   do { if(LoRaWAN::getVerbose()) { std::cout << x; } } while(0)
 
#define DEBUG_PRINTLN(x)   do { if(LoRaWAN::getVerbose()) { std::cout << x << std::endl; } } while(0)
 
#define DEBUG_HEX(x)   do { if(LoRaWAN::getVerbose()) { std::cout << std::hex << (x) << std::dec; } } while(0)
 

Detailed Description

Implementation of the LoRaWAN protocol for communication with LoRaWAN networks.

This file contains the implementation of the LoRaWAN class, which provides methods for initializing the LoRaWAN stack, joining a network, sending and receiving messages, and handling various LoRaWAN protocol features such as ADR (Adaptive Data Rate) and MAC commands.

The implementation uses the RFM95 radio module and supports both CH341SPI and Linux SPI interfaces.

Note
This implementation is designed for use with the RFM95 radio module and may require modifications to work with other radio modules.

@dependencies

Usage

To use this implementation, create an instance of the LoRaWAN class and call its methods to initialize the radio, join a network, and send/receive messages. The class provides methods for setting device parameters (DevEUI, AppEUI, AppKey, etc.), configuring the radio, and handling protocol-specific tasks such as calculating MICs and processing MAC commands.

Example:

LoRaWAN lorawan;
lorawan.setDevEUI("0004A30B001C0530");
lorawan.setAppEUI("70B3D57ED00201A6");
lorawan.setAppKey("8D7F3B4C5A6B7C8D9E0F1A2B3C4D5E6F");
std::vector<uint8_t> data = {0x01, 0x02, 0x03};
lorawan.send(data, 1, false);
}
Class that provides LoRaWAN protocol implementation.
Definition LoRaWAN.hpp:74
@ OTAA
Over-The-Air Activation - dynamic session keys.
Definition LoRaWAN.hpp:100
void setAppEUI(const std::string &appEUI)
Set the Application EUI.
Definition LoRaWAN.cpp:709
bool join(JoinMode mode, unsigned long timeout=10000)
Join a LoRaWAN network.
Definition LoRaWAN.cpp:761
bool send(const std::vector< uint8_t > &data, uint8_t port, bool confirmed=false, bool force_duty_cycle=false)
Send a message.
Definition LoRaWAN.cpp:1196
void setAppKey(const std::string &appKey)
Set the Application Key.
Definition LoRaWAN.cpp:729
void setDevEUI(const std::string &devEUI)
Set the Device EUI.
Definition LoRaWAN.cpp:689

Classes

Methods

Debugging

The implementation includes several debug macros for conditional printing:

Structures

Constants

Enums

Typedefs

Structs

Authors

Date
2025/03/08

License

This code is provided under the MIT License.

Macro Definition Documentation

◆ DEBUG_HEX

#define DEBUG_HEX (   x)    do { if(LoRaWAN::getVerbose()) { std::cout << std::hex << (x) << std::dec; } } while(0)

◆ DEBUG_PRINT

#define DEBUG_PRINT (   x)    do { if(LoRaWAN::getVerbose()) { std::cout << x; } } while(0)

◆ DEBUG_PRINTLN

#define DEBUG_PRINTLN (   x)    do { if(LoRaWAN::getVerbose()) { std::cout << x << std::endl; } } while(0)