A step-by-step guide for building and configuring your IoT system with ESP32, LoRa, 5G, and PACE communication.
This guide provides detailed instructions for setting up an IoT system with integrated ATAK functionality, leveraging ESP32, 5G for video transmission, and PACE communication strategies for robust connectivity.
The system includes:
Below are wiring diagrams for connecting the ESP32-CAM, LoRa module, GPS, and other components.
ESP32 Pin Connections:
- LoRa Module:
VCC -> 3.3V
GND -> GND
MISO -> GPIO19
MOSI -> GPIO23
SCK -> GPIO18
NSS -> GPIO5
RST -> GPIO14
DIO0 -> GPIO26
- GPS Module:
VCC -> 3.3V
GND -> GND
RX -> GPIO16
TX -> GPIO17
Raspberry Pi Zero 2 W Pin Connections: - LoRa Module: VCC -> 3.3V GND -> GND MISO -> GPIO9 MOSI -> GPIO10 SCK -> GPIO11 NSS -> GPIO8 RST -> GPIO25 DIO0 -> GPIO24 - Optional GPS Module: VCC -> 3.3V GND -> GND RX -> GPIO14 TX -> GPIO15
The Raspberry Pi Zero 2 W collects LoRa data from ESP32 nodes and forwards it to the central hub (Raspberry Pi 4) via Wi-Fi or 5G, depending on network availability.
Raspberry Pi Pin Connections:
- 5G Modem:
USB Modem -> Raspberry Pi USB Port
- LoRa Gateway:
VCC -> 5V
GND -> GND
MISO -> GPIO9
MOSI -> GPIO10
SCK -> GPIO11
NSS -> GPIO8
RST -> GPIO25
DIO0 -> GPIO24
Use weatherproof enclosures for outdoor nodes. Ensure stable power supply to each device using LiPo batteries or solar panels as necessary.
Flash the ESP32 with the following firmware for LoRa and GPS communication:
#include#include TinyGPSPlus gps; HardwareSerial gpsSerial(1); void setup() { gpsSerial.begin(9600, SERIAL_8N1, 16, 17); LoRa.begin(868E6); } void loop() { while (gpsSerial.available() > 0) { if (gps.encode(gpsSerial.read())) { String message = "{"; message += "\"lat\":" + String(gps.location.lat(), 6) + ","; message += "\"lon\":" + String(gps.location.lng(), 6) + "}"; LoRa.beginPacket(); LoRa.print(message); LoRa.endPacket(); } } }
Set up Node-RED on both the Raspberry Pi Zero 2 W and Raspberry Pi 4 to handle PACE communication:
[{
"id": "primary",
"type": "http request",
"url": "http://central_hub:8087",
"method": "POST",
"headers": {"Content-Type": "application/xml"},
"wires": [["response_handler"]]
}, {
"id": "fallback_wifi",
"type": "mqtt out",
"topic": "fallback/wifi",
"broker": "mqtt_broker",
"wires": [["response_handler"]]
}, {
"id": "fallback_lora",
"type": "function",
"name": "LoRa Packet Handler",
"func": "msg.payload = {data: msg.payload}; return msg;",
"wires": [["send_lora"]]
}]
The flow attempts to send data using 5G first (HTTP), then Wi-Fi (MQTT), and finally LoRa as a contingency.
Install the following software on the Raspberry Pi:
sudo apt update
sudo apt install mosquitto mosquitto-clients
sudo apt install nodered influxdb grafana
Set up a flow to handle incoming data from ESP32 nodes:
[{
"id": "sensor1",
"type": "mqtt in",
"topic": "sensors/#",
"broker": "mqtt_broker",
"payload": "json",
"wires": [["process_data"]]
}, {
"id": "process_data",
"type": "function",
"name": "Parse GPS",
"func": "msg.payload = {lat: msg.payload.lat, lon: msg.payload.lon}; return msg;",
"wires": [["influxdb"]]
}]
Use the CoT protocol to send sensor and video data to ATAK:
Sensor detected motion
Use Python to send CoT data via HTTP:
import requests cot_message = """""" response = requests.post("http://atak_ip:8087", data=cot_message, headers={"Content-Type": "application/xml"}) print(response.status_code) Motion detected
Node-RED dynamically switches channels based on availability. For example:
if (5G_unavailable) {
switch_to("Wi-Fi Mesh");
} else if (Wi-Fi_unavailable) {
switch_to("LoRa");
} else if (LoRa_unavailable) {
switch_to("Satellite");
}
Common issues and their solutions: