# lnlp/lmic-node architecture

> Architecture diagram of the GitHub repository lnlp/lmic-node, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lnlp/lmic-node
- Repository: https://github.com/lnlp/lmic-node

## Overview

##### Main Components

a) Node Hardware Layer:
- MCU (various supported boards)
- LoRa Radio Module (SX127x/RFM9x)
- Peripherals (LED, Display, Serial)

b) Software Components:
- LMIC Library Layer (MCCI or Classic)
- Board Support Layer (BSF)
- Application Layer
- Configuration Layer

c) External Systems:
- The Things Network (TTN)
- Gateway
- Application Server

**[Hardware Layer]**

- MCU
- Serial Interface
- I2C Interface (Display)
- SPI Interface (LoRa)
- GPIO (LED)

- LoRa Radio Module
- Antenna

**[Software Layer]**

- Board Support Files (BSF)
- Hardware Abstraction

- LMIC Library
- LoRaWAN Stack
- Radio Driver

- Application Logic
- Setup & Initialization
- Work Scheduler
- Payload Handling
- Status Management

- Configuration
- LoRaWAN Keys
- Regional Settings
- Board Settings

**[Network Layer]**

- LoRa Gateway

- The Things Network
- Network Server

- Application Server
- Payload Decoder

##### Key Interactions

- Data flow between hardware components (SPI, I2C, GPIO)
- LoRaWAN message flow (Uplink/Downlink)
- Configuration flow
- Initialization sequence

##### Important Details

a) Hardware Layer:
- Supported board types
- Interface types (SPI, I2C, Serial)
- Optional components (Display, LED)

b) Software Layer:
- LMIC library variants
- Board support abstraction
- Work scheduler mechanism
- Configuration management

c) Network Layer:
- LoRaWAN activation methods (OTAA/ABP)
- Payload formatting
- Network server interaction

##### Additional Elements

- Component types
- Optional vs. required components
- Supported board variations

##### Notes Section

Notes about:
- Configuration requirements
- Regional settings
- Memory constraints
- Hardware dependencies
- Initialization sequence

- The overall system architecture
- Component interactions
- Data flow paths
- Configuration requirements
- Hardware abstraction approach
- Deployment considerations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Hardware
        MCU[MCU]
        LoRa["LoRa Radio Module (SX127x/RFM9x)"]
        Interfaces["Interfaces"]
        
        MCU --- Interfaces
        Interfaces --> |SPI| LoRa
        Interfaces --> |I2C| Display[Display]
        Interfaces --> |GPIO| LED[LED]
        Interfaces --> |UART| Serial[Serial]
        
        LoRa --> Antenna[Antenna]
    end

    subgraph Software
        BSF["Board Support Layer (BSF)"]
        LMIC["LMIC Library"]
        AppLogic["Application Layer"]
        Config["Configuration Layer"]
        
        BSF --> LMIC
        LMIC --> AppLogic
        Config --> AppLogic
        
        subgraph BSF_Components
            BSF_TTGO["TTGO LoRa32"]
            BSF_Feather["Adafruit Feather"]
            BSF_Heltec["Heltec WiFi LoRa"]
        end
        
        BSF --- BSF_Components
        
        subgraph LMIC_Components
            LoRaWAN_Stack["LoRaWAN Stack"]
            Radio_Driver["Radio Driver"]
        end
        
        LMIC --- LMIC_Components
        
        subgraph App_Components
            Setup["Setup & Initialization"]
            Scheduler["Work Scheduler"]
            Payload["Payload Handling"]
            Status["Status Management"]
        end
        
        AppLogic --- App_Components
        
        subgraph Config_Components
            Keys["LoRaWAN Keys"]
            Regional["Regional Settings"]
            BoardSettings["Board Settings"]
        end
        
        Config --- Config_Components
    end

    subgraph Network
        Gateway["LoRa Gateway"]
        TTN["The Things Network"]
        AppServer["Application Server"]
        
        Gateway --> TTN
        TTN --> AppServer
    end

    MCU <--> BSF
    LoRa <--> Radio_Driver
    AppLogic --> Gateway

    %% Click events for component mapping
    click BSF "https://github.com/lnlp/LMIC-node/tree/main/src/boards/"
    click BSF_TTGO "https://github.com/lnlp/LMIC-node/blob/main/src/boards/bsf_ttgo_lora32_v2.h"
    click BSF_Feather "https://github.com/lnlp/LMIC-node/blob/main/src/boards/bsf_adafruit_feather_m0_lora.h"
    click BSF_Heltec "https://github.com/lnlp/LMIC-node/blob/main/src/boards/bsf_heltec_wifi_lora_32.h"
    click AppLogic "https://github.com/lnlp/LMIC-node/blob/main/src/LMIC-node.cpp"
    click Config "https://github.com/lnlp/LMIC-node/blob/main/keyfiles/lorawan-keys_example.h"
    click Payload "https://github.com/lnlp/LMIC-node/blob/main/payload-formatters/lmic-node-uplink-formatters.js"

    classDef hardware fill:#e6e6e6,stroke:#333
    classDef software fill:#b3d9ff,stroke:#333
    classDef network fill:#99ff99,stroke:#333
    classDef interface fill:#ffe6cc,stroke:#333

    class MCU,LoRa,Display,LED,Serial,Antenna hardware
    class BSF,LMIC,AppLogic,Config,BSF_Components,LMIC_Components,App_Components,Config_Components software
    class Gateway,TTN,AppServer network
    class Interfaces interface
```
