|
|
void | os_getArtEui (u1_t *buf) |
| | LMIC configuration functions (placeholders).
|
| void | onEvent (ev_t ev) |
| | LMIC/LoRaWAN event callback.
|
| void | initLoRa () |
| | Initializes the LMIC stack and configures LoRaWAN (ABP, US915).
|
| void | tareaLoRa (void *pvParameters) |
| | Task dedicated to sending data via LoRaWAN.
|
| void | tareaRunLoop (void *pvParameters) |
| | LMIC runloop task.
|
|
| static u1_t | NWKSKEY [16] |
| | ABP keys and device address (DEMO).
|
| const lmic_pinmap | lmic_pins |
| | Pin map for the SX127x radio of the TTGO LoRa32.
|
Overview
This module manages LoRaWAN transmission using LMIC:
- Initializes the LMIC stack and device HAL (TTGO LORA 32 V2.1).
- Manages frame construction and transmission from queueFragmentos.
- Monitors LMIC events (EV_TXCOMPLETE, join, duty cycle) and synchronizes via semaforoEnvioCompleto.
Structure and components
- Configuration
- Network parameters (OTAA/ABP), channels and region.
- HAL and SPI/Radio pinmap.
- Transport to LMIC
- Fragment: binary block ready for transmission (produced by aggregation in Data Format).
- Tasks/Callbacks
Main API
- Input
- Output
- Functions/Callbacks
- LMIC_setTxData2(port, data, len, confirmed).
- onEvent(ev) state and error handling.
- tareaLoRa, tareaRunLoop.
- Configuration
- LMIC_reset(), LMIC_setTxData2(), LMIC_setClockError(), channel/region setup.
Usage
Flow summary:
1) LoRaWAN startup
- Initializes HAL/SPI/Radio and resets LMIC (LMIC_reset()).
- Configures OTAA/ABP, region and channels.
- Creates tareaRunLoop and tareaLoRa.
2) Data transmission
- tareaLoRa blocks on queueFragmentos, builds frame and calls LMIC_setTxData2.
- Avoids collisions by checking LMIC.opmode & OP_TXRXPEND.
3) LMIC events
- onEvent(EV_TXCOMPLETE): releases semaforoEnvioCompleto and optionally schedules next transmission.
- onEvent(EV_JOINED/EV_JOINING): controls join state.
- Handles duty cycle and retries according to region.
Best practices (LoRaWAN)
- Check OP_TXRXPEND before sending to avoid breaking duty cycle.
- Use consistent application ports and payload sizes within regional limits.
- Minimize work inside onEvent; delegate to tasks when possible.
- Adjust LMIC_setClockError() if crystal has notable deviation.
- Ensure join retry with backoff and log states for diagnostics.
◆ initLoRa()
Initializes the LMIC stack and configures LoRaWAN (ABP, US915).
- Calls os_init() and LMIC_reset().
- Adjusts LMIC_setClockError() (1%) for crystal tolerance.
- Configures ABP session with LMIC_setSession() and US915 region (LMIC_selectSubBand(7)).
- Disables ADR and LinkCheck to simplify the flow.
- Note
- Adjust sub-banda, DR y potencia según gateway/región.
◆ onEvent()
LMIC/LoRaWAN event callback.
Handles events from the LMIC stack and synchronizes the transmission flow using semaforoEnvioCompleto.
- EV_TXCOMPLETE: indicates end of TX and releases the semaphore.
- TXRX_ACK: reports if an ACK was received from the network.
- Parameters
-
| ev | Event reported by LMIC. |
◆ tareaLoRa()
| void tareaLoRa |
( |
void * | pvParameters | ) |
|
Task dedicated to sending data via LoRaWAN.
- Waits for fragments in queueFragmentos.
- Takes semaforoEnvioCompleto to serialize transmissions.
- Calls LMIC_setTxData2() with application port 1 and without confirmation (confirmed=0).
◆ tareaRunLoop()
| void tareaRunLoop |
( |
void * | pvParameters | ) |
|
LMIC runloop task.
Executes os_runloop_once() in a loop to process timers and internal LMIC events.
◆ lmic_pins
| const lmic_pinmap lmic_pins |
Initial value:= {.nss = 18,
.rxtx = LMIC_UNUSED_PIN,
.rst = LMIC_UNUSED_PIN,
.dio = {26, 33, 32}}
Pin map for the SX127x radio of the TTGO LoRa32.
Defines NSS, DIO0-DIO2 and pins not used by LMIC.
◆ NWKSKEY
Initial value:= {
0xC2, 0x5B, 0x0A, 0x78, 0xA8, 0x0A, 0x63, 0x1D,
0x86, 0xC8, 0x1B, 0xA3, 0x3A, 0x9E, 0x36, 0xEF
}
ABP keys and device address (DEMO).
- Warning
- Keys in plaintext, replace in production.