|
LoRaWANCH341 Library
|
Class that provides LoRaWAN protocol implementation. More...
#include <LoRaWAN.hpp>

Classes | |
| struct | Impl |
| struct | Message |
| Structure representing a LoRaWAN message. More... | |
Public Types | |
| enum | Region { REGION_EU868 = 0 , REGION_US915 , REGION_AU915 , REGION_EU433 , REGIONS } |
| LoRaWAN supported regions. More... | |
| enum | DeviceClass { CLASS_A , CLASS_B , CLASS_C } |
| LoRaWAN device classes. More... | |
| enum | JoinMode { OTAA , ABP } |
| LoRaWAN join modes. More... | |
| enum | ConfirmationState { NONE , WAITING_ACK , ACK_PENDING } |
| Represents the state of message confirmations. More... | |
| enum | RxWindowState { RX_IDLE , RX_WAIT_1 , RX_WINDOW_1 , RX_WAIT_2 , RX_WINDOW_2 , RX_CONTINUOUS } |
| Represents the state of receive windows. More... | |
| typedef std::function< void(const Message &)> | ReceiveCallback |
| Callback type for received messages. | |
| typedef std::function< void(bool)> | JoinCallback |
| Callback type for join events. | |
Public Member Functions | |
| LoRaWAN () | |
| Default constructor. | |
| LoRaWAN (std::unique_ptr< SPIInterface > spi_interface) | |
| Constructor with custom SPI interface. | |
| ~LoRaWAN () | |
| Destructor. | |
| bool | init (int deviceIndex=0) |
| Initialize the LoRaWAN stack and radio. | |
| void | setDeviceClass (DeviceClass deviceClass) |
| Set the device class (A, B, or C). | |
| void | setDevEUI (const std::string &devEUI) |
| Set the Device EUI. | |
| void | setAppEUI (const std::string &appEUI) |
| Set the Application EUI. | |
| void | setAppKey (const std::string &appKey) |
| Set the Application Key. | |
| void | setDevAddr (const std::string &devAddr) |
| Set the Device Address. | |
| void | setNwkSKey (const std::string &nwkSKey) |
| Set the Network Session Key. | |
| void | setAppSKey (const std::string &appSKey) |
| Set the Application Session Key. | |
| bool | join (JoinMode mode, unsigned long timeout=10000) |
| Join a LoRaWAN network. | |
| std::vector< uint8_t > | encryptPayload (const std::vector< uint8_t > &payload, uint8_t port) |
| Encrypt a payload. | |
| std::vector< uint8_t > | decryptPayload (const std::vector< uint8_t > &payload, uint8_t port) |
| Decrypt a payload. | |
| float | calculateTimeOnAir (size_t payload_size) |
| Calculate the time on air for a payload. | |
| bool | checkDutyCycle (float frequency, size_t payload_size) |
| Check if duty cycle allows transmission. | |
| float | getDutyCycleUsage (int channel) |
| Get the duty cycle usage for a channel. | |
| void | resetDutyCycle () |
| Reset the duty cycle usage. | |
| bool | send (const std::vector< uint8_t > &data, uint8_t port, bool confirmed=false, bool force_duty_cycle=false) |
| Send a message. | |
| void | update () |
| Update the LoRaWAN state. | |
| bool | receive (Message &message, unsigned long timeout=1000) |
| Receive a message. | |
| void | onReceive (std::function< void(const Message &)> callback) |
| Set a callback for received messages. | |
| void | onJoin (std::function< void(bool)> callback) |
| Set a callback for join events. | |
| void | setRegion (int region) |
| Set the LoRaWAN region. | |
| int | getRegion () const |
| Get the current LoRaWAN region. | |
| float | getFrequency () const |
| Get the current frequency. | |
| void | setFrequency (float freq_mhz) |
| Set the frequency. | |
| int | getChannelFromFrequency (float freq_mhz) const |
| Get the channel from a frequency. | |
| float | getFrequencyFromChannel (int channel) const |
| Get the frequency for a channel. | |
| void | setChannel (uint8_t channel) |
| Set the current channel. | |
| uint8_t | getChannel () const |
| Get the current channel. | |
| void | setSingleChannel (bool enable, float freq_mhz=868.1, int sf=9, int bw=125, int cr=5, int power=14, int preamble=8) |
| Enable or disable single channel mode. | |
| bool | getSingleChannel () const |
| Check if single channel mode is enabled. | |
| float | getSingleChannelFrequency () const |
| Get the single channel frequency. | |
| void | setTxPower (int8_t power) |
| Set the transmission power. | |
| int | getRSSI () const |
| Get the RSSI (Received Signal Strength Indicator). | |
| int | getSNR () const |
| Get the SNR (Signal-to-Noise Ratio). | |
| uint32_t | getFrameCounter () const |
| Get the frame counter. | |
| void | setFrameCounter (uint32_t counter) |
| Set the frame counter. | |
| void | wake () |
| Wake the radio from sleep mode. | |
| void | sleep () |
| Put the radio in sleep mode. | |
| bool | validateKeys () const |
| Validate the session keys. | |
| void | enableADR (bool enable) |
| Enable or disable ADR (Adaptive Data Rate). | |
| bool | isADREnabled () const |
| Check if ADR is enabled. | |
| void | resetSession () |
| Reset the LoRaWAN session. | |
| void | applyADRSettings (uint8_t dataRate, uint8_t txPower, const std::vector< uint8_t > &channelMask) |
| Apply ADR settings. | |
| void | processMACCommands (const std::vector< uint8_t > &commands, std::vector< uint8_t > &response) |
| Process MAC commands. | |
| void | processLinkADRReq (const std::vector< uint8_t > &cmd, size_t index, std::vector< uint8_t > &response) |
| Process LinkADRReq MAC command. | |
| void | sendADRStatistics () |
| Send ADR statistics. | |
| void | updateTxParamsForADR () |
| Update transmission parameters for ADR. | |
| void | setupRxWindows () |
| Set up receive windows. | |
| void | openRX1Window () |
| Open RX1 window. | |
| void | openRX2Window () |
| Open RX2 window. | |
| void | updateRxWindows () |
| Update receive windows. | |
| void | handleConfirmation () |
| Handle confirmations. | |
| void | sendAck () |
| Send an acknowledgment. | |
| void | resetConfirmationState () |
| Reset the confirmation state. | |
| void | handleReceivedMessage (const std::vector< uint8_t > &payload, Message &msg) |
| Handle a received message. | |
| bool | processJoinAccept (const std::vector< uint8_t > &data) |
| Process a join accept message. | |
| void | requestLinkCheck () |
| Request a link check. | |
| void | updateDataRateFromSF () |
| Update the data rate from the spreading factor. | |
Static Public Member Functions | |
| static void | setVerbose (bool verbose) |
| Set verbose mode. | |
| static bool | getVerbose () |
| Get verbose mode. | |
Static Private Attributes | |
| static constexpr int | MAX_CHANNELS = 16 |
| static constexpr unsigned long | RECEIVE_DELAY1 = 1000 |
| static constexpr unsigned long | RECEIVE_DELAY2 = 2000 |
| static constexpr unsigned long | WINDOW_DURATION = 500 |
| static constexpr uint8_t | ADR_ACK_LIMIT = 64 |
| static constexpr uint8_t | ADR_ACK_DELAY = 32 |
| static constexpr uint8_t | MAX_RETRIES = 8 |
| static constexpr float | BASE_FREQ [REGIONS] |
| static constexpr float | CHANNEL_STEP [REGIONS] |
| static constexpr int | MAX_POWER [REGIONS] |
| static constexpr float | RX2_FREQ [REGIONS] |
| static constexpr int | RX2_SF [REGIONS] |
| static constexpr float | RX2_BW [REGIONS] |
| static constexpr int | RX2_CR [REGIONS] |
| static constexpr int | RX2_PREAMBLE [REGIONS] |
| static bool | isVerbose = false |
Class that provides LoRaWAN protocol implementation.
The LoRaWAN class implements the LoRaWAN protocol for communications with LoRaWAN networks. It supports both OTAA and ABP activation methods, Class A and Class C device operation, and provides methods for sending and receiving messages, managing MAC commands, and controlling various radio parameters.
| typedef std::function<void(bool)> LoRaWAN::JoinCallback |
Callback type for join events.
| typedef std::function<void(const Message&)> LoRaWAN::ReceiveCallback |
Callback type for received messages.
| enum LoRaWAN::DeviceClass |
LoRaWAN device classes.
| enum LoRaWAN::JoinMode |
LoRaWAN join modes.
| Enumerator | |
|---|---|
| OTAA | Over-The-Air Activation - dynamic session keys. |
| ABP | Activation By Personalization - static session keys. |
| enum LoRaWAN::Region |
LoRaWAN supported regions.
| LoRaWAN::LoRaWAN | ( | ) |
|
explicit |
Constructor with custom SPI interface.
| spi_interface | A unique pointer to an SPIInterface implementation |
|
default |
Destructor.
| void LoRaWAN::applyADRSettings | ( | uint8_t | dataRate, |
| uint8_t | txPower, | ||
| const std::vector< uint8_t > & | channelMask | ||
| ) |
Apply ADR settings.
| dataRate | The data rate index |
| txPower | The transmission power index |
| channelMask | The channel mask |

| float LoRaWAN::calculateTimeOnAir | ( | size_t | payload_size | ) |
Calculate the time on air for a payload.
| payload_size | Size of the payload in bytes |

| bool LoRaWAN::checkDutyCycle | ( | float | frequency, |
| size_t | payload_size | ||
| ) |
Check if duty cycle allows transmission.
| frequency | Frequency in MHz |
| payload_size | Size of the payload in bytes |


| std::vector< uint8_t > LoRaWAN::decryptPayload | ( | const std::vector< uint8_t > & | payload, |
| uint8_t | port | ||
| ) |
Decrypt a payload.
| payload | The encrypted payload |
| port | The port number |


| void LoRaWAN::enableADR | ( | bool | enable | ) |
Enable or disable ADR (Adaptive Data Rate).
| enable | Whether to enable ADR |

| std::vector< uint8_t > LoRaWAN::encryptPayload | ( | const std::vector< uint8_t > & | payload, |
| uint8_t | port | ||
| ) |
Encrypt a payload.
| payload | The payload to encrypt |
| port | The port number |


| uint8_t LoRaWAN::getChannel | ( | ) | const |
Get the current channel.
| int LoRaWAN::getChannelFromFrequency | ( | float | freq_mhz | ) | const |
Get the channel from a frequency.
| freq_mhz | The frequency in MHz |

| float LoRaWAN::getDutyCycleUsage | ( | int | channel | ) |
Get the duty cycle usage for a channel.
| channel | Channel index |

| uint32_t LoRaWAN::getFrameCounter | ( | ) | const |
Get the frame counter.
| float LoRaWAN::getFrequency | ( | ) | const |
Get the current frequency.

| float LoRaWAN::getFrequencyFromChannel | ( | int | channel | ) | const |
Get the frequency for a channel.
| channel | The channel index |
| int LoRaWAN::getRegion | ( | ) | const |
Get the current LoRaWAN region.
| int LoRaWAN::getRSSI | ( | ) | const |
Get the RSSI (Received Signal Strength Indicator).
| bool LoRaWAN::getSingleChannel | ( | ) | const |
Check if single channel mode is enabled.
| float LoRaWAN::getSingleChannelFrequency | ( | ) | const |
Get the single channel frequency.
| int LoRaWAN::getSNR | ( | ) | const |
Get the SNR (Signal-to-Noise Ratio).
|
inlinestatic |
Get verbose mode.

| void LoRaWAN::handleConfirmation | ( | ) |
Handle confirmations.


| void LoRaWAN::handleReceivedMessage | ( | const std::vector< uint8_t > & | payload, |
| Message & | msg | ||
| ) |
Handle a received message.
| payload | The received payload |
| msg | Reference to a Message structure where the processed message will be stored |


| bool LoRaWAN::init | ( | int | deviceIndex = 0 | ) |
Initialize the LoRaWAN stack and radio.
| deviceIndex | Optional device index for SPI |


| bool LoRaWAN::isADREnabled | ( | ) | const |
Check if ADR is enabled.
| bool LoRaWAN::join | ( | JoinMode | mode, |
| unsigned long | timeout = 10000 |
||
| ) |
Join a LoRaWAN network.
| mode | Join mode (OTAA or ABP) |
| timeout | Timeout in milliseconds |


| void LoRaWAN::onJoin | ( | std::function< void(bool)> | callback | ) |
Set a callback for join events.
| callback | Function to call when a join event occurs |
| void LoRaWAN::onReceive | ( | std::function< void(const Message &)> | callback | ) |
Set a callback for received messages.
| callback | Function to call when a message is received |

| void LoRaWAN::openRX1Window | ( | ) |
Open RX1 window.
Open the RX1 window (modified to use rx1DrOffset)
| void LoRaWAN::openRX2Window | ( | ) |
Open RX2 window.
Open the RX2 window (using custom rx2DataRate if configured)

| bool LoRaWAN::processJoinAccept | ( | const std::vector< uint8_t > & | data | ) |
Process a join accept message.
| data | The join accept message data |

| void LoRaWAN::processLinkADRReq | ( | const std::vector< uint8_t > & | cmd, |
| size_t | index, | ||
| std::vector< uint8_t > & | response | ||
| ) |
Process LinkADRReq MAC command.
| cmd | The MAC command |
| index | The index in the command |
| response | The response MAC command |


| void LoRaWAN::processMACCommands | ( | const std::vector< uint8_t > & | commands, |
| std::vector< uint8_t > & | response | ||
| ) |
Process MAC commands.
| commands | The MAC commands to process |
| response | The response MAC commands |


| bool LoRaWAN::receive | ( | Message & | message, |
| unsigned long | timeout = 1000 |
||
| ) |
Receive a message.
| message | Reference to a Message structure where the received message will be stored |
| timeout | Timeout in milliseconds |

| void LoRaWAN::requestLinkCheck | ( | ) |
Request a link check.
Request to server info about the device link quality.
Sends a MAC LinkCheckReq command to the server. The response will arrive in a future downlink with the margin and number of gateways that received the last uplink. The application must register a reception callback to process the response.

| void LoRaWAN::resetConfirmationState | ( | ) |
Reset the confirmation state.

| void LoRaWAN::resetDutyCycle | ( | ) |
Reset the duty cycle usage.
| void LoRaWAN::resetSession | ( | ) |
Reset the LoRaWAN session.
Clears all session keys and counters.


| bool LoRaWAN::send | ( | const std::vector< uint8_t > & | data, |
| uint8_t | port, | ||
| bool | confirmed = false, |
||
| bool | force_duty_cycle = false |
||
| ) |
Send a message.
| data | The payload to send |
| port | The port number |
| confirmed | Whether the message should be confirmed |
| force_duty_cycle | Whether to force transmission even if duty cycle limits are reached |


| void LoRaWAN::sendAck | ( | ) |
Send an acknowledgment.


| void LoRaWAN::sendADRStatistics | ( | ) |
Send ADR statistics.

| void LoRaWAN::setAppEUI | ( | const std::string & | appEUI | ) |
Set the Application EUI.
| appEUI | Application EUI as a hexadecimal string |


| void LoRaWAN::setAppKey | ( | const std::string & | appKey | ) |
Set the Application Key.
| appKey | Application Key as a hexadecimal string |


| void LoRaWAN::setAppSKey | ( | const std::string & | appSKey | ) |
Set the Application Session Key.
Used for ABP activation.
| appSKey | Application Session Key as a hexadecimal string |
| void LoRaWAN::setChannel | ( | uint8_t | channel | ) |
Set the current channel.
| channel | The channel index |
| void LoRaWAN::setDevAddr | ( | const std::string & | devAddr | ) |
Set the Device Address.
Used for ABP activation.
| devAddr | Device Address as a hexadecimal string |
| void LoRaWAN::setDevEUI | ( | const std::string & | devEUI | ) |
Set the Device EUI.
| devEUI | Device EUI as a hexadecimal string |


| void LoRaWAN::setDeviceClass | ( | DeviceClass | deviceClass | ) |
Set the device class (A, B, or C).
| deviceClass | The device class to set |

| void LoRaWAN::setFrameCounter | ( | uint32_t | counter | ) |
Set the frame counter.
| counter | The new frame counter value |
| void LoRaWAN::setFrequency | ( | float | freq_mhz | ) |
Set the frequency.
| freq_mhz | The frequency in MHz |

| void LoRaWAN::setNwkSKey | ( | const std::string & | nwkSKey | ) |
Set the Network Session Key.
Used for ABP activation.
| nwkSKey | Network Session Key as a hexadecimal string |
| void LoRaWAN::setRegion | ( | int | region | ) |
Set the LoRaWAN region.
| region | The region to set |
| void LoRaWAN::setSingleChannel | ( | bool | enable, |
| float | freq_mhz = 868.1, |
||
| int | sf = 9, |
||
| int | bw = 125, |
||
| int | cr = 5, |
||
| int | power = 14, |
||
| int | preamble = 8 |
||
| ) |
Enable or disable single channel mode.
| enable | Whether to enable single channel mode |
| freq_mhz | The frequency in MHz |
| sf | Spreading factor (7-12) |
| bw | Bandwidth in kHz (125, 250, or 500) |
| cr | Coding rate (5-8 for 4/5 to 4/8) |
| power | Transmission power in dBm |
| preamble | Preamble length |

| void LoRaWAN::setTxPower | ( | int8_t | power | ) |
Set the transmission power.
| power | The transmission power in dBm |
| void LoRaWAN::setupRxWindows | ( | ) |
Set up receive windows.

|
inlinestatic |
Set verbose mode.
| verbose | Whether to enable verbose mode |

| void LoRaWAN::sleep | ( | ) |
Put the radio in sleep mode.
| void LoRaWAN::update | ( | ) |
Update the LoRaWAN state.
Should be called regularly to handle received messages and other events.


| void LoRaWAN::updateDataRateFromSF | ( | ) |
Update the data rate from the spreading factor.

| void LoRaWAN::updateRxWindows | ( | ) |
Update receive windows.


| void LoRaWAN::updateTxParamsForADR | ( | ) |
Update transmission parameters for ADR.

| bool LoRaWAN::validateKeys | ( | ) | const |
Validate the session keys.

| void LoRaWAN::wake | ( | ) |
Wake the radio from sleep mode.
|
private |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
private |
|
private |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
private |
|
private |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
private |
|
staticconstexprprivate |