Skip to content

Kraffcloud/kraffcloud_lora_code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

📡 LoRa to WiFi Gateway (ESP32-S3 + SX1262)

This project implements an IoT Gateway node using a XIAO ESP32-S3 microcontroller. Its main function is to receive telemetry data from field sensors via LoRa (915 MHz), display the information locally on an OLED screen, and forward the formatted JSON data packet to a secure backend (NestJS) through a Cloudflare HTTPS tunnel.


🛠️ Required Hardware

  • Microcontroller: Seeed Studio XIAO ESP32-S3
  • LoRa Module: Wio SX1262
  • Display: OLED SSD1306 128x64 (I2C)

Pinout Connections

Component ESP32-S3 Pin
LoRa NSS 41
LoRa DIO1 39
LoRa NRST 42
LoRa BUSY 40
OLED SDA Default I2C
OLED SCL Default I2C

📦 Dependencies and Libraries

To compile this code in the Arduino IDE or PlatformIO, you need to install the following libraries:

  • RadioLib (SX1262 transceiver handling)
  • U8g2 (Graphic controller for the OLED display)
  • WiFi, HTTPClient, WiFiClientSecure (Native ESP32 core libraries)

⚙️ Quick Setup

Before flashing the code to the ESP32, you must configure the credentials at the top of the main file:

  1. WiFi Network:

    • const char* ssid = "YOUR_WIFI_SSID";
    • const char* password = "YOUR_WIFI_PASSWORD";
  2. Backend Connection (Cloudflare / NestJS): Make sure to enter the exact domain provided by the Cloudflare tunnel, without the trailing port.

  3. Authentication and Device:

    • const char* apiKey = "YOUR_SECRET_API_KEY";
    • const char* deviceUid = "YOUR_NAME_DEVICE";

🔄 Data Flow

1. LoRa Reception

The Gateway constantly listens on the 915.0 MHz frequency (Bandwidth: 125.0, Spreading Factor: 7). The sending node is expected to transmit a strict comma-separated String format:

Voltage,BatteryPercentage (Example: "3.7,85")

2. Local Interface (OLED)

Upon receiving a valid packet, the OLED screen updates to display:

  • The raw received data.
  • The signal strength (RSSI) in dBm.

3. HTTP Request (POST)

The code extracts the voltage and percentage, builds a JSON object, and sends it using WiFiClientSecure (with flexible SSL validation to support Cloudflare development tunnels).

JSON Payload structure sent to the server: { "deviceUid": "SENSOR_ID_01", "battery_v": 3.7, "battery_p": 85 } (The x-simulator-key header is included for backend authorization).


⚠️ Development Notes

  • SSL Certificates: Currently, client.setInsecure() is enabled. This is ideal for testing with Cloudflare. For a strict production environment with a custom domain, it is recommended to provide the root CA certificate.
  • Sync Word: The LoRa system uses the sync word 0x12 (Private network). Ensure that the sending nodes share this exact Sync Word.

About

kraffcloud lora code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages