ESP32 LoRa Sensor Data Monitoring on Web Server using RYLR998

ESP32 LoRa Sensor Data Monitoring on Web Server using RYLR998 ESP32 LoRa Sensor Data Monitoring on Web Server using RYLR998

Have you ever tried monitoring the temperature and humidity in a backyard greenhouse, an outbuilding used for mushroom farming or hydroponics, or inside a 3D printer enclosure in a detached workshop—only to realize your home Wi-Fi signal dies halfway across the yard?

Standard Wi-Fi is fantastic for high-bandwidth tasks, but it has poor wall penetration and very limited outdoor range. If you want to monitor environmental conditions hundreds of meters (or even kilometers) away without paying for cellular data plans or trenching Ethernet cables across your property, LoRa (Long Range) radio technology is the ultimate solution.

In this tutorial, we are going to build a complete ESP32 LoRa Sensor Data Monitoring System with a Local Web Server. We will use two ultra-compact ESP32-C3 SuperMini boards, two Reyax RYLR998 LoRa transceiver modules, a DHT22 sensor, and a Breadboard Power Supply Module to reliably handle high-power radio transmissions.

One node will act as a remote Transmitter (reading temperature and humidity and broadcasting it over LoRa), and the second node will sit inside your house acting as a Receiver & Wi-Fi Web Server. It will catch the long-range radio packets and display live, auto-updating readings on a sleek, mobile-friendly web dashboard that you can open from any phone or laptop on your home network.

Related Project: LoRa Temperature & Humidity Monitor Using ESP32, RYLR998, and SHT31 on Oled display


Why Use LoRa + ESP32-C3 for Environmental Monitoring?

Whether you are managing delicate humidity levels for hydroponics and mushroom cultivation, keeping an eye on agricultural storage sheds, or monitoring ambient temperatures inside a 3D printer enclosure located in a separate garage, environmental stability is everything.

Here is why this specific hardware combination beats traditional Wi-Fi or Bluetooth sensors:

  • Massive Range: While Wi-Fi struggles past 30–50 meters through walls, the RYLR998 LoRa module operates on sub-GHz frequencies (868 MHz / 915 MHz), easily punching through concrete, foliage, and metal to reach 1 km to 10+ km depending on line-of-sight.
  • No Wi-Fi Needed at the Sensor Site: Only the indoor receiver needs access to your home Wi-Fi router. The remote sensor node operates purely over radio waves.
  • Ultra-Compact & 3.3V Logic Native: The ESP32-C3 SuperMini is roughly the size of a thumb, costs just a few dollars, and natively runs at 3.3V logic—matching the RYLR998 UART pins without requiring voltage dividers or logic level shifters.

System Architecture: How the Project Works

Because smartphones and laptops cannot talk directly to a LoRa radio signal, we use a LoRa-to-Wi-Fi Gateway architecture:

[ Remote Site (No Wi-Fi) ]                    [ Home / Office (Wi-Fi Zone) ]
+------------------------+                    +----------------------------+
| Breadboard Power Supply|                    | RYLR998 LoRa (Address: 2)  |
|   ├── 3.3V -> RYLR998  |   LoRa RF Signal   |             ↓              |
|   └── 5V   -> ESP32-C3 | ================>  | ESP32-C3 SuperMini #2      |
|                 ↑      |  (868 / 915 MHz)   |      (Hosts Web Server)    |
|            DHT22 Sensor|                    +----------------------------+
+------------------------+                                  ↓
                                                   (Home Wi-Fi Router)
                                                            ↓
                                              [ Smartphone / PC Browser ]
  1. Node 1 (The Transmitter): Placed in your greenhouse, mushroom grow room, or 3D printer enclosure. Every 5 seconds, the ESP32-C3 reads temperature and humidity from the DHT22, packages the values into a compact comma-separated string (e.g., 26.4,65.2,101), and sends it via UART AT+SEND command to the RYLR998 LoRa module.
  2. LoRa Radio Link: Powered by a dedicated 3.3V breadboard power rail, the transmitter’s RYLR998 broadcasts the packet at full +22 dBm output power to Address 2.
  3. Node 2 (The Receiver & Web Server): Placed inside your house within range of your Wi-Fi router. Its RYLR998 catches the radio packet—along with the RSSI (Signal Strength) and SNR (Signal-to-Noise Ratio)—and passes it to the second ESP32-C3.
  4. Live Web Dashboard: The receiver ESP32-C3 hosts a responsive web server. When you type its IP address into your browser, you get a clean dashboard showing real-time Temperature, Humidity, Signal Strength, and Time Since Last Update without having to refresh the page.

Requirements

Hardware Requirements:

  • 2 × RYLR998 LoRa module (one for the transmitter, one for the receiver)
  • 2 × ESP32-C3 SuperMini board
  • 1 × DHT22 (AM2302) temperature and humidity sensor
  • 1 × MB102 breadboard power supply module (for the transmitter side)
  • 1 × Breadboard and jumper wires(optional)
  • 1 × 6.5V to 12V DC adapter (or a USB cable) to feed the power supply module

Software Requirements:

  • Arduino IDE with the ESP32 board package installed
  • DHT sensor library by Adafruit
  • Adafruit Unified Sensor library

The web server part uses the WiFi.h and WebServer.h libraries that already come with the ESP32 board package, so nothing extra to install there.


Understanding the Hardware & Power Architecture

ESP32-C3 SuperMini

The ESP32-C3 SuperMini is a tiny development board powered by a single-core 32-bit RISC-V chip running up to 160 MHz. Despite its tiny footprint (22.5 × 18 mm), it packs 4MB Flash, 400KB SRAM, 2.4GHz Wi-Fi, Bluetooth 5 (LE), and dedicated hardware UART pins (GPIO 20 for RX and GPIO 21 for TX), making it a clean pairing for serial LoRa modules.

Reyax RYLR998 LoRa Module

Unlike raw SX1276/SX1278 SPI modules that require complex wiring (MISO, MOSI, SCK, NSS, RST, DIO0) and external libraries, the Reyax RYLR998 integrates a Semtech LoRa engine with an onboard STM32 microcontroller. You communicate with it using simple Serial AT commands over just two data wires (TXD and RXD).

  • Operating Voltage: 3.0V – 3.6V (Strictly 3.3V! Never connect VDD to 5V!)
  • Frequency Range: 868 MHz (Europe/India) or 915 MHz (North America)
  • Receive Current: ~17.5 mA
  • Peak Transmit Current: Up to 140 mA at +22 dBm maximum output power

Reyax RYLR998 datasheet: here

DHT22 Temperature & Humidity Sensor

We chose the DHT22 over the cheaper DHT11 because applications like mushroom fruiting chambers, hydroponics, and filament dry boxes require accuracy across wide ranges.

  • Humidity Range: 0–100% RH (±2% accuracy)
  • Temperature Range: -40°C to +80°C (±0.5°C accuracy)
  • Sampling Rate: 0.5 Hz (one reading every 2 seconds)

Why We Use a Breadboard Power Supply on the Transmitter

When building long-range LoRa projects, power starvation is the #1 reason makers run into mysterious resets or failed transmissions.

While the ESP32-C3 SuperMini’s tiny onboard 3.3V regulator can easily supply enough current when the RYLR998 is only listening on the Receiver side (~17.5 mA), the Transmitter side is a completely different story. When the RYLR998 fires a packet at maximum transmit power (+22 dBm), it draws sharp current spikes of up to 140 mA.

If you power the RYLR998 (or extra accessories like a relay module to switch an exhaust fan or humidifier) directly from the ESP32-C3’s onboard regulator, that 140 mA transmit burst can cause a voltage drop (brownout), crashing the ESP32 or corrupting the radio transmission.

By adding an MB102 Breadboard Power Supply Module on the Transmitter side, we split the load across two independent regulated rails:

  • 3.3V Rail (from MB102): Directly powers the RYLR998 LoRa module and the DHT22 sensor, delivering clean, dedicated current for the 140 mA RF transmission bursts.
  • 5V Rail (from MB102): Powers the ESP32-C3 SuperMini (via its 5V pin) and any 5V relay modules you may want to attach later.
  • Common Ground (GND): Connecting all GND pins together ensures clean 3.3V UART logic communication between the ESP32 and the RYLR998.

Interfacing ESP32-C3 with RYLR998 and DHT22

The wiring is the same idea on both sides. The only differences are that the transmitter has the DHT22 and the breadboard power supply, and the receiver is powered from USB.

Power setup on the transmitter side

  1. Plug the MB102 module on the breadboard power rails.
  2. Set the jumper of the left rail to 5V and the jumper of the right rail to 3.3V.
  3. Connect the 5V rail to the 5V pin of the ESP32-C3 SuperMini.
  4. Connect the 3V rail to the VDD of the RYLR998 and to VCC of the DHT22.
  5. Join the GND of both rails together with the GND of the ESP32-C3, RYLR998 and DHT22. A common ground is a must.
  6. Place the 100 µF capacitor across the 3.3V and GND rail near the LoRa module. LoRa transmission draws short current spikes and the capacitor keeps the supply steady.

One warning here: do not plug the USB cable into the ESP32-C3 while it is also powered from the 5V pin. Upload your code first, then unplug the USB and switch on the breadboard supply.

Transmitter connections

Interfacing ESP32-C3 with RYLR998 and DHT22 on transmitter side

RYLR998 pin ESP32-C3 SuperMini
VDD 3.3V rail of MB102
GND GND
TXD GPIO20 (RX)
RXD GPIO21 (TX)
NRST not connected

 

DHT22 pin ESP32-c3 supermini
VCC 3.3V pin
DATA GPIO7
GND GND

Remember that serial lines cross over: the TX of the module goes to the RX of the ESP32 and the RX of the module goes to the TX of the ESP32.

Receiver connections

Interfacing ESP32-C3 with RYLR998 on receiver side

RYLR998 pin ESP32-C3 SuperMini
VDD 3V3
GND GND
TXD GPIO20 (RX)
RXD GPIO21 (TX)

The receiver does not need the DHT22 or the power supply module. Power it with its USB-C cable from a charger or your computer.


Build Custom PCBs & 3D-Printed Enclosures for Your ESP32 & RYLR998 LoRa Project

Monitor remote sensor data over long distances and visualize it on a live web server using your ESP32 and RYLR998 LoRa module. PCBWay’s integrated manufacturing services help you transform your prototype into a robust, field-ready monitoring system—perfect for agriculture, industrial IoT, or environmental sensing.

Custom PCB Manufacturing for Stable LoRa Communication:
PCBWay manufactures high-quality custom PCBs that consolidate your ESP32, RYLR998 LoRa transceiver, sensor interfaces, and power management onto a single compact board. Their PCBs feature clean SPI traces with proper impedance control for reliable communication with the RYLR998 module, dedicated power planes to handle transmission current bursts, and RF-optimized layouts to maximize signal range and minimize interference. Choose professional SMT assembly to receive a fully populated, tested board ready for web server deployment.

Weatherproof 3D-Printed Enclosures for Outdoor Deployment:
Design and order a custom enclosure through PCBWay’s advanced 3D printing service. Create a rugged, weather-resistant housing using UV-stabilized ASA or waterproof PETG, featuring an external antenna mounting point for optimal LoRa signal reception, ventilation for sensor accuracy, and cable glands for waterproof wiring. Add secure mounting flanges for pole or wall installation and internal PCB bosses—all printed with precision for long-term outdoor reliability.

Why PCBWay Delivers Professional Results:

  • Outdoor Durability: Custom enclosures protect electronics from harsh environmental conditions
  • Seamless Integration: Perfect PCB-to-enclosure fit from one trusted source
  • Complete Solution: From prototype to field-deployed monitoring system

Build Your LoRa Monitoring System Today:
Upload your PCB design and enclosure model for instant quotes, DFM feedback, and professional manufacturing only at PCBWAY.COM


Preparing the Arduino IDE to Upload the Code

Before uploading, select the board ESP32C3 Dev Module in the Arduino IDE. The SuperMini uses the built-in USB port for serial, so set USB CDC On Boot: Enabled, otherwise you will not see anything in the Serial Monitor. We use Serial1 on GPIO20 and GPIO21 for the LoRa module, so these pins do not conflict with the USB serial.

Install Required Libraries: Open Sketch > Include Library > Manage Libraries and install:

    • DHT sensor library by Adafruit : here
    • Adafruit Unified Sensor by Adafruit : here

Source Code: LoRa Transmitter Node

Upload the following code to ESP32-C3 SuperMini #1 (the remote sensor node).

(Note: Change LORA_BAND to 915000000 if you are in North America, or keep 868000000 for India/Europe).

/*
 * Project: Circuitschools ESP32-C3 LoRa Environmental Monitor - TRANSMITTER NODE
 * Hardware: ESP32-C3 SuperMini + Reyax RYLR998 + DHT22 + MB102 Power Supply
 */

#include <Arduino.h>
#include <DHT.h>

// --- Pin Definitions ---
#define DHTPIN 7          // DHT22 Data pin connected to GPIO 4
#define DHTTYPE DHT22     // DHT 22 (AM2302)
#define RXD1 20           // ESP32-C3 RX connected to RYLR998 TXD
#define TXD1 21           // ESP32-C3 TX connected to RYLR998 RXD
#define LED_PIN 8         // Onboard Blue LED on ESP32-C3 SuperMini (Active LOW)

// --- LoRa Configuration ---
#define LORA_BAND "868000000"   // Use 868000000 (EU/IN) or 915000000 (US)
#define LORA_NETWORK_ID "18"    // Must match on both modules (3 to 15, or 18)
#define LORA_MY_ADDRESS "1"     // Transmitter Address = 1
#define LORA_DEST_ADDRESS "2"   // Receiver Address = 2

DHT dht(DHTPIN, DHTTYPE);
HardwareSerial LoRaSerial(1); // Use Hardware UART1

unsigned long lastSendTime = 0;
const unsigned long sendInterval = 5000; // Send data every 5 seconds
uint32_t packetCounter = 0;

// Helper function to send AT commands to RYLR998 and print response
void sendLoRaCommand(String cmd, int waitTime = 500) {
  LoRaSerial.println(cmd);
  delay(waitTime);
  while (LoRaSerial.available()) {
    String response = LoRaSerial.readStringUntil('\n');
    Serial.println("[RYLR998] " + response);
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH); // Turn onboard LED off initially (Active LOW)

  delay(2000);
  Serial.println("--- Starting LoRa Transmitter Node ---");

  // Initialize DHT22 Sensor
  dht.begin();

  // Initialize Hardware Serial for RYLR998 (115200 default baud rate)
  LoRaSerial.begin(115200, SERIAL_8N1, RXD1, TXD1);
  delay(1000);

  // Configure RYLR998 Module automatically on boot
  Serial.println("Configuring RYLR998 LoRa Module...");
  sendLoRaCommand("AT");
  sendLoRaCommand("AT+BAND=" + String(LORA_BAND));
  sendLoRaCommand("AT+NETWORKID=" + String(LORA_NETWORK_ID));
  sendLoRaCommand("AT+ADDRESS=" + String(LORA_MY_ADDRESS));
  sendLoRaCommand("AT+CRFOP=22"); // Set maximum transmit power (+22 dBm)
  // Parameter: SF9, BW 125kHz (7), CR 4/5 (1), Preamble 12 -> Balanced range & speed
  sendLoRaCommand("AT+PARAMETER=9,7,1,12");
  Serial.println("LoRa Transmitter Ready!");
}

void loop() {
  if (millis() - lastSendTime >= sendInterval) {
    lastSendTime = millis();

    // Read humidity and temperature from DHT22
    float humidity = dht.readHumidity();
    float temperature = dht.readTemperature(); // Celsius

    // Check if reading failed
    if (isnan(humidity) || isnan(temperature)) {
      Serial.println("Error: Failed to read from DHT22 sensor!");
      return;
    }

    packetCounter++;

    // Format payload: "TEMP,HUM,PACKET_ID" -> e.g., "27.5,64.2,104"
    String payload = String(temperature, 1) + "," + String(humidity, 1) + "," + String(packetCounter);
    int payloadLength = payload.length();

    // Construct AT+SEND command: AT+SEND=<Dest_Addr>,<Length>,<Data>
    String atCommand = "AT+SEND=" + String(LORA_DEST_ADDRESS) + "," + String(payloadLength) + "," + payload;

    // Blink onboard LED briefly when transmitting
    digitalWrite(LED_PIN, LOW);
    Serial.println("Sending Packet: " + atCommand);
    sendLoRaCommand(atCommand, 300);
    digitalWrite(LED_PIN, HIGH);
  }
}

Source Code: LoRa Receiver Node

Now upload this code to ESP32-C3 SuperMini #2 (the indoor receiver). Before uploading, replace YOUR_WIFI_SSID and YOUR_WIFI_PASSWORD with your home Wi-Fi credentials.

No Need to Remember IP Addresses (mDNS Support):

Normally, your home router assigns a dynamic IP address (like 192.168.1.45) that can change whenever the router restarts. By adding the ESPmDNS library (MDNS.begin("lorasensor")), the ESP32 broadcasts its own local domain name. You can simply type http://lorasensor.local into your browser to open the live dashboard anytime!

How the Receiver Parses Data & Updates the Web Page:

When the RYLR998 receives a message, it outputs a string in this exact format:+RCV=1,12,27.5,64.2,15,-45,10

  • 1 = Sender Address
  • 12 = Payload Length
  • 27.5,64.2,15 = Our payload (Temp, Humidity, Packet #)
  • -45 = RSSI (Signal strength in dBm)
  • 10 = SNR (Signal-to-Noise Ratio)

Our code slices this string apart and serves a responsive HTML/CSS dashboard that fetches fresh JSON data in the background every 2 seconds without refreshing the browser page.

/*
 * Project: Circuitschools ESP32-C3 LoRa Data Monitoring on WEB SERVER
 * Hardware: ESP32-C3 SuperMini + Reyax RYLR998
 * Web Dashboard URL: http://lorasensor.local
 */

#include <Arduino.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WebServer.h>

// --- Wi-Fi Credentials ---
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

// --- mDNS Hostname (Access at http://lorasensor.local) ---
const char* mdnsHostname = "lorasensor";

// --- Pin Definitions ---
#define RXD1 20
#define TXD1 21
#define LED_PIN 8

// --- LoRa Configuration ---
#define LORA_BAND "868000000"   // Must match Transmitter (868000000 or 915000000)
#define LORA_NETWORK_ID "18"    // Must match Transmitter
#define LORA_MY_ADDRESS "2"     // Receiver Address = 2

HardwareSerial LoRaSerial(1);
WebServer server(80);

// Global Variables to hold latest sensor data
String latestTemp = "--";
String latestHum = "--";
String latestPacketID = "0";
String latestRSSI = "--";
String latestSNR = "--";
unsigned long lastReceivedMillis = 0;

void sendLoRaCommand(String cmd, int waitTime = 500) {
  LoRaSerial.println(cmd);
  delay(waitTime);
  while (LoRaSerial.available()) {
    Serial.println("[RYLR998] " + LoRaSerial.readStringUntil('\n'));
  }
}

// Parse incoming +RCV=<Address>,<Length>,<Temp>,<Hum>,<PktID>,<RSSI>,<SNR>
void parseLoRaMessage(String raw) {
  raw.trim();
  if (!raw.startsWith("+RCV=")) return;

  Serial.println("Raw LoRa Packet: " + raw);

  // Remove "+RCV="
  String data = raw.substring(5);

  // Find comma indices
  int c1 = data.indexOf(',');                 // After Address
  int c2 = data.indexOf(',', c1 + 1);         // After Length
  int c3 = data.indexOf(',', c2 + 1);         // After Temp
  int c4 = data.indexOf(',', c3 + 1);         // After Humidity
  int c5 = data.indexOf(',', c4 + 1);         // After PacketID
  int c6 = data.indexOf(',', c5 + 1);         // After RSSI

  if (c1 > 0 && c2 > 0 && c3 > 0 && c4 > 0 && c5 > 0 && c6 > 0) {
    latestTemp     = data.substring(c2 + 1, c3);
    latestHum      = data.substring(c3 + 1, c4);
    latestPacketID = data.substring(c4 + 1, c5);
    latestRSSI     = data.substring(c5 + 1, c6);
    latestSNR      = data.substring(c6 + 1);
    lastReceivedMillis = millis();

    Serial.printf("Parsed -> Temp: %s C | Hum: %s %% | Pkt: %s | RSSI: %s dBm\n",
                  latestTemp.c_str(), latestHum.c_str(), latestPacketID.c_str(), latestRSSI.c_str());
  }
}

// HTML Web Page stored in Flash (PROGMEM)
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>ESP32 LoRa Environmental Monitor</title>
  <style>
    :root { --bg: #0f172a; --card: #1e293b; --text: #f8fafc; --sub: #94a3b8; --accent: #38bdf8; }
    body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); margin: 0; padding: 20px; text-align: center; }
    h1 { font-size: 1.6rem; margin-bottom: 5px; color: var(--accent); }
    p.subtitle { color: var(--sub); margin-top: 0; font-size: 0.95rem; }
    .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; max-width: 750px; margin: 25px auto; }
    .card { background: var(--card); padding: 24px; border-radius: 16px; box-shadow: 0 8px 20px rgba(0,0,0,0.35); border: 1px solid rgba(255,255,255,0.06); }
    .label { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; color: var(--sub); }
    .value { font-size: 2.8rem; font-weight: 700; margin: 12px 0; }
    .temp-color { color: #fb923c; }
    .hum-color { color: #38bdf8; }
    .unit { font-size: 1.2rem; font-weight: 400; color: var(--sub); }
    .meta-bar { max-width: 750px; margin: 0 auto; background: var(--card); padding: 14px 20px; border-radius: 12px; display: flex; flex-wrap: wrap; justify-content: space-around; gap: 10px; font-size: 0.9rem; color: var(--sub); }
    .meta-item strong { color: var(--text); }
    .status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #22c55e; margin-right: 6px; }
  </style>
</head>
<body>
  <h1>ESP32 LoRa Telemetry Dashboard</h1>
  <p class="subtitle">Live at <strong>lorasensor.local</strong> | Long-Range RYLR998 Monitor</p>

  <div class="grid">
    <div class="card">
      <div class="label">Temperature</div>
      <div class="value temp-color"><span id="temp">--</span><span class="unit"> &deg;C</span></div>
      <div class="label" id="tempF">-- &deg;F</div>
    </div>
    <div class="card">
      <div class="label">Relative Humidity</div>
      <div class="value hum-color"><span id="hum">--</span><span class="unit"> %</span></div>
      <div class="label" id="comfort">Waiting for sensor...</div>
    </div>
  </div>

  <div class="meta-bar">
    <div class="meta-item"><span class="status-dot" id="dot"></span>Status: <strong id="age">Waiting...</strong></div>
    <div class="meta-item">RSSI: <strong id="rssi">--</strong> dBm</div>
    <div class="meta-item">SNR: <strong id="snr">--</strong> dB</div>
    <div class="meta-item">Packets: <strong id="pkt">0</strong></div>
  </div>

  <script>
    function fetchTelemetry() {
      fetch('/data')
        .then(response => response.json())
        .then(data => {
          document.getElementById('temp').innerText = data.temp;
          document.getElementById('hum').innerText = data.hum;
          document.getElementById('rssi').innerText = data.rssi;
          document.getElementById('snr').innerText = data.snr;
          document.getElementById('pkt').innerText = data.pkt;

          if (data.temp !== "--") {
            let f = (parseFloat(data.temp) * 9 / 5 + 32).toFixed(1);
            document.getElementById('tempF').innerHTML = f + " &deg;F";
          }
          if (data.hum !== "--") {
            let h = parseFloat(data.hum);
            let msg = h > 75 ? "High Humidity" : (h < 35 ? "Dry Environment" : "Optimal Range");
            document.getElementById('comfort').innerText = msg;
          }

          let sec = parseInt(data.age);
          let dot = document.getElementById('dot');
          if (data.pkt === "0") {
            document.getElementById('age').innerText = "No packets yet";
            dot.style.background = "#eab308";
          } else {
            document.getElementById('age').innerText = sec + "s ago";
            dot.style.background = sec > 15 ? "#ef4444" : "#22c55e";
          }
        })
        .catch(err => console.error(err));
    }
    setInterval(fetchTelemetry, 2000);
    fetchTelemetry();
  </script>
</body>
</html>
)rawliteral";

void handleRoot() {
  server.send(200, "text/html", index_html);
}

void handleData() {
  unsigned long ageSeconds = (lastReceivedMillis == 0) ? 0 : (millis() - lastReceivedMillis) / 1000;
  String json = "{";
  json += "\"temp\":\"" + latestTemp + "\",";
  json += "\"hum\":\"" + latestHum + "\",";
  json += "\"pkt\":\"" + latestPacketID + "\",";
  json += "\"rssi\":\"" + latestRSSI + "\",";
  json += "\"snr\":\"" + latestSNR + "\",";
  json += "\"age\":\"" + String(ageSeconds) + "\"";
  json += "}";
  server.send(200, "application/json", json);
}

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);

  delay(2000);
  Serial.println("--- Starting LoRa Receiver & Web Server ---");

  // Configure RYLR998
  LoRaSerial.begin(115200, SERIAL_8N1, RXD1, TXD1);
  delay(1000);
  sendLoRaCommand("AT");
  sendLoRaCommand("AT+BAND=" + String(LORA_BAND));
  sendLoRaCommand("AT+NETWORKID=" + String(LORA_NETWORK_ID));
  sendLoRaCommand("AT+ADDRESS=" + String(LORA_MY_ADDRESS));
  sendLoRaCommand("AT+PARAMETER=9,7,1,12");

  // Connect to Wi-Fi
  WiFi.mode(WIFI_STA);
  WiFi.setTxPower(WIFI_POWER_8_5dBm); // Prevents ESP32-C3 SuperMini antenna reflection issues
  WiFi.begin(ssid, password);
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nConnected to Wi-Fi!");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());

  // Initialize mDNS Responder (http://lorasensor.local)
  if (MDNS.begin(mdnsHostname)) {
    MDNS.addService("http", "tcp", 80); // Advertise HTTP web server service on port 80
    Serial.println("mDNS responder started! Open http://" + String(mdnsHostname) + ".local in your browser.");
  } else {
    Serial.println("Error setting up mDNS responder!");
  }

  // Start Web Server routes
  server.on("/", handleRoot);
  server.on("/data", handleData);
  server.begin();
  Serial.println("HTTP Web Server started!");
}

void loop() {
  server.handleClient();

  // Check if LoRa packet arrived
  if (LoRaSerial.available()) {
    digitalWrite(LED_PIN, LOW); // Blink LED on packet receive
    String incoming = LoRaSerial.readStringUntil('\n');
    parseLoRaMessage(incoming);
    digitalWrite(LED_PIN, HIGH);
  }
}

Testing the Web Server & Range Performance

  1. Turn on the MB102 Breadboard Power Supply on your Transmitter Node, and plug your indoor Receiver Node into any 5V USB power adapter (you don’t even need a computer attached!).
  2. Connect your laptop, iPhone, or Android device to the same home Wi-Fi network.
  3. Open your web browser and type http://lorasensor.local into the address bar. (If a browser tries to search Google instead of opening the local site, make sure you include http:// at the front).
  4. Within 5 seconds, the first LoRa packet will arrive! You will see the Temperature (in both °C and °F), Relative Humidity, RSSI, SNR, and Packet Counter update live on the dashboard.

ESP32 LoRa Sensor Data Monitoring output data on Web Server

Understanding Your RSSI Values:

  • -30 dBm to -70 dBm: Strong signal (same room or nearby building).
  • -71 dBm to -100 dBm: Good, reliable long-range signal through walls and trees.
  • -101 dBm to -120 dBm: Edge of range; consider increasing the Spreading Factor in AT+PARAMETER (e.g., AT+PARAMETER=11,7,1,12) for even deeper obstacle penetration.

Placement tips for greenhouse, mushroom farm and 3D printer enclosure

  • Greenhouse: Mount the DHT22 at plant height, away from the direct sun and away from the heater outlet. Keep the breadboard and power supply in a dry plastic box with only the sensor and antenna outside.
  • Hydroponics room: Keep the electronics away from the nutrient tank splash zone. Humidity here is high, so a ventilated project box with the sensor on a short cable works best.
  • Mushroom farming: Fruiting chambers run at very high humidity, often close to the upper end of what a DHT22 handles. Keep the sensor out of direct mist and water droplets, and check it now and then against a reference hygrometer. Condensation on the sensor can give a reading stuck at 100%.
  • 3D printer enclosure: Put the sensor inside the enclosure, but keep the ESP32, LoRa module and the power supply outside where it stays cooler. The DHT22 handles normal PLA and ABS enclosure temperatures well.
  • Antenna: Keep the antenna vertical and away from metal sheets and wet soil. Raising the transmitter and receiver antennas even by one or two metres can improve range more than anything else.

Troubleshooting

Problem What to check
Serial Monitor is empty Set USB CDC On Boot to Enabled and reselect the port
AT commands show no reply TX and RX wires are swapped, or the module is not getting 3.3V
DHT22 read failed Check the DATA pin, the pull-up resistor and the 3.3V supply
Receiver gets nothing Address, network ID and band must match on both modules, and the antennas must be attached
Random resets of the transmitter Add the 100 µF capacitor and check the MB102 jumpers are on the right voltage
Dashboard does not open Phone must be on the same Wi-Fi network as the receiver, and use the IP printed in Serial Monitor

Frequently Asked Questions (FAQs)

Q1: Can I connect a 5V Relay Module on the Transmitter side to automatically control a humidifier or exhaust fan? Yes! Because you already have the MB102 Breadboard Power Supply on the transmitter node, you can power your 5V Relay Module directly from the 5V Rail (+) of the MB102 while keeping the RYLR998 isolated on the 3.3V Rail (+). This prevents relay coil activation currents and the 140 mA LoRa transmit bursts from resetting the ESP32-C3.

Q2: Can I add multiple transmitter nodes (e.g., Greenhouse #1, Mushroom Room #2, 3D Printer Enclosure #3) to one Receiver? Yes! Simply give each transmitter a unique address (AT+ADDRESS=1, AT+ADDRESS=3, AT+ADDRESS=4) and have all of them send data to the Receiver (AT+SEND=2,...). Because the receiver’s +RCV= string always starts with the sender’s address (+RCV=1,... or +RCV=3,...), you can easily display multiple rooms on the same web page.

Q3: How can I get even longer range out of the RYLR998? In the code, change AT+PARAMETER=9,7,1,12 to AT+PARAMETER=12,7,1,12 on both nodes. Increasing the Spreading Factor from 9 to 12 slows down the air data rate slightly, which dramatically boosts receiver sensitivity and range through dense obstacles.

Q4: Can I replace the DHT22 with an SHT31 or BME280 sensor? Absolutely. Since the LoRa link simply transmits a comma-separated text string (Temp,Humidity,PacketID), you can swap the DHT22 for an I2C sensor like the SHT31 (wired to SDA = GPIO 8, SCL = GPIO 9) without changing a single line of the Receiver or Web Server code!

Add a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *