IoT Drivers  v3.3.0 (S2022)
Engineering in Software Technology
Receive a downlink message

In this use case, a downlink link message will be received. A downlink message is received in a lora_driver_payload_t variable.

Note
The driver must be initialised Initialise the driver and must be setup to OTAA OTAA setup steps or ABP OTAA setup steps.
To be able to receive any downlink messages you may specify a FreeRTOS message buffer during the initialisation of the driver. In this message buffer the received messages will be delivered by the driver (Initialise the driver).

In this example a downlink message with 4 bytes will be received from the LoRaWAN. These 4 bytes will in this example represent a maximum humidity setting and a maximum temperature setting that we want to be able to recieve from the LoRaWAN.

uint16_t maxHumSetting; // Max Humidity
int16_t maxTempSetting; // Max Temperature

Down-link Message Setup

The following must be added to a FreeRTOS tasks for(;;) loop in your application - typical you will have a separate task for handling downlink messages:

  1. Define a payload struct variable Create a payload variable to receive the down-link message in
    lora_driver_payload_t downlinkPayload;
  2. Wait for a message to be received
    // this code must be in the loop of a FreeRTOS task!
    xMessageBufferReceive(downLinkMessageBufferHandle, &downlinkPayload, sizeof(lora_driver_payload_t), portMAX_DELAY);
    printf("DOWN LINK: from port: %d with %d bytes received!", downlinkPayload.port_no, downlinkPayload.len); // Just for Debug
    if (4 == downlinkPayload.len) // Check that we have got the expected 4 bytes
    {
    // decode the payload into our variales
    maxHumSetting = (downlinkPayload.bytes[0] << 8) + downlinkPayload.bytes[1];
    maxTempSetting = (downlinkPayload.bytes[2] << 8) + downlinkPayload.bytes[3];
    }
lora_driver_payload::len
uint8_t len
Definition: lora_driver.h:53
lora_driver_payload::bytes
uint8_t bytes[LORA_MAX_PAYLOAD_LENGTH]
Definition: lora_driver.h:54
lora_driver_payload
Payload data structure.
Definition: lora_driver.h:51