A complete IoT solution for real-time water tanker fleet monitoring, featuring GPS tracking, water level monitoring, tamper detection, and automated alerts.
- Video Demo: Watch the system in action: SWAT Demo on YouTube
- Hardware Simulation: Try the hardware simulation: Wokwi Simulator
SWAT is an end-to-end water tanker monitoring system that combines hardware sensors with a modern web dashboard to provide real-time visibility into your water tanker fleet. The system tracks GPS location, monitors water levels using ultrasonic sensors, detects tampering, and sends automated email alerts.
- Real-time GPS Tracking: Monitor the location of all tankers on an interactive map
- Water Level Monitoring: Track water levels with ultrasonic sensors
- Tamper Detection: Automated detection of suspicious water level drops
- Email Alerts: Instant notifications for critical events
- Fleet Dashboard: Comprehensive overview of all tankers and their status
- Historical Data: Charts and logs for analysis and reporting
SWAT/
βββ Hardware/ # Arduino/ESP32 firmware and sensor code
β βββ altsoftserialcode.c
β βββ gcorrectlocation.c
β βββ gpslocationloop.c
β
βββ Software/ # Next.js web dashboard
βββ app/ # Next.js app router pages
βββ components/ # React components
βββ lib/ # Utilities and services
βββ public/ # Static assets
- Microcontroller: ESP32 or Arduino with WiFi/GSM module
- GPS Module: NEO-6M or similar for location tracking
- Ultrasonic Sensor: HC-SR04 or JSN-SR04T for water level measurement
- Power Supply: 12V battery or vehicle power adapter
- Enclosure: Waterproof housing for electronics
- GPS Module: Connect to serial pins for location data
- Ultrasonic Sensor: Mount at the top of the water tank
- Trigger pin β GPIO pin
- Echo pin β GPIO pin
- VCC β 5V
- GND β Ground
- ESP32/Arduino: Program with the firmware from
/Hardwaredirectory - Power: Connect to stable 12V power source
ESP32/Arduino
βββ GPS Module (TX/RX)
βββ Ultrasonic Sensor (Trig/Echo)
βββ Power (12V β 5V regulator)
βββ WiFi/GSM Module (if separate)
- Frontend: Next.js 15, React 19, TypeScript
- Styling: Tailwind CSS 4, shadcn/ui components
- Maps: Google Maps API
- Charts: Recharts
- Real-time: MQTT (HiveMQ), Server-Sent Events
- Email: Resend API
- State Management: SWR
- Fleet statistics (total, active, inactive tankers)
- Average water level across fleet
- Low and critical level alerts
- Search and filter functionality
- Live GPS tracking on interactive map
- Water level gauges and charts
- Color-coded status indicators
- Automatic updates without page refresh
- Multi-tanker tamper monitoring
- Suspicious water level drop detection
- Automated email alerts
- Event logging and history
- Detailed tanker information
- Location map with path history
- Water level history chart
- Sensor data and status
- Node.js 18 or higher
- npm or yarn
- Google Maps API key
- MQTT broker (HiveMQ Cloud account)
- Resend API key (for email alerts)
- Arduino IDE or PlatformIO (for hardware)
git clone <repository-url>
cd SWATcd Hardware
# Open .c files in Arduino IDE
# Configure WiFi credentials and MQTT broker details
# Upload to ESP32/Arduinocd Software
npm installCreate Software/.env:
# MQTT Broker
HIVEMQ_HOST=your-broker.hivemq.cloud
HIVEMQ_PORT=8883
HIVEMQ_USERNAME=your-username
HIVEMQ_PASSWORD=your-password
# Google Maps
NEXT_PUBLIC_GOOGLE_MAPS_API_KEY=your-api-key
# Tanker Configuration
NEXT_PUBLIC_TANKER_DEPTH_CM=200
# Email Alerts
RESEND_API_KEY=your-resend-api-key
ALERT_EMAIL=your-email@example.com
# Tamper Detection
TAMPER_TIMEOUT_MS=60000cd Software
npm run devEach tanker publishes to two topics:
{TANKER_ID}/gps β GPS coordinates
{TANKER_ID}/distance β Ultrasonic sensor reading (cm)
GPS Topic (T001/gps):
{
"lat": 12.9716,
"lon": 77.5946
}Distance Topic (T001/distance):
68.5
#include <WiFi.h>
#include <PubSubClient.h>
const char* TANKER_ID = "T001";
const char* WIFI_SSID = "your-wifi";
const char* WIFI_PASSWORD = "your-password";
const char* MQTT_SERVER = "broker.hivemq.cloud";
const int MQTT_PORT = 8883;
WiFiClient espClient;
PubSubClient client(espClient);
void publishGPS(float lat, float lon) {
String topic = String(TANKER_ID) + "/gps";
String payload = "{\"lat\":" + String(lat, 6) +
",\"lon\":" + String(lon, 6) + "}";
client.publish(topic.c_str(), payload.c_str());
}
void publishDistance(float distance) {
String topic = String(TANKER_ID) + "/distance";
String payload = String(distance);
client.publish(topic.c_str(), payload.c_str());
}# Test GPS data
mosquitto_pub -h your-broker.hivemq.cloud -p 8883 \
-u username -P password --capath /etc/ssl/certs/ \
-t "T001/gps" -m '{"lat":12.9716,"lon":77.5946}'
# Test distance data
mosquitto_pub -h your-broker.hivemq.cloud -p 8883 \
-u username -P password --capath /etc/ssl/certs/ \
-t "T001/distance" -m "68.5"Simply change the tanker ID and publish to new topics:
T002/gpsandT002/distanceT003/gpsandT003/distance- etc.
Water Level (cm) = Tank Depth - Sensor Distance
Percentage = (Water Level / Tank Depth) Γ 100
| Status | Range | Color |
|---|---|---|
| Full | 75-100% | π’ Green |
| Good | 50-75% | π΅ Blue |
| Low | 25-50% | π Orange |
| Critical | 0-25% | π΄ Red |
The system monitors for:
- Rapid water level drops
- Unusual patterns in sensor data
- Disconnected sensors
Automated emails are sent for:
- Tamper detection events
- Critical water levels (< 25%)
- Sensor disconnections
- System errors
View all alerts in the Email Logs section of the dashboard.
GET /api/stream- Real-time data stream (SSE)GET /api/tamper-status- Current tamper detection statusGET /api/email-logs- Email notification history
- Flash firmware to each ESP32/Arduino
- Configure unique tanker IDs (T001, T002, etc.)
- Mount sensors in water tanks
- Connect to power supply
- Verify MQTT connection and data transmission
GPS not getting fix:
- Ensure clear view of sky
- Wait 2-5 minutes for initial fix
- Check antenna connection
Ultrasonic sensor not reading:
- Verify wiring connections
- Check power supply (5V)
- Ensure sensor is mounted correctly
MQTT not connecting:
- Verify WiFi credentials
- Check broker URL and port
- Confirm SSL/TLS settings
Dashboard not showing data:
- Check MQTT broker connection
- Verify topic names match pattern
- Inspect browser console for errors
Map not loading:
- Verify Google Maps API key
- Enable Maps JavaScript API
- Check API quotas
Email alerts not working:
- Confirm Resend API key is valid
- Check email address configuration
- Review email logs for errors
- Software README - Detailed dashboard documentation
- Multi-Tanker Setup Guide - Implementation guide
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is private and proprietary.
- Next.js - React framework
- shadcn/ui - UI component library
- Google Maps Platform - Mapping services
- HiveMQ Cloud - MQTT broker
- Resend - Email service
- Recharts - Charting library
For issues, questions, or feature requests, please open an issue in the repository.
- Video Demo: https://youtu.be/Gl9nbqIaxvQ
- Hardware Simulation: https://wokwi.com/projects/444181553182324737
Built with β€οΈ for efficient water management