esp-idf-sx126x Driver

repository·main·Indexed 40 days ago

https://github.com/nopnop2002/esp-idf-sx126x

A low-power, long-range transceiver driver for SX1262, SX1268, and LLCC68 chips ported for the ESP-IDF framework. Includes support for LoRa modulation, interrupt configuration via SetDioIrqParams, and various gateway examples including HTTP, HTTPS, and MQTT implementations for ESP32 series microcontrollers.

Tokens
11K
Snippets
28
Records
79
Agent score
100%

What's inside esp-idf-sx126x

  1. Overview of the UDP-SOCKET Example

    main

    The UDP-SOCKET example implements a LoRa and UDP-SOCKET gateway application using an ESP32 and an SX126x transceiver. It acts as a bridge between LoRa wireless communication and UDP/IP network communication.

    There are two primary modes of operation:

    1. UDP to LoRa: The ESP32 acts as a UDP Server, receiving data from a UDP Client over WiFi and forwarding it to the SX126x via SPI to be transmitted over LoRa.
    2. LoRa to UDP: The ESP32 acts as a UDP Client, receiving data from the SX126x via SPI and forwarding it over WiFi to a UDP Server.
  2. Overview of the TCP-SOCKET Example

    main

    The TCP-SOCKET example implements a LoRa and TCP-SOCKET gateway application using an ESP32 and an SX126x transceiver. It allows for bidirectional communication between a TCP network (via WiFi) and a LoRa network (via SPI).

    There are two primary modes of operation:

    1. TCP to LoRa: The ESP32 acts as a TCP Server. It receives data from a TCP Client over WiFi and forwards it to the SX126x to be sent via LoRa.
    2. LoRa to TCP: The ESP32 acts as a TCP Client. It receives data from the SX126x via LoRa and forwards it to a TCP Server over WiFi.
  3. Overview of the USB Serial Device Gateway

    main

    This project implements a LoRa and USB Serial Device gateway application using the ESP32 and the TinyUSB stack. It allows an ESP32 to act as a bridge between a USB Serial Host (like a PC running terminal software or a Python script) and an SX126x LoRa transceiver via SPI.

    Data Flow Models:

    1. USB to LoRa: Data received from the USB Serial Host is sent to the LoRa transceiver. This is useful for sending commands or data from a PC to LoRa nodes.
    2. LoRa to USB: Data received from the LoRa transceiver is sent to the USB Serial Host. This is useful for monitoring LoRa node transmissions on a PC.
  4. Implement a LoRa and VCP Gateway with ESP32-S2/S3

    main

    This project implements a gateway application that bridges LoRa communication with a Virtual Com Port (VCP) using an ESP32 acting as a USB host. This allows communication between a LoRa transceiver (SX126x) and a VCP device (like an Arduino Uno or Mega) via a USB connection.

    Hardware Requirements

    • ESP32-S2 or ESP32-S3: Required because these chips have the necessary USB host capabilities.
    • SX126x LoRa Transceiver: Connected to the ESP32 via SPI.
    • VCP Device: An Arduino Uno, Arduino Mega, or similar device with a UART-to-USB conversion chip.
    • USB Type-A Female Connector: Used to connect the ESP32 to the VCP device.

    Supported USB Chips

    The project relies on specific ESP-IDF components for USB host support. Only the following UART-USB converter chips are supported:

    • ch34x
    • cp210x
    • ftdi
  5. Use the HTTP Example as a LoRa/HTTP Gateway

    main

    The HTTP Example allows an ESP32 with an SX126x transceiver to act as a gateway between LoRa wireless communication and HTTP network communication. It supports two primary modes:

    1. HTTP to LoRa (ESP32 as HTTP Server): The ESP32 hosts a web server. When it receives an HTTP request, it forwards the data via LoRa to a remote SX126x node.
    2. LoRa to HTTP (ESP32 as HTTP Client): The ESP32 listens for LoRa packets. When a packet is received, the ESP32 acts as an HTTP client and sends the data to a remote HTTP server.
  6. Use the BLE Example as a LoRa and BLE Gateway

    main

    The nimble example implements a gateway between LoRa and Bluetooth Low Energy (BLE). It uses the ESP-NimBLE host stack, which allows for concurrent connections (multiple smartphones connected simultaneously), unlike the ESP-Bluedroid stack.

    There are two primary modes of operation:

    1. BLE to LoRa: Data received via BLE from a smartphone is forwarded to the SX126x via SPI and transmitted over LoRa.
    2. LoRa to BLE: Data received via LoRa is forwarded via SPI to the ESP32 and transmitted to a smartphone via BLE.
  7. Concurrent BLE connections with ESP-NimBLE

    main
    Because this project uses the ESP-NimBLE host stack, it supports concurrent connections. This allows multiple smartphones to connect to the ESP32 gateway simultaneously. The maximum number of simultaneous connections is defined within the source code configuration.
  8. Configure SX1262/SX1268 transceiver options

    main

    When using SX1262 or SX1268 modules, you may need to adjust settings based on your specific hardware schematic.

    TCXO (Temperature-Compensated Crystal Oscillator)

    • If using a TCXO, the XTB pin is not connected.
    • The 6th pin (DIO3) of the SX1262/SX1268 can be used to power the TCXO.
    • Note: Ra-01S and Ra-01SH modules do not use TCXO.

    Power Supply Modes

    • LDO Mode: Only LDO is used in all modes. (Used by Ra-01S / Ra-01SH).
    • DC_DC + LDO Mode: DC_DC and LDO are used for STBY_XOSC, FS, RX, and TX modes.

    RF-Switching

    • Generally, use DIO2 to switch the RF-Switch.
    • Ra-01S / Ra-01SH: These use an integrated SC70-6 load switch controlled via DIO2:
      • DIO2 = 1, CTRL = 0 $\rightarrow$ Switch to Tx Mode.
      • DIO2 = 0, CTRL = 1 $\rightarrow$ Switch to Rx Mode.

    Warning: The default library settings are for Ra-01S / Ra-01SH. If using other modules, you must configure these options via menuconfig to match your hardware.

  9. Configure Radio Direction (MQTT to LoRa vs LoRa to MQTT)

    main

    You must select the wireless communication direction in the Radio Setting configuration:

    1. MQTT to LoRa: The ESP32 subscribes to an MQTT topic and forwards the payload to the SX126x via SPI to be sent over LoRa. Use this to control LoRa nodes from an MQTT client.
    2. LoRa to MQTT: The ESP32 receives LoRa packets via the SX126x and publishes them to an MQTT topic. Use this to bridge LoRa sensor data to an MQTT broker.
    # Example: Testing MQTT to LoRa using mosquitto_pub
    mosquitto_pub -h broker.emqx.io -p 1883 -t "/topic/lora/test" -m "test"
    
    # Example: Testing LoRa to MQTT using mosquitto_sub
    mosquitto_sub -h broker.emqx.io -p 1883 -t "/topic/lora/test"
  10. Configure VCP to LoRa and LoRa to VCP modes

    main

    The gateway can operate in two primary directions:

    VCP to LoRa (Downlink/Commanding)

    In this mode, the ESP32 receives data from the VCP device (via USB) and forwards it to the LoRa network (via SPI/SX126x). Data Flow: VCP Device (USB) -> ESP32 -> SX126x (LoRa)

    LoRa to VCP (Uplink/Reporting)

    In this mode, the ESP32 receives data from the LoRa network and forwards it to the VCP device. Data Flow: SX126x (LoRa) -> ESP32 -> VCP Device (USB)

  11. Understand LLCC68 compatibility and limitations

    main

    The LLCC68 chip is compatible with SX1262/SX1268 but has different Spreading Factor (SF) and Bandwidth (BW) capabilities.

    Spreading Factor (SF) and Bandwidth (BW) Comparison

    FeatureSX1262/SX1268LLCC68
    Supported SFSF5 to SF12SF5 to SF11
    BW Range7.8 - 500 kHz125 - 500 kHz
    SF/BW ConstraintsFlexibleSF5-9 (125kHz), SF5-10 (250kHz), SF5-11 (500kHz)

    Note: When using LLCC68 modules other than Ra-01SC/01SCH, you must set options appropriately based on the datasheet.

  12. Understand the Web Form Example architecture

    main

    The Web Form Example demonstrates bidirectional communication between a web browser and a LoRa transceiver using an ESP32 as the bridge. It utilizes WebSockets for real-time communication between the browser and the ESP32, and SPI to communicate with the SX126x radio.

    There are two primary modes of operation:

    1. Web to LoRa: Data entered in the web form is sent via WebSocket to the ESP32, which then transmits it over LoRa via the SX126x. WebForm -> (WebSocket) -> ESP32 -> (SPI) -> SX126x -> (LoRa)

    2. LoRa to Web: Data received by the SX126x via LoRa is passed through the ESP32 via SPI and sent to the web browser via WebSocket for display. LoRa -> SX126x -> (SPI) -> ESP32 -> (WebSocket) -> WebForm