README.md
1# LoRa Basic Modem
2
3**LoRa Basic Modem** proposes an implementation of the [TS001-LoRaWAN L2 1.0.4](https://resources.lora-alliance.org/technical-specifications/ts001-1-0-4-lorawan-l2-1-0-4-specification) and [Regional Parameters RP2-1.0.3](https://resources.lora-alliance.org/technical-specifications/rp2-1-0-3-lorawan-regional-parameters) specifications.
4
5## Key Features
6
7- **Class A**: Supports Class A operation
8- **Class B**: Supports Class B operation (with up to 4 multicast sessions)
9- **Class C**: Supports Class C operation (with up to 4 multicast sessions)
10- **Region Support**:
11 - AS923 (AS923-1, AS923-2, AS923-3, AS923-4)
12 - `SMTC_MODEM_REGION_AS_923_GRP1`
13 - `SMTC_MODEM_REGION_AS_923_GRP2`
14 - `SMTC_MODEM_REGION_AS_923_GRP3`
15 - `SMTC_MODEM_REGION_AS_923_GRP4`
16 - AU915
17 - `SMTC_MODEM_REGION_AU_915`
18 - CN470
19 - `SMTC_MODEM_REGION_CN_470`
20 - `SMTC_MODEM_REGION_CN_470_RP_1_0`
21 - EU868
22 - `SMTC_MODEM_REGION_EU_868`
23 - IN865
24 - `SMTC_MODEM_REGION_IN_865`
25 - KR920
26 - `SMTC_MODEM_REGION_KR_920`
27 - RU864
28 - `SMTC_MODEM_REGION_RU_864`
29 - US915
30 - `SMTC_MODEM_REGION_US_915`
31
32 **Note**: In addition the proposed implementation also provides a 2.4 GHz global ISM band (WW2G4) region support.
33
34- **Semtech Radios Support**:
35 - LR1110 with firmware 0x0401.
36 - LR1120 with firmware 0x0201
37 - LR1121 with firmware 0x0103
38 - SX1261, SX1262, SX1268
39 - SX1280, SX1281
40 - Experimental: SX1272, SX1276
41
42- **Secure Elements**:
43 Supports both software-emulated and hardware secure-elements, providing necessary cryptographic operations for LoRaWAN protocol.
44
45- **MCU Abstraction Layer**:
46 Facilitates porting with the following required MCU hardware resources:
47 - 1 HW timer.
48 - 1 SPI interface.
49 - Minimum 40 KB of FLASH is required to operate in Class A with a single region (EX:EU868). Each additional region adds approximately 1.5 KB.
50 - Minimum 6KB of RAM memory.
51 - 48B of non-volatile memory to store LoRaWAN and modem context.
52 Up to 512B of non-volatile memory if a software-emulated secure-element is used.
53 - Optional 1 Watchdog.
54
55- **Activation Methods**:
56 - Supports OTAA activation by default
57 - ABP activation is implemented only for debugging purposes.
58 **Note:** No stack context is saved in non-volatile memory. Therefore, it is strongly discouraged to use this mode for any other purpose than debugging.
59
60- **Porting Options**:
61 - Supports Bare Metal or RTOS-based projects.
62
63## LoRa Basics Modem Options
64
65### Build process
66
67The build process using the makefile allows flexibility in choosing different compile-time options.
68To explore all available make process options, run:
69
70```bash
71make -C help
72```
73
74Build process options can be provided either using the command line or by editing [options.mk](makefiles/options.mk)
75
76### Radio Targets
77
78Support for the following transceivers can be selected at build time:
79
80- sx128x - SX1280 & SX1281 Transceivers.
81- lr1110 - LR1110 Transceiver.
82- lr1120 - LR1120 Transceiver.
83- lr1121 - LR1121 Transceiver.
84- sx1261 - SX1261 Transceiver.
85- sx1262 - SX1262 Transceiver.
86- sx1268 - SX1268 Transceiver.
87- sx1272 - SX1272 Transceiver.
88- sx1276 - SX1276 Transceiver.
89
90LoRa Basics™ Modem (LBM) should be built for a specific transceiver by using the basic_modem_<TARGET> parameter.
91
92### MCU Flags
93
94MCU flags are passed to the compiler through the MCU_FLAGS build parameter. The flags are set as a single text string.
95
96For example, to build LoRa Basics Modem for an STM32L4 MCU the following MCU_FLAGS are used:
97`MCU_FLAGS="-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard"`
98
99### Regions
100
101Support for one or more of the following regions can be selected at compile time:
102
103- AS_923 - AS923MHz ISM Band. Group selection is performed at runtime through the API.
104- AU_915 - AU915-928MHz ISM Band.
105- CN_470 - CN470-510MHz Band.
106- CN_470_RP_1_0 - CN470-510MHz Band. LoRaWAN Regional Parameters v1.0 version.
107- EU_868 - EU863-870MHz ISM Band.
108- IN_865 - IN865-867MHz ISM Band.
109- KR_920 - KR920-923MHz ISM Band.
110- RU_864 - RU864-870MHz ISM Band.
111- US_915 - US902-928MHz ISM Band.
112- WW_2G4 - Emulation of the LoRaWAN Standard for the 2.4GHz global ISM band.
113The supported regions are selected through the REGION build option. If the user does not explicitly select one or more
114regions, all regions are included at compile time.
115
116### Cryptographic Engine Selection
117
118LR11xx Transceivers include a Cryptographic Engine which provides a dedicated hardware accelerator for AES-128 encryption based algorithms. This Cryptographic Engine improves the power efficiency of cryptographic operations and reduces the code size of the software stack. Alternatively, LBM includes a software-implemented Cryptographic Engine.
119The selection of the Cryptographic Engine to use is done through the CRYPTO parameter. The following options are available:
120
121- **SOFT** - Use the LoRa Basics Modem Cryptographic Engine (Default).
122- **LR11XX** - Use the LR11xx Cryptographic Engine with user defined keys.
123- **LR11XX_WITH_CREDENTIALS** - Use the LR11xx Cryptographic Engine with pre-provisioned EUIs and keys.
124
125### LoRa Basics Modem Features Selection
126
127The user can choose which feature to embed in LoRa Basics Modem by updating [options.mk](makefiles/options.mk).
128
129**LoRaWAN Stack related options**:
130
131- LBM_CLASS_B: Enable compilation of class B feature
132- LBM_CLASS_C: Enable compilation of class C feature
133- LBM_MULTICAST: Enable compilation of LoRaWAN multicast feature
134- LBM_CSMA: Enable compilation of CSMA feature
135- LBM_RELAY_TX_ENABLE : Enable compilation of Relay Tx feature
136- LBM_RELAY_RX_ENABLE : Enable compilation of Relay Rx feature
137
138**LoRaWAN packages related options**:
139
140- LBM_ALC_SYNC: Enable compilation of LoRaWAN ALCSync package
141- LBM_ALC_SYNC_VERSION: to choose with version of ALCSync package shall be built
142- LBM_FUOTA: Enable compilation of LoRaWAN FUOTA dedicated packages
143- LBM_FUOTA_VERSION: to choose the version of FUOTA packages
144
145**LoRaCloud related options**:
146
147- LBM_ALMANAC: Enable compilation of the almanac update service
148- LBM_STREAM: Enable compilation of the Stream service
149- LBM_LFU: Enable compilation of the Large File Upload service
150- LBM_DEVICE_MANAGEMENT: Enable compilation of the device management service
151
152**Miscellaneous options**:
153
154- LBM_GEOLOCATION: Enable compilation of the geolocation service
155- LBM_STORE_AND_FORWARD: Enable compilation of the store and forward service
156
157### EXTRAFLAGS Usage
158
159Build time parameters are passed to the compiler through the use of the EXTRAFLAGS parameter.
160For example, to change the internal radio planner margin delay value the following build command line can be used:
161
162```bash
163make basic_modem_<TARGET> MCU_FLAGS=xxx EXTRAFLAGS="-DRP_MARGIN_DELAY=12"
164```
165
166### Debug and Optimization options
167
168The following options can be enabled for debugging:
169
170- VERBOSE=yes/no - Increase build verbosity (default: no).
171- DEBUG=yes/no - Enable debugging options (default: no).
172- MODEM_TRACE=yes/no - Choose to enable or disable modem trace print (default: yes).
173
174Build optimization can be chosen by updating `OPT` and `DEBUG_OPT` options
175
176## Developing an Application with LoRa Basics Modem
177
178### User application
179
180Initialize the stack by invoking the `smtc_modem_init()` API.
181Subsequently, call the `smtc_modem_run_engine()` API periodically to progress the internal state machine of the stack. The return value of the `smtc_modem_run_engine()` API indicates when the next task will be handled. Whenever a stack-related interruption occurs, call the `smtc_modem_run_engine()` API to process it and take necessary actions.
182Before entering a low-power wait mode, ensure no stack pending actions exist by using the `smtc_modem_is_irq_flag_pending()` API.
183
184Find the definitions for these APIs in [smtc_modem_utilities.h](smtc_modem_api/smtc_modem_utilities.h)
185
186### Modem API
187
188Refer to [smtc_modem_api.h](smtc_modem_api/smtc_modem_api.h) for the Application Programming Interface definitions.
189
190### Modem HAL
191
192For porting LoRa Basics Modem to a new architecture/platform, implement functions defined in [smtc_modem_hal.h](smtc_modem_hal/smtc_modem_hal.h).
193
194### Radio BSP (Board Specific Package) and HAL (Hardware Abstraction Layer)
195
196Semtech radio drivers and Radio Abstraction Layer (RAL) architecture requires the user to implement the radio HAL and BSP functions.
197
198Radio BSP functions are defined for each transceiver and can be found in [smtc_modem_core/smtc_ral/src](smtc_modem_core/smtc_ral/src) folder. (Files named `ral_xxx_bsp.h`).
199
200Radio HAL functions are defined for each transceiver in [smtc_modem_core/radio_drivers](smtc_modem_core/radio_drivers) folder.
201
202### Fetch an Event
203
204Utilize the shared callback during initialization to be informed of incoming events.
205Retrieve pending events by calling `smtc_modem_get_event()`.
206Unstack pending events with successive calls to `smtc_modem_get_event()` until `SMTC_MODEM_RC_NO_EVEN`T return code is received.
207
208### Join a LoRaWAN Network
209
210Before initiating a join procedure, set LoRaWAN parameters using the following functions:
211
212- LoRaWAN region with `smtc_modem_set_region()` (can only be changed when the modem is not joining or joined)
213- Configure EUIs and key parameters with functions such as `smtc_modem_set_deveui()`, `smtc_modem_set_joineui()` and `smtc_modem_set_nwkkey()`.
214- If needed set the type of network (private or public) using `smtc_modem_set_network_type()` (default is public).
215
216Once parameters are set, start joining a LoRaWAN network by calling `smtc_modem_join_network()`.
217The user is informed of the procedure's progress via two events:
218
219- `SMTC_MODEM_EVENT_JOINED`: Join accept received; the join procedure is complete.
220- `SMTC_MODEM_EVENT_JOINFAIL`: Nothing received after the join request; the join procedure continues.
221
222Cancel an ongoing join procedure or leave an already-joined network by calling `smtc_modem_leave_network()`.
223
224#### Join Sequence
225
226
227
228### Send Data Over LoRaWAN
229
230The user can send a standard uplink, while being connected, with the following functions:
231
232- `smtc_modem_request_uplink()`
233- `smtc_modem_request_emergency_uplink()` to send data with the highest priority, ignoring duty cycle restriction
234- `smtc_modem_request_empty_uplink()` to send an empty payload with an optional FPort field, creating a downlink opportunity
235
236Transmission status will be available through the event `SMTC_MODEM_EVENT_TXDONE` and can be one of the following:
237
238- `SMTC_MODEM_EVENT_TXDONE_NOT_SENT`: Transmission was not completed.
239- `SMTC_MODEM_EVENT_TXDONE_SENT`: Transmission was completed successfully.
240- `SMTC_MODEM_EVENT_TXDONE_CONFIRMED`: Transmission was completed successfully, and an acknowledgment was received from the network.
241
242### Receive Data Over LoRaWAN
243
244Upon receiving a downlink with data for the application, the event `SMTC_MODEM_EVENT_DOWNDATA` is triggered.
245Retrieve data and metadata by calling `smtc_modem_get_downlink_data()`.
246Available metadata includes RSSI, SNR, reception window, FPort, FPending bit, frequency, and datarate.
247
248### Manage a LoRaWAN Connection Lifecycle
249
250Once connected to a LoRaWAN network, configure parameters:
251
252- ADR profile with `smtc_modem_adr_set_profile()`
253- Number of transmissions for each unconfirmed uplink with `smtc_modem_set_nb_trans()`
254
255Retrieve information about the connection:
256
257- Duty cycle limitation status with `smtc_modem_get_duty_cycle_status()`
258- Maximum size of the next uplink with `smtc_modem_get_next_tx_max_payload()`
259- Available datarates with `smtc_modem_get_enabled_datarates()`
260- Number of consecutive uplinks without downlink with `smtc_modem_lorawan_get_lost_connection_counter()`
261
262### Carrier Sense Multiple Access (CSMA) for LoRaWAN
263
264The modem supports a CSMA (Carrier Sense Multiple Access) feature designed to prevent collisions in LoRa packet transmissions.
265LoRa Alliance Technical Recommendations can be read at [TR0013](https://resources.lora-alliance.org/home/tr013-1-0-0-csma)
266
267To enable CSMA during compilation, set the option `LBM_CSMA=yes` in the Makefile.
268By default, CSMA is activated at modem startup if the compilation option `USE_CSMA_BY_DEFAULT=yes` is configured.
269
270Toggle the CSMA feature on or off using the function `smtc_modem_csma_set_state()`.
271For tailored optimization to specific use cases, configure CSMA parameters with the function `smtc_modem_csma_set_parameters()`.
272
273**Note**: CSMA support is limited to lr11xx and sx126x radios. Activating this feature on other targets may result in undesirable behavior or modem panic.
274
275### LoRaWAN Class B
276
277LoRa Basic Modem does not support Class B by default. To use this feature, it must be activated during project compilation.
278
279#### Activating Class B Support
280
281Activate Class B support by setting the flag `LBM_CLASS_B` to yes in the [options.mk](makefiles/options.mk) file. This enables Class B functionality in LoRa Basic Modem.
282
283#### Starting Class B
284
285Initiate Class B after a successful join, preferably after receiving the `SMTC_MODEM_EVENT_JOINED` event.
286Start Class B by calling `smtc_modem_set_class()` with the parameter `SMTC_MODEM_CLASS_B`.
287LoRa Basic Modem autonomously handles prerequisites for Class B in LoRaWAN.
288
289To change the ping slot periodicity (default is 7, meaning a ping slot every 128 seconds), call `smtc_modem_class_b_set_ping_slot_periodicity()` before `smtc_modem_set_class()`.
290
291#### Special Cases
292
293- If your network server doesn't support time synchronization via a network command, activate the clk sync package to set the GPS time before starting Class B.
294- If no longer connected to the LoRaWAN network, Class B automatically stops after 2 hours without receiving a beacon. The user receives the `SMTC_MODEM_EVENT_CLASS_B_STATUS`
295
296#### Class B Sequence
297
298
299
300### LoRaWAN Multicast
301
302Up to 4 multicast groups can be configured by calling `smtc_modem_multicast_set_grp_config()` with the following parameters
303for each group to be configured:
304
305- Group ID
306- Address
307- Network session key
308- Application session key
309
310To retrieve the group address of a specific group ID, use `smtc_modem_multicast_get_grp_config()`.
311
312#### LoRaWAN Multicast in Class B
313
314In Class B mode, when multicast groups are configured, initiate each session by calling `smtc_modem_multicast_class_b_start_session()` with the following parameters:
315
316- Group ID
317- Frequency
318- Datarate
319- Ping slot
320
321For Class B multicast downlinks, use `smtc_modem_get_downlink_data()` after the `SMTC_MODEM_EVENT_DOWNDATA` event, and check the window metadata with `SMTC_MODEM_DL_WINDOW_RXB_MC_GRPx` (x being the multicast group ID).
322Retrieve the current session status with `smtc_modem_multicast_class_b_get_session_status()` and stop a multicast session with `smtc_modem_multicast_class_b_stop_session()`.
323To halt all Class B multicast sessions, use `smtc_modem_multicast_class_b_stop_all_sessions()`.
324
325#### LoRaWAN Multicast in Class C
326
327In Class C mode, when multicast groups are configured, initiate each session with `smtc_modem_multicast_class_c_start_session()` and provide:
328
329- Group ID
330- Frequency
331- Datarate
332
333Class C multicast downlinks are available by fetching downlink data with `smtc_modem_get_downlink_data()` after the event `SMTC_MODEM_EVENT_DOWNDATA` triggered. The window metadata value with `SMTC_MODEM_DL_WINDOW_RXC_MC_GRPx`(x being the multicast group ID).
334It is possible to read back the status of the current session by calling `smtc_modem_multicast_class_c_get_session_status()`.
335A multicast session can be stopped by calling `smtc_modem_multicast_class_c_stop_session()`.
336All class C multicast sessions can be stopped by calling `smtc_modem_multicast_class_c_stop_all_sessions()`.
337
338If the frequency or datarate of the first session differs from the current unicast Class C configuration, it will automatically switch. However, if subsequent sessions have different configurations, they cannot be started until all ongoing sessions are stopped with `smtc_modem_multicast_class_c_stop_session()`.
339For Class C multicast downlinks, use `smtc_modem_get_downlink_data()` after the `SMTC_MODEM_EVENT_DOWNDATA` event, and check the window metadata with `SMTC_MODEM_DL_WINDOW_RXC_MC_GRPx` (x being the multicast group ID).
340Retrieve the current session status with `smtc_modem_multicast_class_c_get_session_status()` and stop a multicast session with `smtc_modem_multicast_class_c_stop_session()`.
341To halt all Class C multicast sessions, use `smtc_modem_multicast_class_c_stop_all_sessions()`.
342
343### LoRaWAN Mac Request
344
345Initiate LoRaWAN-specific Mac requests with `smtc_modem_trig_lorawan_mac_request()`.
346
347#### LoRaWAN Link Check Request
348
349Use `smtc_modem_trig_lorawan_mac_request()` with the `SMTC_MODEM_LORAWAN_MAC_REQ_LINK_CHECK` bit mask to generate a LoRaWAN Link Check Request uplink.
350Transmission status is available through the `SMTC_MODEM_EVENT_LINK_CHECK` event:
351
352- `SMTC_MODEM_EVENT_MAC_REQUEST_NOT_ANSWERED`: No answer received from the network.
353- `SMTC_MODEM_EVENT_MAC_REQUEST_ANSWERED`: Valid answer received; data can be fetched using `smtc_modem_get_lorawan_link_check_data()`.
354
355#### LoRaWAN Device Time Request
356
357Use `smtc_modem_trig_lorawan_mac_request()` with the `SMTC_MODEM_LORAWAN_MAC_REQ_DEVICE_TIME` bit mask to generate a LoRaWAN Device Time Request uplink.
358Transmission status is available through the `SMTC_MODEM_EVENT_LORAWAN_MAC_TIME` event:
359
360- `SMTC_MODEM_EVENT_MAC_REQUEST_NOT_ANSWERED`: No answer received from the network.
361- `SMTC_MODEM_EVENT_MAC_REQUEST_ANSWERED`: Valid answer received; time can be fetched using `smtc_modem_get_lorawan_mac_time()`.
362
363#### LoRaWAN Ping Slot Info Request
364
365Use `smtc_modem_trig_lorawan_mac_request()` with the `SMTC_MODEM_LORAWAN_MAC_REQ_PING_SLOT_INFO` bit mask to generate a LoRaWAN Ping Slot Info Request uplink.
366Transmission status is available through the `SMTC_MODEM_EVENT_CLASS_B_PING_SLOT_INFO` event:
367
368- `SMTC_MODEM_EVENT_MAC_REQUEST_NOT_ANSWERED`: No answer received from the network.
369- `SMTC_MODEM_EVENT_MAC_REQUEST_ANSWERED`: Network acknowledged the request.
370
371## LoRa Basics Modem Additional Features
372
373### LoRaWAN Certification Protocol handling
374
375The LoRaWAN Certification package is essential during the LoRaWAN certification process. Follow these steps:
376
3771. Set LoRaWAN keys with `smtc_modem_set_deveui()`, `smtc_modem_set_joineui()`, `smtc_modem_set_nwkkey()` and `smtc_modem_set_appkey()`.
3782. Connect to the network with `smtc_modem_join_network()`
3793. Launch the certification service with `smtc_modem_set_certification_mode()`. This command saves a flag in NVM to permit the certification to reset the MCU when required and continue the certification process at boot.
380
381### Application Layer Clock Synchronization (ALCSync)
382
383Use this application when a Network Server doesn't support the DeviceTimeReq commands.
384Activate ALCSync support by setting the flag `LBM_ALC_SYNC` to yes in the [options.mk](makefiles/options.mk) file
385
386When started the application will trig a time synchronization to the application server every `periodicity_s` configured by the ALCSync server package.
387The default value is 36h.
388Each time a valid time sync answer is received by the modem, it will generate an event of type `SMTC_MODEM_EVENT_ALCSYNC_TIME`
389
390Start the service with `smtc_modem_start_alcsync_service()`.
391Stop the service with `smtc_modem_stop_alcsync_service()`.
392Get GPS epoch time, number of seconds elapsed since GPS epoch (00:00:00, Sunday 6th of January 1980) with `smtc_modem_get_alcsync_time()`
393Trigger a single uplink requesting time on Application Layer Clock Synchronization (ALCSync) service with `smtc_modem_trigger_alcsync_request()`, the service must be start first.
394
395## FUOTA (Firmware Update Over The Air)
396
397The FUOTA service in LoRa Basics Modem aligns with the firmware update standard established by the LoRa Alliance. It encompasses five Applicative Packages outlined in the LoRaWAN standard:
398
399- **LoRaWAN Remote Multicast Setup** Specification:
400 - [TS005-1.0.0](https://resources.lora-alliance.org/technical-specifications/lorawan-remote-multicast-setup-specification-v1-0-0)
401 - [TS005-2.0.0](https://resources.lora-alliance.org/technical-specifications/ts005-2-0-0-remote-multicast-setup)
402- **LoRaWAN Fragmented Data Block Transport** Specification:
403 - [TS004-1.0.0](https://resources.lora-alliance.org/technical-specifications/lorawan-fragmented-data-block-transport-specification-v1-0-0)
404 - [TS004-2.0.0](https://resources.lora-alliance.org/technical-specifications/ts004-2-0-0-fragmented-data-block-transport)
405- **LoRaWAN Application Layer Clock Synchronization** Specification:
406 - [TS003-1.0.0](https://resources.lora-alliance.org/technical-specifications/lorawan-application-layer-clock-synchronization-specification-v1-0-0)
407 - [TS003-2.0.0](https://resources.lora-alliance.org/technical-specifications/ts003-2-0-0-application-layer-clock-synchronization)
408- **Firmware Management Protocol** Specification: [TS006-1.0.0](https://resources.lora-alliance.org/technical-specifications/ts006-1-0-0-firmware-management-protocol)
409- **Multi-Package Access** Specification: [TS007-1.0.0](https://resources.lora-alliance.org/technical-specifications/ts007-1-0-0-multi-package-access)
410
411This library offers the implementation of LoRaWAN Alliance's V1 and V2 Fuota packages
412The proposed implementation supports both Class B or Class C modes and supports up to 4 simultaneous multicast sessions.
413
414### FUOTA Activation
415
416FUOTA is not enabled by default in LoRa Basics™ Modem.
417To activate it during project compilation, set the `LBM_FUOTA` flag to `yes` and set the `LBM_FUOTA_VERSION` flag to chosen version number 1 or 2 in [options.mk](makefiles/options.mk).
418
419Multi-Package Access is not automatically added to compilation even if `LBM_FUOTA` flag is set to `yes`. User shall set `LBM_FUOTA_ENABLE_MPA` to yes to use it.
420
421Additionally, provide the following compilation fields:
422
423- `FUOTA_MAXIMUM_NB_OF_FRAGMENTS`
424- `FUOTA_MAXIMUM_SIZE_OF_FRAGMENTS`
425- `FUOTA_MAXIMUM_FRAG_REDUNDANCY`
426
427Class B, Class C, multicast, and the previously mentioned packages are automatically built by activating this compilation flag.
428
429#### Prerequisites before starting a FUOTA session
430
431Two essential functions must be implemented for the FUOTA service:
432
433- `smtc_modem_hal_context_store` for the `CONTEXT_FUOTA` parameter
434- `smtc_modem_hal_context_restore` function
435
436These functions ensure that the received firmware update file is stored in non-volatile memory during the FUOTA session.
437
438#### Starting a Class C FUOTA session
439
440To initiate a multicast session in Class C, no specific action is required; it is handled transparently based on fuota server requests.
441If your Network server does not support the network Device Time Request cmd, activate the clk sync service (refer to the specific chapter on this service).
442
443#### End of Class C FUOTA session
444
445The implemented service only takes care of the transfer/reconstruction of the file and its storage in non-volatile memory. Everything related to the implementation of the new firmware itself (reboot, dual bank, etc.) is not implemented in this service and is left to the implementation of the end user.
446
447Once the session is completed, the user receives an event: `SMTC_MODEM_EVENT_LORAWAN_FUOTA_DONE` with the status "true" if the transfer is completed without error.
448
449The FUOTA service manages the transfer and reconstruction of the file, storing it in non-volatile memory.
450Implementation of the new firmware (reboot, dual bank, etc.) is not part of this service and is left to the end user.
451After completion, the user receives an event `SMTC_MODEM_EVENT_LORAWAN_FUOTA_DONE` with a `true` status if the transfer is completed without errors.
452
453#### Remark
454
455The fragmentation session for FUOTA may end, but not the Class C multicast session. The latter remains active until the session timeout. The user can end the session when they receive the `SMTC_MODEM_EVENT_LORAWAN_FUOTA_DONE` event. Alternatively, they can let the multicast session continue until the timeout, receiving an event `SMTC_MODEM_EVENT_NO_MORE_MULTICAST_SESSION_CLASS_C`. At the session start, they will receive an event `SMTC_MODEM_EVENT_NEW_MULTICAST_SESSION_CLASS_C` with the associated group_id present in the status.
456
457#### Special case
458
459When all Class C multicast sessions are completed, the stack remains in Class C Unicast. The user must switch back to Class A if desired (on the event `SMTC_MODEM_EVENT_NO_MORE_MULTICAST_SESSION_CLASS_C`).
460
461#### To start a Class B multicast FUOTA session
462
463The process is similar to that described for Class C with the exception that Class B activation process will generate some dedicated events (see Class B section for details).
464
465In normal operation, the user should receive the following events successively:
466
467- `SMTC_MODEM_EVENT_NEW_MULTICAST_SESSION_CLASS_B`
468- `SMTC_MODEM_EVENT_LORAWAN_FUOTA_DONE`
469- `SMTC_MODEM_EVENT_NO_MORE_MULTICAST_SESSION_CLASS_B`
470
471### Stream service (LoRaCloud)
472
473The user can stream data, allowing LoRa Basics™ Modem to handle maximum transmission size limits.
474Before initiating a stream, the user must set several parameters using `smtc_modem_stream_init()`:
475
476- LoRaWAN FPort
477- Encryption mode
478- Redundancy ratio
479
480Once configured, the user can add data to the stream buffer using `smtc_modem_stream_add_data()`. It is recommended to check the free space in the buffer with `smtc_modem_stream_status()` before adding data.
481
482The event `SMTC_MODEM_EVENT_STREAM_DONE` is triggered when the last byte of the stream buffer is sent. This event is for informational purposes; there is no need to wait for it before adding data to the stream buffer.
483
484### Large File Upload service (LoRaCloud)
485
486Empower your application with the Large File Upload service in LoRa Basics Modem, allowing you to transmit files of up to 8180 bytes seamlessly, with the modem managing maximum transmission size limits.
487
488Before initiating a file upload, set the required parameters by invoking `smtc_modem_file_upload_init()`:
489
490- Application index
491- Encryption mode
492- File to be sent and its size
493- Delay between two fragment uploads
494
495Once configured, commence the transfer with `smtc_modem_file_upload_start()`. If needed, the transfer can be aborted using `smtc_modem_file_upload_reset()`.
496
497The event `SMTC_MODEM_EVENT_UPLOAD_DONE` is triggered when:
498
499- The LoRa Cloud Modem & Geolocation Services acknowledges the reception with a dedicated downlink message
500(status set to `SMTC_MODEM_EVENT_UPLOAD_DONE_SUCCESSFUL`)
501- No acknowledgment is received after the last upload (status set to `SMTC_MODEM_EVENT_UPLOAD_DONE_ABORTED`)
502
503### Device Management service (LoRaCloud)
504
505#### Periodic information report
506
507The device management service allows sending periodic information reports. Enable this service using `smtc_modem_dm_enable()`.
508
509Before initiating a periodic information report, set various parameters (order does not matter):
510
511- LoRaWAN FPort, with `smtc_modem_dm_set_fport()`
512- Fields to be reported, with `smtc_modem_dm_set_periodic_info_fields()`
513- (Optional) User data to be reported, with `smtc_modem_dm_set_user_data()` - useful only if `SMTC_MODEM_DM_FIELD_APP_STATUS` is part of the user_data parameter given to `smtc_modem_dm_set_periodic_info_fields()`
514- Interval between two periodic information reports, with `smtc_modem_dm_set_info_interval()`
515
516Request a device management information report, distinct from periodic reports, by calling `smtc_modem_dm_request_immediate_info_field()` where fields different from those set with `smtc_modem_dm_set_periodic_info_fields()` can be reported.
517
518#### Downlink requests
519
520The cloud service may send requests to the modem on the device management port. Four kinds of requests can be received:
521
522- **Reset request**: Requests a reset (a `SMTC_MODEM_EVENT_RESET` event will be triggered once the modem resets)
523- **Rejoin**: Asks the modem to leave and rejoin the network (a new `SMTC_MODEM_EVENT_JOINED` or `SMTC_MODEM_EVENT_JOINFAIL` will be triggered afterward)
524- **Mute**: ask the modem to mute itself permanently or during a specified number of days (a `SMTC_MODEM_EVENT_MUTE` event is triggered)
525- **SetConf**: Update device management configuration (a `SMTC_MODEM_EVENT_DM_SET_CONF` event is triggered, provided the field that was updated according to `smtc_modem_event_setconf_opcode_t` )
526
527### Almanac Update service (LoRaCloud)
528
529Choose to update the Lora-Edge transceiver almanac using the cloud with the autonomous Almanac Update service.
530Initiate the service with `smtc_modem_almanac_start()` and stop it anytime with `smtc_modem_almanac_stop()`.
531
532Until the update is finalized, the service exchanges data with the cloud with no delay.
533Once the almanac is fully updated, the service asks for updates once a day (value can be modified at compile time ALMANAC_PERIOD_S).
534
535### ALCSync service (LoRaCloud)
536
537Opt for LoRaCloud to perform automatic time synchronization instead of a dedicated Application Server using port 202.
538The LoRaWAN package used for that is LoRaWAN Application Layer Clock Synchronization V1.0.0.
539
540Utilize the `smtc_modem_dm_handle_alcsync()` function to force the modem to encapsulate ALCSync payload into cloud messages. The service's behavior remains unaltered, and `SMTC_MODEM_EVENT_ALCSYNC_TIME` event will be triggered in case of new time synchronization.
541
542### Store and Forward service
543
544Refer to [README.md](smtc_modem_core/modem_services/store_and_forward/README.md) for comprehensive information about the Store and Forward service.
545
546### Geolocation services
547
548Explore GNSS and Wi-Fi scan & send services in detail by referring to [README.md](smtc_modem_core/geolocation_services/README.md)
549
550## SX1272/SX1276 (experimental)
551
552This version of LoRa Basics Modem introduces experimental support for SX1272 and SX1276 radios.
553The provided driver is not fully aligned with the required architecture of LBM V4, as it performs radio access in an interrupt context (which is no longer done on other radios).
554Additionally, it requires the use of an additional low-power timer to handle some reception timeout, especially for GFSK reception.
555
556In the provided example on the STM32L4 MCU (under the lbm_examples folder), LPTIM2 is used with the disadvantage of preventing the use of STOP2 low power mode.
557
558## Relay
559
560**LoRa Basic Modem** proposes an implementation of the [LoRaWAN® Relay Specification TS011-1.0.1](https://resources.lora-alliance.org/technical-specifications/ts011-1-0-1-relay)
561
562This implementation provides the code for the relayed end-device referred as Relay Tx
563
564### Relay Tx
565
566To build the relay Tx feature you need to define "LBM_RELAY_TX_ENABLE=yes"
567
568This option will require an additional 500 bytes of RAM and 5.5 Kbytes of FLASH.
569
570### Known limitation for the Relay Tx
571
572- Relay specific cryptographic operations are not supported by Semtech’s hardware Crypto Engine (LR11xx platform), and therefore this implementation is only compatible with embedded software cryptographic operations.
573- SX128x and SX127x are not supported fir Relay Tx operation.
574- The Scan and Send feature (SEND_MODE_UPLINK used in SMTC_MODEM_WIFI_SEND_MODE) of the geolocation services can only be used when the Relay Tx device is joined.
575- In a Store and Forward context (device accruing scans when it is offline) with device being relayed, the first uplink may be missed if the Relay Rx is waiting for its network configuration from the LNS.
576- On this release, a single WOR channel is supported for US915 and AU915 regions.
577- If the Periodical uplink example is built with the RELAY_TX=yes and RELAY_RX=yes flags (that device is relayed device, but can be changed to a Relay Rx by network command), the modem will enable the RELAY_TX feature after a reset. However, if a command from the LNS to activate the RELAY_RX feature (0X40 RELAY CONFIG) is received, the device will unexpectedly open an additional RxR window, without compromising functionality.
578
579### Relay Rx
580
581To build the relay Rx feature you need to define "LBM_RELAY_RX_ENABLE=yes"
582
583This option will require an additional 2.5 kbytes of RAM and 10 kbytes of FLASH.
584
585On a hardware note, it is strongly recommended to use a 32 MHz TCXO in a Relay Rx to respect the maximum frequency offset budget between the end-device and the relay itself.
586
587### Known limitation for the Relay Rx
588
589- This implementation is only compatible with embedded software cryptographic operations. (see above “Relay Tx”).
590- SX128x and SX127x are not supported
591- Due to specification limitation, JoinAccept cannot be forwarded to end-device if Rx1 delay is greater than 12s with SF12BW125, Rx1 and RxR windows will overlap
592- If the CAD periodicity is set to 250ms or less, it is no longer possible to increase it without resetting the Relay Rx.
593- The reduction of a device bucket size on the go, will not be effective before the previous allocation has been used.
594- On this release, a single WOR channel is supported for US915 and AU915 regions.
595- If the Periodical uplink example is built with the RELAY_TX=yes and RELAY_RX=yes flags (that device is relayed device, but can be changed to a Relay Rx by network command) , the modem will enable the RELAY_TX feature after a reset. However, if a command from the LNS to activate the RELAY_RX feature (0X40 RELAY CONFIG) is received, the the device will unexpectedly open an additional RxR window, without compromising functionality.
596
597## LoRa Basic Modem known limitations
598
599- [test-mode] The device will panic and reset if a bandwidth that is not supported by the selected radio chip is chosen. The choice of bandwidth is dependent on the radio used. This will not happen for the LoRaWAN bandwidths 125kHz and 500kHz.
600- [test-mode] In test mode, CSMA can’t be used for non LoRaWAN bandwidths lower than 125 kHz.
601- [charge] Values returned by `smtc_modem_get_charge()` for regions CN470 and CN470_RP1 are not accurate.
602- [charge] Values returned by `smtc_modem_get_charge()` for sx127x radios are not accurate.
603- [modem-status] The joining bit status is exclusively set during the LoRaWAN join transaction (i.e., Tx/Rx1/Rx2) and remains unset between join attempts.
604- [file upload] DAS may encounter difficulties reconstructing small files (less than 13 bytes) when the modem operates in the US915 region and utilizes DR0 data rate.
605- On fixed channel plan regions (ex:US915) if LBT is enabled and a channel is constantly jammed, the modem will use the 7 others channels then it will try to send on the jammed channel. As the modem cannot send on this channel, it will not remove this channel from the usable channel list and did not re-enable all other channels. Resulting in modem stuck.
606
607## Disclaimer
608
609This code is released under the Clear BSD license LICENSE.txt.
610Consistent with the terms of the Clear BSD license, it is not warrantied in anyway.
611