This project implements a dual directional antenna–based RF localization system using ESP32, LoRa RF modules, Mosquitto MQTT, and a React (Vite) dashboard. The system estimates the relative direction and position of a transmitter by analyzing received signal characteristics from directional antennas connected to spatially separated receiver nodes.
This guide will help you set up a Mosquitto MQTT broker on Windows, connect ESP32 devices for IoT communication, and run a React dashboard for monitoring and control in a dual directional antenna-based localization system.
project-root/
├── dashboard/ # Vite React web application
│ ├── package.json
│ ├── src/
│ └── ...
├── receiver/
│ └── receiver.ino # ESP32 receiver code
├── transmitter/
│ └── transmitter.ino # ESP32 transmitter code
└── README.md
-
LoRa RF modules are used for both transmission and reception
-
Operates in sub-GHz ISM bands (e.g., 433 MHz, 868 MHz, 915 MHz)
-
Chosen for:
- Long-range capability
- Robust link budget
- RSSI and SNR reporting
-
Transmitter ESP32
- No WiFi required
- RF-only operation
- Board-specific identifier
-
Receiver ESP32
- WiFi enabled
- MQTT client
- Publishes RF measurements to broker
- Buck converter strongly recommended
- Avoid powering ESP32 directly from linear regulators
- Prevents brownout during WiFi transmission peaks
- The system operates at 433 MHz, chosen for its availability in the ISM band and compatibility with LoRa modules.
-
A Yagi–Uda antenna was designed and built for the transmitter.
-
Design goals:
- Directional radiation pattern for localization
- High gain with moderate beamwidth
- Minimized side and back lobes
- 4NEC2 software was used to simulate antenna parameters and optimize performance.
-
Simulations included:
- Element lengths and spacing
- Radiation pattern (gain, beamwidth, front-to-back ratio)
- Impedance characteristics
-
Optimization aimed to achieve:
- Maximum forward gain
- VSWR < 2:1 at 433 MHz
- Balanced element excitation
-
Balanis’ “Antenna Theory: Analysis and Design” was used to determine:
- Uncompensated element lengths
- Compensated lengths after accounting for practical construction factors
-
These calculations ensured theoretical guidance aligned with practical design. See page number 594 - 597
Reference:
C. A. Balanis, Antenna Theory: Analysis and Design, 4th Edition, John Wiley & Sons, 2016.
- Uncompensated element lengths
- Compensated lengths after accounting for practical construction factors
- These calculations ensured theoretical guidance aligned with practical design.
-
A matching circuit was calculated using 4NEC2 to ensure proper impedance matching between the Yagi antenna and the 50 Ω LoRa transmitter.
-
Goals:
- Minimize reflection coefficient
- Maximize power transfer to the antenna
-
Typical approach included LC network optimization.
-
A balun (balanced-to-unbalanced transformer) is recommended for Yagi antennas to:
- Suppress common-mode currents on the feedline
- Maintain radiation pattern integrity
- Ensure balanced operation between antenna and coax
-
While not yet implemented, a 1:1 or 4:1 current balun can be added at the feedpoint for improved performance.
radiation-pattern-and-impedance-matching
- The final antenna design combines simulation-based optimization, practical corrections, and matching network design to achieve reliable RF transmission at 433 MHz.
- Future improvements include balun implementation to further reduce feedline radiation and improve impedance matching.
- Windows 10/11
- ESP32 development board(s)
- Arduino IDE or PlatformIO
- Node.js (for React dashboard)
- WiFi network access
-
Download Mosquitto
- Visit mosquitto.org/download
- Download the Windows installer (64-bit recommended)
- Run the installer as administrator
-
Add Mosquitto to System PATH
- Open System Properties → Advanced → System Variables
- Add
C:\Program Files\mosquittoto your PATH variable
Create the following directories for Mosquitto data and logs:
mkdir C:\mosquitto\data
mkdir C:\mosquitto\log- Navigate to
C:\Program Files\mosquitto - Open
mosquitto.conffile (create if it doesn't exist) - Add the following configuration at the end of the file:
# Allow anonymous connections
allow_anonymous true
# Plain MQTT (ESP32, MQTT clients)
listener 1883
protocol mqtt
# WebSockets (browser dashboard)
listener 9002
protocol websockets
# Persistence & logging
persistence true
persistence_location C:\mosquitto\data\
log_dest file C:\mosquitto\log\mosquitto.log
Open Command Prompt as administrator and run:
net start mosquittoExpected output:
The Mosquitto Broker service is starting.
The Mosquitto Broker service was started successfully.
Open Command Prompt and run:
ipconfigNote your IPv4 address (e.g., 10.214.162.1)
Important: For reliable operation, it's recommended to use a buck converter for powering ESP32 boards instead of the onboard voltage regulator. This ensures stable power delivery and prevents brownouts during WiFi transmission.
- Open Arduino IDE or PlatformIO
- Load the
transmitter/transmitter.inofile - Update the following variables in the code:
ANTENNA_FREQUENCY: Set your desired antenna frequency design (e.g.,433E6for 433MHz,915E6for 915MHz)BOARD_ID: Set to"board1"or"board2"depending on which transmitter this is
- Upload the code to your ESP32 transmitter device
Note: The transmitter does not require WiFi or MQTT configuration as it communicates directly via radio frequency.
- Load the
receiver/receiver.inofile - Update the following variables in the code:
ssid: Your WiFi network namepassword: Your WiFi passwordmqtt_server: Your PC's IP address (from Step 5)ANTENNA_FREQUENCY: Set to match your transmitter's frequency (e.g.,433E6for 433MHz,915E6for 915MHz)BOARD_ID: Set to"board1"or"board2"to match the corresponding transmitter
- Upload the code to your ESP32 receiver device
- Navigate to the dashboard directory:
cd dashboard- Install the required packages:
npm installStart the React development server:
npm run devThe dashboard should now be accessible at http://localhost:5173 (or the port specified by Vite).
Open Command Prompt and run:
mosquitto_sub -h 10.214.162.1 -t "esp32/+"This will subscribe to all ESP32-related topics and show data received from the transmitter via the receiver.
Monitor receiver status and data:
mosquitto_sub -h 10.214.162.1 -t "esp32/receiver/status"
mosquitto_sub -h 10.214.162.1 -t "esp32/receiver/data"Monitor board-specific data:
mosquitto_sub -h 10.214.162.1 -t "esp32/board1/+"
mosquitto_sub -h 10.214.162.1 -t "esp32/board2/+"Control receiver via MQTT:
mosquitto_pub -h 10.214.162.1 -t "esp32/receiver/control" -m "reset"Note: The transmitter communicates via RF only and does not publish directly to MQTT. All MQTT communication comes through the receiver.
mosquitto_sub -h 10.214.162.1 -t "esp32/+"-h 10.214.162.1: Specifies the MQTT broker's IP address-t "esp32/+": Subscribes to all topics starting with "esp32/" (wildcard subscription)
mosquitto_pub -h 10.214.162.1 -t "esp32/transmitter/control" -m "start"-h 10.214.162.1: Specifies the MQTT broker's IP address-t "esp32/transmitter/control": Sets the target topic-m "start": Sends the message "start" to the topic
-
Start Mosquitto Broker:
net start mosquitto -
Start React Dashboard:
cd dashboard npm run dev -
Flash and Connect ESP32 Devices:
- Upload
transmitter.inoto transmitter ESP32 (configure ANTENNA_FREQUENCY and BOARD_ID) - Upload
receiver.inoto receiver ESP32 (configure WiFi, MQTT, ANTENNA_FREQUENCY, and BOARD_ID) - Transmitter will start broadcasting via RF
- Receiver will connect to WiFi and MQTT broker, forwarding received RF data
- Upload
-
Access Dashboard:
- Open browser to
http://localhost:5173 - Monitor real-time localization data from ESP32 devices
- Send commands through the web interface
- Open browser to
The React dashboard provides:
- Real-time MQTT message monitoring from receiver
- Localization data visualization and tracking
- Device status indicators for receiver and connected transmitters
- Interactive controls for receiver device
- WebSocket connection to Mosquitto (port 9002)
- Board-specific data visualization (board1, board2)
- RF signal strength and directional antenna monitoring
- Real-time positioning and triangulation display
- Responsive design for desktop and mobile
-
Mosquitto service won't start:
- Check if port 1883 is already in use
- Run Command Prompt as administrator
- Verify configuration file syntax
-
ESP32 devices can't connect:
- Receiver issues:
- Ensure receiver ESP32 and PC are on the same network
- Check Windows Firewall settings (allow ports 1883, 9002)
- Verify the IP address is correct in receiver code
- Make sure Mosquitto service is running
- Transmitter issues:
- Check antenna frequency configuration matches receiver
- Verify BOARD_ID is properly set and unique
- Ensure proper power supply (use buck converter)
- Check RF transmission range
- Receiver issues:
-
React dashboard won't start:
- Ensure Node.js is installed
- Run
npm installin the dashboard directory - Check for port conflicts (default: 5173)
-
WebSocket connection fails:
- Verify Mosquitto is configured for WebSockets (port 9002)
- Check browser console for connection errors
- Ensure firewall allows port 9002
Allow Mosquitto through Windows Firewall:
- Open Windows Defender Firewall
- Click "Allow an app or feature through Windows Defender Firewall"
- Add
mosquitto.exeand allow both private and public networks - Ensure ports 1883 and 9002 are open
C:\Program Files\mosquitto\
├── mosquitto.conf # Configuration file
├── mosquitto.exe # Main executable
└── ...
C:\mosquitto\
├── data\ # Persistence data
└── log\ # Log files
└── mosquitto.log
project-root/
├── dashboard/ # React dashboard
│ ├── package.json
│ ├── vite.config.js
│ ├── src/
│ │ ├── App.jsx
│ │ ├── components/
│ │ └── ...
│ └── dist/ # Built files (after npm run build)
├── receiver/
│ └── receiver.ino # ESP32 receiver firmware
└── transmitter/
└── transmitter.ino # ESP32 transmitter firmware
# Stop Mosquitto
net stop mosquitto
# Stop React dev server
# Press Ctrl+C in the terminal running npm run dev# View Mosquitto logs
type C:\mosquitto\log\mosquitto.log
# View real-time logs
tail -f C:\mosquitto\log\mosquitto.logcd dashboard
npm run buildThis configuration allows anonymous connections for testing purposes. For production use, consider:
- Setting up username/password authentication
- Using SSL/TLS encryption
- Configuring proper access control lists
- Disabling anonymous access
- Using environment variables for sensitive data
Note: Transmitter boards communicate via RF to the receiver, which then publishes the data to appropriate MQTT topics based on BOARD_ID.
This setup guide is provided as-is for educational and development purposes.