LoRaMesher Library  0.0.5
A LoRa Mesh library for the IoT
LoraMesher Class Reference

LoRaMesher Library. More...

#include <LoraMesher.h>

Public Member Functions

void begin (float freq=LM_BAND, float bw=LM_BANDWIDTH, uint8_t sf=LM_LORASF, uint8_t cr=LM_CODING_RATE, uint8_t syncWord=LM_SYNC_WORD, int8_t power=LM_POWER, uint16_t preambleLength=LM_PREAMBLE_LENGTH)
 LoRaMesh initialization method. More...
 
void init (void(*receiverFunction)(void *))
 Initialize the LoraMesher object. More...
 
void start ()
 Start/Resume LoRaMesher. After calling begin(...) or standby() you can Start/resume the LoRaMesher. After Start/Resume LoRaMesher it will create and send a Routing Message. Do not abuse this function, it will prevent the duty cycle to function as intended.
 
void standby ()
 Standby LoRaMesher. Including tasks and reception and send packets.
 
 ~LoraMesher ()
 Destroy the LoraMesher.
 
void setFrequency (float freq)
 Set the Frequency. Allowed values range from 137.0 MHz to 525.0 MHz. More...
 
void setBandwidth (float bw)
 Sets LoRa bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. More...
 
void setSpreadingFactor (uint8_t sf)
 Sets LoRa spreading factor. Allowed values range from 6 to 12. More...
 
void setCodingRate (uint8_t cr)
 Sets LoRa coding rate denominator. Allowed values range from 5 to 8. More...
 
void setOutputPower (int8_t power, bool useRfo=false)
 Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin). High power +20 dBm operation is also supported, on the PA_BOOST pin. More...
 
void setReceiveAppDataTaskHandle (TaskHandle_t ReceiveAppDataTaskHandle)
 Set the Receive App Data Task Handle, every time a received packet for this node is detected, this task will be notified. More...
 
LM_LinkedList< RouteNode > * routingTableList ()
 Routing table List.
 
template<typename T >
void createPacketAndSend (uint16_t dst, T *payload, uint8_t payloadSize)
 Create a Packet And Send it. More...
 
void sendReliablePacket (uint16_t dst, uint8_t *payload, uint32_t payloadSize)
 Send the payload reliable. It will wait for an ACK back from the destination to send the next packet. More...
 
template<typename T >
void sendReliable (uint16_t dst, T *payload, uint32_t payloadSize)
 Send the payload reliable. It will wait for an ack of the destination. More...
 
size_t getReceivedQueueSize ()
 Returns the number of packets inside the received packets queue. More...
 
size_t getSendQueueSize ()
 Get the Send Queue Size. Packets that are waiting to be send. More...
 
template<typename T >
AppPacket< T > * getNextAppPacket ()
 Get the Next Application Packet. More...
 
int routingTableSize ()
 Returns the routing table size. More...
 
uint16_t getLocalAddress ()
 Get the Local Address. More...
 
uint32_t getReceivedDataPacketsNum ()
 Get the Received Data Packets Num. More...
 
uint32_t getSendPacketsNum ()
 Get the Send Packets Num. More...
 
uint32_t getReceivedHelloPacketsNum ()
 Get the Received Hello Packets Num. More...
 
uint32_t getSentHelloPacketsNum ()
 Get the Sent Hello Packets Num. More...
 
uint32_t getReceivedBroadcastPacketsNum ()
 Get the Received Broadcast Packets Num. More...
 
uint32_t getForwardedPacketsNum ()
 Get the Received Broadcast Packets Num. More...
 
uint32_t getDataPacketsForMeNum ()
 Get the Data Packets For Me Num. More...
 
uint32_t getReceivedIAmViaNum ()
 Get the Received I Am Via Num. More...
 
uint32_t getDestinyUnreachableNum ()
 Get the Destiny Unreachable Num. More...
 
uint32_t getReceivedNotForMe ()
 Get the Received Not For Me. More...
 

Static Public Member Functions

static LoraMeshergetInstance ()
 Get the Instance of the LoRaMesher. More...
 
template<typename T >
static void deletePacket (AppPacket< T > *p)
 Delete the packet from memory. More...
 

Detailed Description

LoRaMesher Library.

Member Function Documentation

◆ begin()

void LoraMesher::begin ( float  freq = LM_BAND,
float  bw = LM_BANDWIDTH,
uint8_t  sf = LM_LORASF,
uint8_t  cr = LM_CODING_RATE,
uint8_t  syncWord = LM_SYNC_WORD,
int8_t  power = LM_POWER,
uint16_t  preambleLength = LM_PREAMBLE_LENGTH 
)

LoRaMesh initialization method.

Parameters
freqCarrier frequency in MHz. Allowed values range from 137.0 MHz to 1020.0 MHz.
bwLoRa bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
sfLoRa spreading factor. Allowed values range from 6 to 12.
crLoRa coding rate denominator. Allowed values range from 5 to 8.
syncWordLoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
powerTransmission output power in dBm. Allowed values range from 2 to 17 dBm.
preambleLengthLength of LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. Allowed values range from 6 to 65535.

Example of usage:

void processReceivedPackets(void* parameters) {
for (;;) {
//Wait for the notification of processReceivedPackets and enter blocking
ulTaskNotifyTake(pdPASS, portMAX_DELAY);
// Get the receivedAppPackets and get all the elements
while (radio.getReceivedQueueSize() > 0) {
//Get the first element inside the Received User Packets FiFo
AppPacket<DataPacket>* packet = radio.getNextAppPacket<DataPacket>();
//Do something with the packet, ex: print(packetReceived);
//Then delete the packet
radio.deletePacket(packet);
}
}
}
Application packet, it is used to send the packet to the application layer.
Definition: AppPacket.h:11

Then initialize:

radio.begin();
radio.start();
LoRaMesher Library.
Definition: LoraMesher.h:28
static LoraMesher & getInstance()
Get the Instance of the LoRaMesher.
Definition: LoraMesher.h:36
void begin(float freq=LM_BAND, float bw=LM_BANDWIDTH, uint8_t sf=LM_LORASF, uint8_t cr=LM_CODING_RATE, uint8_t syncWord=LM_SYNC_WORD, int8_t power=LM_POWER, uint16_t preambleLength=LM_PREAMBLE_LENGTH)
LoRaMesh initialization method.
Definition: LoraMesher.cpp:5
void start()
Start/Resume LoRaMesher. After calling begin(...) or standby() you can Start/resume the LoRaMesher....
Definition: LoraMesher.cpp:52

Then for receiving app packets:

TaskHandle_t receiveLoRaMessage_Handle = NULL;
int res = xTaskCreate(
processReceivedPackets,
"Receive User routine",
4096,
(void*) 1,
2,
&receiveLoRaMessage_Handle);
if (res != pdPASS) {
Log.errorln(F("Receive User Task creation gave error: %d"), res);
}
radio.setReceiveAppDataTaskHandle(receiveLoRaMessage_Handle);
void setReceiveAppDataTaskHandle(TaskHandle_t ReceiveAppDataTaskHandle)
Set the Receive App Data Task Handle, every time a received packet for this node is detected,...
Definition: LoraMesher.h:200

RadioLib reference begin code

◆ createPacketAndSend()

template<typename T >
void LoraMesher::createPacketAndSend ( uint16_t  dst,
T *  payload,
uint8_t  payloadSize 
)
inline

Create a Packet And Send it.

Template Parameters
T
Parameters
dstDestination
payloadPayload of type T
payloadSizeLength of the payload in T

◆ deletePacket()

template<typename T >
static void LoraMesher::deletePacket ( AppPacket< T > *  p)
inlinestatic

Delete the packet from memory.

Template Parameters
TType of packet
Parameters
pPacket to delete

◆ getDataPacketsForMeNum()

uint32_t LoraMesher::getDataPacketsForMeNum ( )
inline

Get the Data Packets For Me Num.

Returns
uint32_t

◆ getDestinyUnreachableNum()

uint32_t LoraMesher::getDestinyUnreachableNum ( )
inline

Get the Destiny Unreachable Num.

Returns
uint32_t

◆ getForwardedPacketsNum()

uint32_t LoraMesher::getForwardedPacketsNum ( )
inline

Get the Received Broadcast Packets Num.

Returns
uint32_t

◆ getInstance()

static LoraMesher & LoraMesher::getInstance ( )
inlinestatic

Get the Instance of the LoRaMesher.

Returns
LoraMesher&

◆ getLocalAddress()

uint16_t LoraMesher::getLocalAddress ( )

Get the Local Address.

Returns
uint16_t Address

◆ getNextAppPacket()

template<typename T >
AppPacket< T > * LoraMesher::getNextAppPacket ( )
inline

Get the Next Application Packet.

Template Parameters
TType to be converted
Returns
AppPacket<T>*

◆ getReceivedBroadcastPacketsNum()

uint32_t LoraMesher::getReceivedBroadcastPacketsNum ( )
inline

Get the Received Broadcast Packets Num.

Returns
uint32_t

◆ getReceivedDataPacketsNum()

uint32_t LoraMesher::getReceivedDataPacketsNum ( )
inline

Get the Received Data Packets Num.

Returns
uint32_t

◆ getReceivedHelloPacketsNum()

uint32_t LoraMesher::getReceivedHelloPacketsNum ( )
inline

Get the Received Hello Packets Num.

Returns
uint32_t

◆ getReceivedIAmViaNum()

uint32_t LoraMesher::getReceivedIAmViaNum ( )
inline

Get the Received I Am Via Num.

Returns
uint32_t

◆ getReceivedNotForMe()

uint32_t LoraMesher::getReceivedNotForMe ( )
inline

Get the Received Not For Me.

Returns
uint32_t

◆ getReceivedQueueSize()

size_t LoraMesher::getReceivedQueueSize ( )

Returns the number of packets inside the received packets queue.

Returns
size_t Received Queue Size

End Region Routing Table Region PacketQueue

◆ getSendPacketsNum()

uint32_t LoraMesher::getSendPacketsNum ( )
inline

Get the Send Packets Num.

Returns
uint32_t

◆ getSendQueueSize()

size_t LoraMesher::getSendQueueSize ( )

Get the Send Queue Size. Packets that are waiting to be send.

Returns
size_t Send Queue Size

◆ getSentHelloPacketsNum()

uint32_t LoraMesher::getSentHelloPacketsNum ( )
inline

Get the Sent Hello Packets Num.

Returns
uint32_t

◆ init()

void LoraMesher::init ( void(*)(void *)  receiverFunction)

Initialize the LoraMesher object.

Parameters
receiverFunctionReceiver function. It will be notified when data for the user is available. Example of usage:
void processReceivedPackets(void* parameters) {
for (;;) {
//Wait for the notification of processReceivedPackets and enter blocking
ulTaskNotifyTake(pdPASS, portMAX_DELAY);
// Get the receivedAppPackets and get all the elements
while (radio.getReceivedQueueSize() > 0) {
//Get the first element inside the Received User Packets FiFo
AppPacket<DataPacket>* packet = radio.getNextAppPacket<DataPacket>();
//Do something with the packet, ex: print(packetReceived);
//Then delete the packet
radio.deletePacket(packet);
}
}
}

Then initialize:

radio.init(processReceivedPackets);
void init(void(*receiverFunction)(void *))
Initialize the LoraMesher object.
Definition: LoraMesher.cpp:13

◆ routingTableSize()

int LoraMesher::routingTableSize ( )

Returns the routing table size.

Returns
int

End Region Packet Service Region Routing Table

◆ sendReliable()

template<typename T >
void LoraMesher::sendReliable ( uint16_t  dst,
T *  payload,
uint32_t  payloadSize 
)
inline

Send the payload reliable. It will wait for an ack of the destination.

Template Parameters
T
Parameters
dstDestination
payloadPayload of type T
payloadSizeLength of the payload in T

◆ sendReliablePacket()

void LoraMesher::sendReliablePacket ( uint16_t  dst,
uint8_t *  payload,
uint32_t  payloadSize 
)

Send the payload reliable. It will wait for an ACK back from the destination to send the next packet.

Parameters
dstdestination address
payloadpayload to send
payloadSizepayload size to be send in Bytes

◆ setBandwidth()

void LoraMesher::setBandwidth ( float  bw)
inline

Sets LoRa bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.

Parameters
bwLoRa bandwidth to be set in kHz.

◆ setCodingRate()

void LoraMesher::setCodingRate ( uint8_t  cr)
inline

Sets LoRa coding rate denominator. Allowed values range from 5 to 8.

Parameters
crLoRa coding rate denominator to be set.

◆ setFrequency()

void LoraMesher::setFrequency ( float  freq)
inline

Set the Frequency. Allowed values range from 137.0 MHz to 525.0 MHz.

Parameters
freqFrequency to be set in MHz

◆ setOutputPower()

void LoraMesher::setOutputPower ( int8_t  power,
bool  useRfo = false 
)
inline

Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin). High power +20 dBm operation is also supported, on the PA_BOOST pin.

Parameters
powerTransmission output power in dBm.
useRfoWhether to use the RFO (true) or the PA_BOOST (false) pin for the RF output. Defaults to PA_BOOST.

◆ setReceiveAppDataTaskHandle()

void LoraMesher::setReceiveAppDataTaskHandle ( TaskHandle_t  ReceiveAppDataTaskHandle)
inline

Set the Receive App Data Task Handle, every time a received packet for this node is detected, this task will be notified.

Parameters
ReceiveAppDataTaskHandleTask handle which will be notified every time a packet for the application is detected.

◆ setSpreadingFactor()

void LoraMesher::setSpreadingFactor ( uint8_t  sf)
inline

Sets LoRa spreading factor. Allowed values range from 6 to 12.

Parameters
sfLoRa spreading factor to be set.

The documentation for this class was generated from the following files: