This example demonstrates how to switch between Class A and Class B modes in a LoRaWAN application, allowing the device to communicate using scheduled ping slots in Class B mode.
This application automatically submits a Join-Request to the LoRa Network Server.
Once the join accept is received, the application waits for the blue button to be pressed.
Pressing the NUCLEO blue button switches the device between Class A and Class B.
Once Class B is set, the modem will automatically send a DevTimeRequest and a PingSlotInfoRequest to the Network Server, then enable Class B after receiving a beacon.
Several constants are defined at the top of main_lorawan.c, common_app_configuration.h, or lorawan_commissioning.h. Their values can be set to define the LoRaWAN configuration of the application.
| Constant | Comments |
|---|---|
EXTI_BUTTON |
Pin name of the button. |
LORAWAN_APP_DATA_MAX_SIZE |
User application data buffer size. |
LORAWAN_REGION_USED |
LoRaWAN regulatory region. |
PING_SLOT_PERIODICITY |
Ping slot periodicity for class B unicast. |
Supported values for LORAWAN_REGION_USED:
MODEM_E_LORAWAN_REGION_AS923_GRP1MODEM_E_LORAWAN_REGION_AS923_GRP2MODEM_E_LORAWAN_REGION_AS923_GRP3MODEM_E_LORAWAN_REGION_AS923_GRP4MODEM_E_LORAWAN_REGION_AU915MODEM_E_LORAWAN_REGION_CN470MODEM_E_LORAWAN_REGION_EU868 (default)MODEM_E_LORAWAN_REGION_IN865MODEM_E_LORAWAN_REGION_KR920MODEM_E_LORAWAN_REGION_RU864MODEM_E_LORAWAN_REGION_US915MODEM_E_LORAWAN_REGION_WW2G4
Supported values for PING_SLOT_PERIODICITY:
MODEM_E_CLASS_B_PING_SLOT_1_SMODEM_E_CLASS_B_PING_SLOT_2_SMODEM_E_CLASS_B_PING_SLOT_4_SMODEM_E_CLASS_B_PING_SLOT_8_SMODEM_E_CLASS_B_PING_SLOT_16_SMODEM_E_CLASS_B_PING_SLOT_32_SMODEM_E_CLASS_B_PING_SLOT_64_SMODEM_E_CLASS_B_PING_SLOT_128_S
The LR1121 is pre-provisioned with a ChipEUI/DevEUI and a JoinEUI. The application will use these identifiers if the USE_LR11XX_CREDENTIALS from lorawan_commissioning.h is set to true.
Alternatively, you can provide your own EUIs in Inc/apps/lorawan_commissioning/lorawan_commissioning.h by setting USE_LR11XX_CREDENTIALS to false and changing the values of LORAWAN_DEVICE_EUI, LORAWAN_JOIN_EUI, LORAWAN_NWK_KEY and LORAWAN_APP_KEY.
Information messages are displayed on the serial console, starting with the DevEUI, AppEUI/JoinEUI, and PIN that you might need to register your device with the LoRa Cloud Device Join service.
Once Class B is set and enabled, a message is displayed to inform you that Class B downlinks can now be received.
The application implements a state machine based on the reception of events:
- Reset event: Configures the keys, the region, and starts the join procedure.
- Joined event: Displays a message to inform you that you can push the blue button to switch to Class B.
- Class B status event: Immediately sends an uplink to inform the Network Server that Class B is running.
- TxDone event: Checks if Class B is enabled; if yes, displays a message to inform you that you can send Class B downlinks.
Pressing the blue button switches the device between Class A and Class B.