Uncategorized

ESP32 and LoRaWAN: Long-Range IoT Without Wi-Fi or Cellular

Every connectivity option covered so far in this series — Wi-Fi, Bluetooth, MQTT over Wi-Fi — shares one limitation: range. Wi-Fi tops out at maybe 50 meters indoors, and BLE even less. For projects that need to communicate over kilometers rather than meters, without the cost and power draw of cellular, LoRaWAN fills a gap none of these other protocols can touch.

This guide covers what LoRaWAN is, how it works with the ESP32, and when it’s the right choice over the connectivity options covered in our other guides.

What Is LoRaWAN?

LoRaWAN (Long Range Wide Area Network) is a low-power wireless protocol built on top of LoRa (Long Range) radio modulation. It’s specifically designed for devices that need to send small amounts of data over long distances — think 2-15 kilometers in rural areas, and 1-5 kilometers in dense urban environments — while consuming very little power.

Unlike Wi-Fi or Bluetooth, LoRaWAN isn’t built for high-bandwidth communication. It’s built for the opposite: small, infrequent messages traveling very long distances on minimal power.

LoRaWAN vs Wi-Fi vs BLE vs Cellular

FactorWi-FiBLELoRaWANCellular (NB-IoT/LTE-M)
Range~50m indoor~10-30m1-15kmWide (carrier coverage)
Power consumptionHighLowVery lowModerate
BandwidthHighLow-moderateVery lowLow-moderate
Infrastructure costRouter neededNone (direct)Gateway neededCarrier subscription
Best forHigh-bandwidth, short rangePhone-connected devicesLong-range, low-data-rateWide-area, carrier-covered

How LoRaWAN Networks Are Structured

End Devices

Your ESP32-based sensor or tracker, equipped with a LoRa radio module, is the “end device” — it transmits small data packets at infrequent intervals.

Gateways

LoRaWAN end devices transmit to a gateway, which can receive signals from many end devices across a wide geographic area and forward that data to a network server, typically over a standard internet connection.

Network Server and Application Server

The network server manages device authentication, deduplicates messages received by multiple gateways, and routes data to the appropriate application server, where your actual application logic processes the incoming sensor data.

Public vs Private Networks

You can either use a public LoRaWAN network or deploy your own private gateway if you’re operating in an area without existing coverage — a common choice for industrial sites, farms, or campuses.

Setting Up ESP32 with LoRaWAN

Hardware Requirements

The ESP32 itself doesn’t include a LoRa radio — you’ll need an add-on module (commonly using the Semtech SX1276 or SX1262 chipset) connected via SPI, or a combined ESP32+LoRa development board.

Basic LoRaWAN Join and Send Example

cpp

#include <lmic.h>
#include <hal/hal.h>

// Device credentials (from your LoRaWAN network provider)
static const u1_t PROGMEM DEVEUI[8] = { /* your DevEUI */ };
static const u1_t PROGMEM APPEUI[8] = { /* your AppEUI */ };
static const u1_t PROGMEM APPKEY[16] = { /* your AppKey */ };

void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8); }
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8); }
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16); }

static osjob_t sendjob;

void do_send(osjob_t* j) {
  uint8_t payload[] = {0x01, 0x02, 0x03}; // your sensor data, encoded
  LMIC_setTxData2(1, payload, sizeof(payload), 0);
  Serial.println("Packet queued");
}

void onEvent(ev_t ev) {
  if (ev == EV_TXCOMPLETE) {
    Serial.println("Transmission complete");
    os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(300), do_send); // send every 5 minutes
  }
}

void setup() {
  Serial.begin(115200);
  os_init();
  LMIC_reset();
  do_send(&sendjob);
}

void loop() {
  os_runloop_once();
}

This example uses OTAA (Over-The-Air Activation), where the device authenticates with the network the first time it powers on — the recommended approach over ABP (Activation By Personalization), which uses fixed keys and offers weaker security.

Practical Considerations

Duty Cycle and Fair Use Regulations

Most regions regulate the LoRa radio spectrum with duty cycle limits — restrictions on how much airtime a device can use in a given period. LoRaWAN isn’t suited for frequent updates, and network and regional regulations may cap you at a small number of transmissions per hour.

Payload Size Limits

LoRaWAN payloads are small — often limited to under 250 bytes depending on the data rate and region. This forces efficient encoding: sending raw sensor values as compact binary data rather than verbose JSON.

Gateway Coverage Planning

Before committing to LoRaWAN for a project, verify gateway coverage in your target deployment area. Unlike cellular, LoRaWAN range depends heavily on terrain, obstacles, and gateway antenna placement.

Combining LoRaWAN with Deep Sleep

LoRaWAN’s already-low power characteristics pair naturally with ESP32’s Deep Sleep mode — a device that wakes briefly to take a reading, sends a small LoRaWAN packet, then returns to deep sleep can run for months or years on a single battery.

When to Choose LoRaWAN Over Alternatives

Choose LoRaWAN when:

  • Your device needs to communicate over kilometers, not meters.
  • Data volume per transmission is small.
  • Battery life measured in months or years matters more than real-time responsiveness.
  • Deployment areas may lack reliable Wi-Fi or cellular coverage.

Choose Wi-Fi or cellular instead when:

  • You need to send larger payloads or communicate frequently.
  • Low latency matters more than power efficiency.
  • Existing Wi-Fi or cellular infrastructure already covers your deployment area.

Conclusion

LoRaWAN fills a specific and important gap in the IoT connectivity landscape: long range and excellent power efficiency, at the cost of bandwidth and transmission frequency. For remote sensor deployments, agricultural monitoring, or asset tracking across large areas, it often makes more sense than pushing Wi-Fi range with extenders or paying for cellular data plans across dozens of devices.

For more on maximizing battery life in projects like this, our ESP32 Deep Sleep guide covers the power management techniques that pair naturally with LoRaWAN’s already-efficient transmission model.

Tags

IoT Journal

Technical Product Manager focused on enterprise IoT and digital transformation.

Leave a Reply

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

Back to top button
Close