LoRaWAN Muxer (lwmux)

The lwmux module arbitrates access to the LoRaWAN uplink layer for multiple independent modules. Further, it provides hooks for LoRaWAN layer events and a higher-lever API for accessing basic network functions.

Hooks

The lwmux module provides the following hooks:

lwm_event

void lwm_event(ev_t e)

This hook is called on every LMiC event and allows the consumer to react to LoRaWAN layer events such as downlink reception. The parameter e contains the current LMIC event.

API

The API for the lwmux module is defined in the followig header file:

#include "lwmux/lwmux.h"
void lwm_setmode(int mode)

Sets the current operation mode of the LoRaWAN layer:

Parameters:
  • mode
    LWM_MODE_SHUTDOWN

    In shutdown mode, the stack is disconnected from the network and does not send or receive messages. This is the default mode upon startup.

    LWM_MODE_NORMAL

    In normal mode, the stack will join the network using OTAA, and once connected, send and receive messages.

void lwm_request_send(lwm_job* job, unsigned int priority, lwm_tx txfunc)

Requests a message transmission opportunity.

Parameters:
  • job – Pointer to a LWM job structure. This structure must be allocated by the caller and is used by the LWM module to keep the state of the transmission request.
  • priority – The priority level of the job. The LWM module uses this value to arbitrate conflicts: If a transmission opportunity arises while there are multiple transmission requests pending, the one with the highest priority is selected.
  • txfunc

    Pointer to the transmission callback function. This function will be called by the LWM module when a transmission opportunity arises and this request was selected.

    bool (*lwm_tx)(lwm_txinfo* txinfo)

    To send a message, the callback function shall place the necessary information into the txinfo structure and return true.

    If the callback function decides that it does not wish to transmit at this time, it shall return false.

    The lwm_txinfo structure has the following fields:

    unsigned char* data

    Pointer to payload data. The application can either copy the data it wants to transmit to this buffer, or change the pointer to point to its own buffer.

    int dlen

    Length of payload data. This value is initialized to the current maximum payload length. It must be set to the actual payload length by the callback function.

    int port

    The port on which to send the message on.

    int confirmed

    To send a confirmed message (ACK bit set), the application must set this field to a non-zero value.

    lwm_complete txcomplete

    If the application wants to be notified once the message transaction is complete, it can place a pointer to a callback function in this field.

    void (*lwm_complete)(void)
void lwm_clear_send(lwm_job* job)

Cancel a previous request for a message transmission opportunity.

Parameters:
  • job – Pointer to the LWM job structure.