Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
lorawan.h File Reference

Public LoRaWAN APIs. More...

#include <device.h>
#include <sys/slist.h>

Go to the source code of this file.

Data Structures

struct  lorawan_join_otaa
 LoRaWAN join parameters for over-the-Air activation (OTAA) More...
 
struct  lorawan_join_abp
 
struct  lorawan_join_config
 
struct  lorawan_downlink_cb
 

Macros

#define LW_RECV_PORT_ANY   UINT16_MAX
 

Enumerations

enum  lorawan_class { LORAWAN_CLASS_A = 0x00 , LORAWAN_CLASS_B = 0x01 , LORAWAN_CLASS_C = 0x02 }
 LoRaWAN class types. More...
 
enum  lorawan_act_type { LORAWAN_ACT_OTAA = 0 , LORAWAN_ACT_ABP }
 LoRaWAN activation types. More...
 
enum  lorawan_datarate {
  LORAWAN_DR_0 = 0 , LORAWAN_DR_1 , LORAWAN_DR_2 , LORAWAN_DR_3 ,
  LORAWAN_DR_4 , LORAWAN_DR_5 , LORAWAN_DR_6 , LORAWAN_DR_7 ,
  LORAWAN_DR_8 , LORAWAN_DR_9 , LORAWAN_DR_10 , LORAWAN_DR_11 ,
  LORAWAN_DR_12 , LORAWAN_DR_13 , LORAWAN_DR_14 , LORAWAN_DR_15
}
 LoRaWAN datarate types. More...
 
enum  lorawan_message_type { LORAWAN_MSG_CONFIRMED = BIT(0) }
 LoRaWAN message types. More...
 

Functions

int lorawan_set_battery_level_callback (uint8_t(*battery_lvl_cb)(void))
 Add battery level callback function. More...
 
void lorawan_register_downlink_callback (struct lorawan_downlink_cb *cb)
 Register a callback to be run on downlink packets. More...
 
void lorawan_register_dr_changed_callback (void(*dr_cb)(enum lorawan_datarate))
 Register a callback to be called when the datarate changes. More...
 
int lorawan_join (const struct lorawan_join_config *config)
 Join the LoRaWAN network. More...
 
int lorawan_start (void)
 Start the LoRaWAN stack. More...
 
int lorawan_send (uint8_t port, uint8_t *data, uint8_t len, uint8_t flags)
 Send data to the LoRaWAN network. More...
 
int lorawan_set_class (enum lorawan_class dev_class)
 Set the current device class. More...
 
int lorawan_set_conf_msg_tries (uint8_t tries)
 Set the number of tries used for transmissions. More...
 
void lorawan_enable_adr (bool enable)
 Enable Adaptive Data Rate (ADR) More...
 
int lorawan_set_datarate (enum lorawan_datarate dr)
 Set the default data rate. More...
 
enum lorawan_datarate lorawan_get_min_datarate (void)
 Get the minimum possible datarate. More...
 
void lorawan_get_payload_sizes (uint8_t *max_next_payload_size, uint8_t *max_payload_size)
 Get the current payload sizes. More...
 

Detailed Description

Public LoRaWAN APIs.

Macro Definition Documentation

◆ LW_RECV_PORT_ANY

#define LW_RECV_PORT_ANY   UINT16_MAX

Enumeration Type Documentation

◆ lorawan_act_type

LoRaWAN activation types.

Enumerator
LORAWAN_ACT_OTAA 
LORAWAN_ACT_ABP 

◆ lorawan_class

LoRaWAN class types.

Enumerator
LORAWAN_CLASS_A 
LORAWAN_CLASS_B 
LORAWAN_CLASS_C 

◆ lorawan_datarate

LoRaWAN datarate types.

Enumerator
LORAWAN_DR_0 
LORAWAN_DR_1 
LORAWAN_DR_2 
LORAWAN_DR_3 
LORAWAN_DR_4 
LORAWAN_DR_5 
LORAWAN_DR_6 
LORAWAN_DR_7 
LORAWAN_DR_8 
LORAWAN_DR_9 
LORAWAN_DR_10 
LORAWAN_DR_11 
LORAWAN_DR_12 
LORAWAN_DR_13 
LORAWAN_DR_14 
LORAWAN_DR_15 

◆ lorawan_message_type

LoRaWAN message types.

Note: The default message type is unconfirmed.

Enumerator
LORAWAN_MSG_CONFIRMED 

Function Documentation

◆ lorawan_enable_adr()

void lorawan_enable_adr ( bool  enable)

Enable Adaptive Data Rate (ADR)

Control whether adaptive data rate (ADR) is enabled. When ADR is enabled, the data rate is treated as a default data rate that will be used if the ADR algorithm has not established a data rate. ADR should normally only be enabled for devices with stable RF conditions (i.e., devices in a mostly static location).

Parameters
enableEnable or Disable adaptive data rate.

◆ lorawan_get_min_datarate()

enum lorawan_datarate lorawan_get_min_datarate ( void  )

Get the minimum possible datarate.

The minimum possible datarate may change in response to a TxParamSetupReq command from the network server.

Returns
Minimum possible data rate

◆ lorawan_get_payload_sizes()

void lorawan_get_payload_sizes ( uint8_t max_next_payload_size,
uint8_t max_payload_size 
)

Get the current payload sizes.

Query the current payload sizes. The maximum payload size varies with datarate, while the current payload size can be less due to MAC layer commands which are inserted into uplink packets.

Parameters
max_next_payload_sizeMaximum payload size for the next transmission
max_payload_sizeMaximum payload size for this datarate

◆ lorawan_join()

int lorawan_join ( const struct lorawan_join_config config)

Join the LoRaWAN network.

Join the LoRaWAN network using OTAA or AWB.

Parameters
configConfiguration to be used
Returns
0 if successful, negative errno code if failure

◆ lorawan_register_downlink_callback()

void lorawan_register_downlink_callback ( struct lorawan_downlink_cb cb)

Register a callback to be run on downlink packets.

Parameters
cbPointer to structure containing callback parameters

◆ lorawan_register_dr_changed_callback()

void lorawan_register_dr_changed_callback ( void(*)(enum lorawan_datarate dr_cb)

Register a callback to be called when the datarate changes.

The callback is called once upon successfully joining a network and again each time the datarate changes due to ADR.

The callback function takes one parameter:

  • dr - updated datarate
Parameters
dr_cbPointer to datarate update callback

◆ lorawan_send()

int lorawan_send ( uint8_t  port,
uint8_t data,
uint8_t  len,
uint8_t  flags 
)

Send data to the LoRaWAN network.

Send data to the connected LoRaWAN network.

Parameters
portPort to be used for sending data. Must be set if the payload is not empty.
dataData buffer to be sent
lenLength of the buffer to be sent. Maximum length of this buffer is 255 bytes but the actual payload size varies with region and datarate.
flagsFlag used to determine the type of message being sent. It could be one of the lorawan_message_type. The default behaviour is unconfirmed message.
Returns
0 if successful, negative errno code if failure

◆ lorawan_set_battery_level_callback()

int lorawan_set_battery_level_callback ( uint8_t(*)(void battery_lvl_cb)

Add battery level callback function.

Provide the LoRaWAN stack with a function to be called whenever a battery level needs to be read. As per LoRaWAN specification the callback needs to return "0: node is connected to an external power source, 1..254: battery level, where 1 is the minimum and 254 is the maximum value, 255: the node was not able to measure the battery level"

Should no callback be provided the lorawan backend will report 255.

Parameters
battery_lvl_cbPointer to the battery level function
Returns
0 if successful, negative errno code if failure

◆ lorawan_set_class()

int lorawan_set_class ( enum lorawan_class  dev_class)

Set the current device class.

Change the current device class. This function may be called before or after a network connection has been established.

Parameters
dev_classNew device class
Returns
0 if successful, negative errno code if failure

◆ lorawan_set_conf_msg_tries()

int lorawan_set_conf_msg_tries ( uint8_t  tries)

Set the number of tries used for transmissions.

Parameters
triesNumber of tries to be used
Returns
0 if successful, negative errno code if failure

◆ lorawan_set_datarate()

int lorawan_set_datarate ( enum lorawan_datarate  dr)

Set the default data rate.

Change the default data rate.

Parameters
drData rate used for transmissions
Returns
0 if successful, negative errno code if failure

◆ lorawan_start()

int lorawan_start ( void  )

Start the LoRaWAN stack.

This function need to be called before joining the network.

Returns
0 if successful, negative errno code if failure