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;
int16_t maxTempSetting;
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:
- Define a payload struct variable Create a payload variable to receive the down-link message in
- Wait for a message to be received
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);
if (4 == downlinkPayload.
len)
{
maxHumSetting = (downlinkPayload.
bytes[0] << 8) + downlinkPayload.
bytes[1];
maxTempSetting = (downlinkPayload.
bytes[2] << 8) + downlinkPayload.
bytes[3];
}