An advanced, solar-powered GPS bike tracker with real-time location monitoring and GSM communication capabilities
๐ Quick Start โข ๐ Features โข ๐ง Hardware โข ๐ Documentation โข ๐ค Contributing
- ๐ Overview
- โจ Features
- ๐ง Hardware Requirements
- ๐ป Software Requirements
- ๐ Quick Start
- โก Hardware Assembly
- ๐ก Pin Configuration
- ๐ ๏ธ Software Installation
- ๐ API Documentation
- ๐ก SIM800L Internet Setup Guide
- ๐ Web API Integration Guide
- ๐ฏ Usage Examples
- ๐ Troubleshooting
- ๐ Changelog
- ๐ค Contributing
- ๐ License
- ๐ Acknowledgments
The IoT Bike Tracker is a comprehensive solution for bicycle security and monitoring, featuring real-time GPS tracking, GSM communication, and sustainable solar power. Built with the ESP8266-based NodeMCU v3.1.0, this project combines robust hardware design with efficient software architecture for reliable outdoor operation.
- ๐ฐ๏ธ Real-time GPS Tracking with Neo6m module (fully implemented)
- ๐ฑ GSM Communication via SIM800L for remote monitoring (fully implemented)
- ๐ HTTP API Integration with web services over GPRS (fully implemented)
- โ๏ธ Solar-powered with dual 18650 battery backup (hardware design)
- ๏ฟฝ Modular Code Architecture for easy customization (fully implemented)
- ๐ Weather-resistant 3D-printed enclosure (design provided)
- ๏ฟฝ Secure Bike Mounting with custom clamp design (design provided)
- GPS tracking with NMEA parsing
- SMS notifications and HTTP API
- Motion detection (GPS-based)
- Speed monitoring and alerts
- Geofencing with breach detection
- System status monitoring
- Dual mode operation (Testing/Production)
- Network connectivity management
- Comprehensive power sleep modes
- Low power management system
- LED status indication (requires LED on D8)
- Audio alerts (requires buzzer on D7)
- OTA updates
- Mobile app integration
- High-precision location tracking with Neo6m GPS module
- Real-time coordinate acquisition and processing
- Configurable update intervals for battery optimization
- NMEA data parsing and validation
- SMS-based location reporting via SIM800L module
- HTTP POST requests to web APIs over GPRS
- Real-time data transmission to cloud services
- Remote command processing capability
- Network status monitoring and error handling
- Configurable message intervals (default: 30 minutes)
- Dual solar panel charging system
- 2S BMS protection for 18650 lithium batteries
- Buck converter voltage regulation
- Comprehensive sleep mode implementation
- Low power mode with activity monitoring
- Deep sleep for extended battery life
- Configurable update intervals for power optimization
- Robust PCB layout optimized for outdoor use
- Water-resistant (IP54) 3D-printed enclosure
- Secure bike mounting system with anti-theft features
- Temperature-resistant component selection
All enclosure parts are in the model/ folder. The cases are designed as stackable modular partsโeach piece fits together to form the complete enclosure. You can use just the original case, or stack Case 2 parts on top for a multi-layer build. Below are previews and download links for all parts:
|
Case 1 โ Top & Bottom Views Top View PNG ยท Bottom View PNG ยท STL ยท GCODE |
Case 2 โ Top & Bottom Views Top View PNG ยท Bottom View PNG ยท STL ยท GCODE |
Case 2 Cover โ Top & Bottom Views Top View PNG ยท Bottom View PNG ยท STL ยท GCODE |
Clamp Case 2 Cover Support โ Top & Bottom Views Top View PNG ยท Bottom View PNG ยท STL ยท GCODE |
Bike Tracker Clamp โ Top & Bottom Views Top View PNG ยท Bottom View PNG ยท STL ยท GCODE |
Case Cover Solar Mount โ Top & Bottom Views Top View PNG ยท Bottom View PNG ยท STL |
All Parts Joined โ Top & Bottom Views Top View PNG ยท Bottom View PNG |
Printing notes: Use PETG or ABS for weather resistance. Add internal standoffs for the PCB and cable exits with grommets for water protection. All parts are designed to stack as modular layersโcombine only the parts you need for your build.
- Print all required parts and clean off support material.
- Install electronics (NodeMCU, SIM800L, Neo6m, batteries) into the Case 1 bottom. Secure the PCB and components.
- Place Case 1 top onto the bottom and loosely fasten screws. If routing wires upward, leave screws slightly loose.
- Stack Case 2 bottom on top of Case 1 top. Align pegs and holes for a snug fit.
- Fasten the stacked cases together using M3 screws or clips. Make sure the joint is tight and secure.
- For weatherproofing, apply a thin bead of silicone or use a gasket between the mating faces.
- Route antennas or cables through the upper compartment as needed. Seal any cable exits with silicone or cable glands.
- Material: PETG or ABS for outdoor durability
- Layer height: 0.2 mm
- Walls: 2โ3 perimeters (โฅ1.2 mm)
- Infill: 20โ40% depending on strength needs
- Supports: Use for overhangs and internal features
- Check alignment and fit of all stacked parts before final assembly.
- Verify clearance for antennas, SIM slot, and cables.
- Confirm screw lengths do not interfere with electronics.
- Inspect gasket or seal for full coverage.
- Object-oriented C++ design with separate classes
- Modular GPS and GSM communication libraries
- Comprehensive error handling and recovery
- Serial debugging and monitoring capabilities
- Dual operating modes (Testing/Development and Production)
- State management system (Initializing, Standby, Tracking, Alert, Error)
- Enhanced modular architecture with proper separation of concerns
Source/BikeTracker/
โโโ BikeTracker.ino # Main application logic with dual mode support
โโโ ModeConfig.h # Operating mode configuration
โโโ PinConfig.h # Hardware pin definitions
โโโ APIConfig.h # HTTP API configuration
โโโ BikeTrackerCore.h/.cpp # Core tracking logic with HTTP integration
โโโ Neo6mGPS.h/.cpp # Enhanced GPS module with full NMEA parsing
โโโ Sim800L.h/.cpp # Enhanced GSM module with HTTP capabilities
๐ Dual Mode Operation:
- Testing Mode: Debug output, serial commands, accelerated timing, test SMS
- Production Mode: Minimal logging, normal timing, real emergency contacts
๐ง Advanced Core Logic:
- Motion detection algorithms with GPS-based tracking
- Speed monitoring with configurable limits
- Geofencing with breach detection
- Alert system with multiple types (Motion, Speed, Geofence, System errors)
- Comprehensive power sleep mode implementation
- Low power management with activity tracking
- Emergency SMS notifications
- Automatic web API data transmission
- Real-time location updates to HTTP endpoints
๐ก Enhanced GPS Features:
- Full NMEA sentence parsing (GGA and RMC)
- Real-time location data extraction
- Speed calculation and monitoring
- GPS fix status detection
- Coordinate conversion (DMS to Decimal)
๐ฑ Advanced GSM Capabilities:
- Network status monitoring and signal strength checking
- Reliable SMS transmission with error handling
- AT command processing with timeout handling
- HTTP POST requests over GPRS
- GPRS initialization and management
- JSON data transmission
- Automatic reconnection with exponential backoff
- Connection health monitoring
๐๏ธ Testing Mode Commands:
ARM/DISARM- Security controlSTATUS- Detailed system statusDIAG- Hardware diagnosticsALERT/SPEED/FENCE- Simulate GPS-based alertsLOCATE- Send location SMSAPI- Test HTTP API connectivityCONNECT- Test internet connectivityRESET- Reset GPRS connectionSLEEP- Enter sleep mode (5 min)DEEPSLEEP- Enter deep sleep (30 min)LOWPOWER- Toggle low power modeWAKE- Wake from sleepHELP- Command reference
Note: Full power management system implemented with comprehensive sleep modes.
| Component | Quantity | Specification | Purpose |
|---|---|---|---|
| ๐ Mini Solar Panel | 2x | 5V 1W Polycrystalline | Primary power source |
| ๐ 18650 Lithium Battery | 2x | 3.7V 3000mAh Protected | Energy storage |
| โก 2S BMS Module | 1x | 7.4V 8A Protection | Battery management |
| ๐ Buck Converter | 2x | DC-DC Step Down 3.3V/5V | Voltage regulation |
| ๐ง NodeMCU v3.1.0 | 1x | ESP8266 Development Board | Main microcontroller |
| ๐ฐ๏ธ Neo6m GPS Module | 1x | UART GPS Receiver | Location tracking |
| ๐ฑ SIM800L GSM Module | 1x | Quad-band GSM/GPRS | Communication |
| ๐ 3D Printed Case | 1x | Water-resistant ABS/PETG | Protection enclosure |
| ๐ง Bike Mounting Clamp | 1x | Adjustable Security Clamp | Secure attachment |
- Input Voltage: 5V (Solar) / 7.4V (Battery)
- Operating Voltage: 3.3V (MCU) / 5V (Modules)
- Power Consumption: ~200mA (Active) / ~50ฮผA (Sleep)
- Battery Life: 7-14 days (weather dependent)
- ๐ฐ๏ธ Real-time GPS tracking
- ๐ฑ SMS notifications and HTTP API
- ๐ถ Motion detection (GPS-based)
- ๐๏ธ Speed monitoring and alerts
- ๐บ๏ธ Geofencing with breach detection
- ๐ System status monitoring
- ๐ค Comprehensive power sleep modes
- ๐ Audio Alerts - Buzzer pin defined and function implemented (D7)
- ๐ก Status LEDs - LED pin defined and function implemented (D8)
Note: The current implementation focuses on GPS+GSM functionality with comprehensive power management. LED and buzzer functionality is implemented but requires physical components.
- Arduino IDE 1.8.19 or later
- ESP8266 Board Package 3.0.0 or later
- USB to Serial Driver (CP2102/CH340)
// Core Libraries (Built-in)
#include <Arduino.h>
#include <SoftwareSerial.h>
// Project-specific Libraries (Included)
#include "Neo6mGPS.h" // GPS module handler
#include "Sim800L.h" // GSM module handler# Install ESP8266 Board Package
# File โ Preferences โ Additional Board Manager URLs:
# http://arduino.esp8266.com/stable/package_esp8266com_index.jsongit clone https://github.com/qppd/IoT-Bike-Tracker.git
cd IoT-Bike-Tracker/Source/BikeTracker- Assemble components according to wiring diagram
- Connect solar panels and battery system
- Mount GPS and GSM antennas appropriately
- Open
BikeTracker.inoin Arduino IDE - Select NodeMCU 1.0 (ESP-12E Module) board
- Choose appropriate COM port
- Upload code to device
- Insert activated SIM card into SIM800L module
- Power on the system and monitor serial output
- Test GPS acquisition and GSM connectivity
Solar Panels โ Buck Converter โ 2S BMS โ 18650 Batteries
โ โ โ โ
5V Input โ Regulated โ 7.4V โ Power
Voltage Storage Backup
The wiring diagram below shows the recommended connections between the NodeMCU (ESP8266), Neo6m GPS, SIM800L, power system (buck converters and 2S BMS) and optional buzzer / status LED. Use the diagram as a reference when assembling the hardware; verify voltage levels before connecting modules.
Note: The SIM800L requires a stable 4V-ish supply capable of delivering peak currents (~2A). Use a proper buck regulator and large decoupling capacitors near the module.
-
GPS Module (Neo6m)
- Connect VCC to 3.3V regulated output
- Connect GND to common ground
- Wire RX/TX to designated GPIO pins
-
GSM Module (SIM800L)
- Connect VCC to 5V regulated output (high current)
- Ensure stable power supply with capacitors
- Connect antenna for optimal signal reception
-
NodeMCU Integration
- Power via VIN pin (5V) or 3.3V pin
- Configure GPIO pins for SoftwareSerial communication
- Implement proper grounding across all modules
| Module | Function | NodeMCU Pin | GPIO | Notes |
|---|---|---|---|---|
| GPS | RX | D2 | GPIO4 | SoftwareSerial RX |
| GPS | TX | D3 | GPIO0 | SoftwareSerial TX |
| GSM | RX | D5 | GPIO14 | SoftwareSerial RX |
| GSM | TX | D6 | GPIO12 | SoftwareSerial TX |
| Buzzer | Signal | D7 | GPIO13 | Audio alerts (implemented) |
| Status LED | Signal | D8 | GPIO15 | Status indication (implemented) |
| Power | VIN | VIN | - | 5V Input |
| Debug | USB | USB | - | Serial Monitor |
- Avoid using GPIO0, GPIO2, GPIO15 during boot
- Ensure proper pull-up/pull-down resistors where needed
- Use level shifters if voltage mismatch occurs
-
Prepare Development Environment
# Install Arduino IDE # Add ESP8266 board support # Install required drivers
-
Configure Board Settings
Board: "NodeMCU 1.0 (ESP-12E Module)" CPU Frequency: "80 MHz" Flash Size: "4MB (FS:2MB OTA:~1019KB)" Upload Speed: "115200" -
Compile and Upload
// Verify code compilation // Select correct COM port // Upload to device // Monitor serial output
The system uses modular configuration files for easy customization:
// Set operating mode
#define CURRENT_MODE MODE_TESTING // or MODE_PRODUCTION
// Mode-specific settings
#if CURRENT_MODE == MODE_TESTING
#define GPS_UPDATE_INTERVAL 5000 // 5 seconds for testing
#define SMS_ALERT_INTERVAL 30000 // 30 seconds for testing
#define MOTION_THRESHOLD 5 // Lower threshold for testing
#define MAX_SPEED_THRESHOLD 10 // km/h for testing alerts
#define EMERGENCY_CONTACT "+1234567890" // Test number
#endif// Web API settings
#define WEB_API_URL "https://your-api.com/api/tracker"
#define DEVICE_ID "BIKE_TRACKER_001"
#define APN_NAME "internet"
// Update intervals
#define HTTP_UPDATE_INTERVAL 30000 // 30 seconds
#define HTTP_RETRY_ATTEMPTS 3
#define CONNECTION_CHECK_INTERVAL 60000 // 1 minute// Hardware pin assignments
#define GPS_RX_PIN D2
#define GPS_TX_PIN D3
#define GSM_RX_PIN D5
#define GSM_TX_PIN D6
#define BUZZER_PIN D7
#define LED_STATUS_PIN D8Neo6mGPS(SoftwareSerial &serial)Initializes GPS module with specified serial interface.
| Method | Return Type | Description |
|---|---|---|
begin(long baudrate) |
void |
Initialize GPS serial communication |
available() |
bool |
Check if GPS data is available |
read() |
String |
Read GPS NMEA sentence |
- Full NMEA sentence parsing (GGA and RMC)
- Real-time location data extraction
- Speed calculation and monitoring
- GPS fix status detection
- Coordinate conversion (DMS to Decimal)
SoftwareSerial SerialGPS(D2, D3);
Neo6mGPS gps(SerialGPS);
void setup() {
gps.begin(9600);
}
void loop() {
if (gps.available()) {
String gpsData = gps.read();
// Process GPS data
}
}Sim800L(SoftwareSerial &serial)Initializes GSM module with specified serial interface.
| Method | Return Type | Description |
|---|---|---|
begin(long baudrate) |
void |
Initialize GSM serial communication |
sendSMS(String number, String message) |
void |
Send SMS to specified number |
available() |
bool |
Check if GSM data is available |
read() |
String |
Read GSM response data |
initializeGPRS(String apn, String user, String pass) |
bool |
Initialize GPRS connection |
sendHTTPPOST(String url, String jsonData, String &response) |
bool |
Send HTTP POST request |
sendLocationHTTP(String url, String deviceId, float lat, float lon, String alertType) |
bool |
Send location data to web API |
disconnectGPRS() |
void |
Disconnect GPRS connection |
setHTTPHeaders(String headers) |
void |
Set custom HTTP headers |
- Network status monitoring
- Signal strength checking
- Reliable SMS transmission
- AT command processing
- HTTP POST requests
- GPRS initialization and management
- JSON data transmission
- Error handling and recovery
- Automatic reconnection with exponential backoff
- Connection health monitoring
SoftwareSerial SerialGSM(D5, D6);
Sim800L gsm(SerialGSM);
void setup() {
gsm.begin(9600);
}
void sendLocation() {
gsm.sendSMS("+1234567890", "Bike Location: lat,lng");
}The bike tracker now supports sending location data to web APIs via HTTP POST requests over GPRS with comprehensive internet connectivity features.
Edit APIConfig.h to configure your web API:
// Your web API endpoint
#define WEB_API_URL "https://your-api.com/api/tracker"
// Unique device identifier
#define DEVICE_ID "BIKE_TRACKER_001"
// Mobile carrier APN - Common APNs
#define APN_NAME "internet" // Generic (try this first)
// === US CARRIERS ===
// #define APN_NAME "vzwinternet" // Verizon
// #define APN_NAME "phone" // AT&T
// #define APN_NAME "fast.t-mobile.com" // T-Mobile
// === EUROPEAN CARRIERS ===
// #define APN_NAME "three.co.uk" // Three UK
// #define APN_NAME "orangeworld" // Orange
// Update interval (milliseconds)
#define HTTP_UPDATE_INTERVAL 30000 // 30 seconds
// Connection settings
#define GPRS_RETRY_ATTEMPTS 3 // Connection retry attempts
#define HTTP_RETRY_ATTEMPTS 3 // HTTP request retries
#define CONNECTION_CHECK_INTERVAL 60000 // 1 minute
// Enable/disable HTTP functionality
#define HTTP_ENABLED trueThe tracker sends location data in the following JSON format:
{
"deviceId": "BIKE_TRACKER_001",
"latitude": 40.7128,
"longitude": -74.0060,
"timestamp": "1640995200000",
"alertType": "MOTION_DETECTED",
"signalStrength": 25,
"localIP": "10.64.64.64",
"imei": "123456789012345"
}The alertType field can contain the following values:
""(empty) - Regular location update"MOTION_DETECTED"- Unauthorized movement detected (GPS-based) โ"SPEED_EXCEEDED"- Speed limit exceeded (GPS-based) โ"GEOFENCE_BREACH"- Vehicle left safe area (GPS-based) โ"SYSTEM_ERROR"- System malfunction โ"GPS_LOST"- GPS signal lost for extended period โ"GSM_LOST"- GSM connection lost for extended period โ
Note: Clean alert system focused on GPS+GSM functionality without hardware dependencies.
Your web API should accept POST requests with:
- Content-Type:
application/json - HTTP Method:
POST - Expected Response: HTTP 200-299 for success
Example response format:
{
"status": "success",
"message": "Location data received",
"deviceId": "BIKE_TRACKER_001"
}// Configure the web API in setup()
void setup() {
tracker.setWebAPI(WEB_API_URL, DEVICE_ID, APN_NAME);
}
// Location data is automatically sent every HTTP_UPDATE_INTERVAL
// Manual sending can be triggered with:
tracker.sendLocationToAPI();In testing mode, use these serial commands:
ARM- Arm the trackerDISARM- Disarm the trackerSTATUS- View detailed system statusDIAG- Run hardware diagnosticsALERT- Simulate motion alertSPEED- Simulate speed alertFENCE- Simulate geofence breachLOCATE- Send location SMSAPI- Manually send location to web APICONNECT- Test internet connectivityRESET- Reset GPRS connectionSLEEP- Enter sleep mode (5 minutes)DEEPSLEEP- Enter deep sleep (30 minutes)LOWPOWER- Toggle low power modeWAKE- Wake from sleepHELP- Show command menu
Note: Comprehensive power management system with multiple sleep modes is fully implemented.
This section provides comprehensive instructions for setting up robust internet connectivity on your IoT Bike Tracker using the SIM800L GSM/GPRS module with enhanced features including automatic reconnection, connection monitoring, and extensive error handling.
- Data Plan: Ensure your SIM card has an active data plan
- PIN Code: Disable PIN code protection on the SIM card
- Roaming: Enable data roaming if needed for your location
- Network Type: 2G/GSM network compatibility required
Before installation, test your SIM card in a phone to verify:
- Network registration works
- Data connectivity is functional
- APN settings are correct
// === COMMON WORLDWIDE APNs ===
#define APN_NAME "internet" // Generic (try this first)
// === US CARRIERS ===
// #define APN_NAME "vzwinternet" // Verizon
// #define APN_NAME "phone" // AT&T
// #define APN_NAME "fast.t-mobile.com" // T-Mobile
// === EUROPEAN CARRIERS ===
// #define APN_NAME "three.co.uk" // Three UK
// #define APN_NAME "internet" // Vodafone
// #define APN_NAME "orangeworld" // Orange
// === ASIAN CARRIERS ===
// #define APN_NAME "airtelgprs.com" // Airtel India
// #define APN_NAME "www" // Jio India#define GPRS_RETRY_ATTEMPTS 3 // Connection retry attempts
#define HTTP_RETRY_ATTEMPTS 3 // HTTP request retries
#define HTTP_UPDATE_INTERVAL 30000 // Regular updates (30 seconds)
#define CONNECTION_CHECK_INTERVAL 60000 // Connection health check (1 minute)- Automatically detects lost GPRS connections
- Attempts reconnection with exponential backoff
- Falls back to connection reset if needed
- Continuous health monitoring
- Inactive connection detection
- Preventive connection maintenance
- Automatic retry logic for failed requests
- Proper error code handling
- Enhanced JSON payload with metadata
- Detailed connection status reporting
- HTTP transaction logging
- Error diagnosis information
Use the serial console to test connectivity:
CONNECT - Test internet connectivity
RESET - Reset GPRS connection
API - Send test data to API
STATUS - Show system status
DIAG - Run comprehensive diagnostics
=== Internet Connectivity Test ===
GSM Network: Connected
Signal Strength: 18 (0-31, higher is better)
GPRS Status: Connected
Local IP: 10.64.64.64
Internet Test: SUCCESS - Internet accessible
Testing API connectivity...
HTTP POST result: SUCCESS
=== Test Complete ===
Solutions:
- Check antenna connection
- Verify SIM card is properly inserted
- Ensure SIM card is activated and has credit
- Check signal strength in your area
Solutions:
- Verify APN settings for your carrier
- Check if data plan is active
- Try different APN from the list
- Ensure sufficient signal strength (>10)
Solutions:
- Verify carrier data settings
- Check for network restrictions
- Try resetting the connection:
RESETcommand - Contact carrier about data connectivity
Solutions:
- Verify API URL is correct and accessible
- Check if API server is running
- Ensure JSON format is accepted by your API
- Test API with external tools (Postman, curl)
- Stable Voltage: 3.7V - 4.2V (4V recommended)
- Current Capability: Minimum 2A peak current
- Power Supply: Use quality power supply or battery
- Brownout Protection: Implement power monitoring
- Insufficient current causes connection drops
- Voltage fluctuations cause module resets
- Poor power supply affects signal quality
- Use SIM cards with secure profiles
- Monitor for unauthorized usage
- Implement data usage limits
- Use HTTPS endpoints when possible
- Implement API authentication
- Validate device identifiers server-side
- Monitor for unusual network activity
- Implement rate limiting on API endpoints
- Use device certificates for enhanced security
- Maintain persistent GPRS connections
- Use connection pooling when possible
- Implement smart retry algorithms
- Compress JSON payloads
- Batch multiple updates when appropriate
- Use efficient data formats
- Power down module during inactive periods (not implemented)
- Optimize power consumption with comprehensive sleep modes
- Optimize update frequencies (implemented via configurable intervals)
-
Hardware Check
- Antenna properly connected
- SIM card inserted correctly
- Power supply adequate (2A+)
- Voltage stable (3.7V-4.2V)
-
SIM Card Check
- Data plan active
- PIN code disabled
- Network registration working
- Sufficient credit/data allowance
-
Configuration Check
- Correct APN for carrier
- Valid API URL
- Proper timeout settings
- Debug logging enabled
-
Network Check
- Signal strength >10
- GPRS registration successful
- Internet connectivity confirmed
- API endpoint accessible
-
Software Check
- Latest firmware version
- No compilation errors
- Debug output showing proper flow
- Error handling working correctly
- Endpoint: Your API URL (configured in
APIConfig.h) - Method:
POST - Content-Type:
application/json - Expected Response: HTTP 200-299 for success
| Field | Type | Description | Example |
|---|---|---|---|
deviceId |
String | Unique identifier for the tracker device | "BIKE_TRACKER_001" |
latitude |
Number | GPS latitude coordinate (decimal degrees) | 40.7128 |
longitude |
Number | GPS longitude coordinate (decimal degrees) | -74.0060 |
timestamp |
String | Unix timestamp in milliseconds | "1640995200000" |
alertType |
String | Type of alert (optional, empty for regular updates) | "MOTION_DETECTED" |
signalStrength |
Number | GSM signal strength (0-31, or -1 if unknown) | 25 |
const express = require('express');
const app = express();
app.use(express.json());
app.post('/api/tracker', (req, res) => {
const { deviceId, latitude, longitude, timestamp, alertType, signalStrength } = req.body;
// Validate required fields
if (!deviceId || !latitude || !longitude || !timestamp) {
return res.status(400).json({ error: 'Missing required fields' });
}
// Log the received data
console.log(`Received location from ${deviceId}:`);
console.log(` Location: ${latitude}, ${longitude}`);
console.log(` Timestamp: ${new Date(parseInt(timestamp))}`);
console.log(` Alert: ${alertType || 'None'}`);
console.log(` Signal: ${signalStrength}`);
// Store in database (implement your storage logic here)
storeLocationData({
deviceId,
latitude: parseFloat(latitude),
longitude: parseFloat(longitude),
timestamp: new Date(parseInt(timestamp)),
alertType: alertType || null,
signalStrength: parseInt(signalStrength)
});
// Send success response
res.status(200).json({
status: 'success',
message: 'Location data received',
deviceId: deviceId
});
});
app.listen(3000, () => {
console.log('Bike Tracker API listening on port 3000');
});from flask import Flask, request, jsonify
from datetime import datetime
import json
app = Flask(__name__)
@app.route('/api/tracker', methods=['POST'])
def receive_location():
try:
data = request.get_json()
# Validate required fields
required_fields = ['deviceId', 'latitude', 'longitude', 'timestamp']
for field in required_fields:
if field not in data:
return jsonify({'error': f'Missing field: {field}'}), 400
# Extract data
device_id = data['deviceId']
latitude = float(data['latitude'])
longitude = float(data['longitude'])
timestamp = datetime.fromtimestamp(int(data['timestamp']) / 1000)
alert_type = data.get('alertType', '')
signal_strength = int(data.get('signalStrength', -1))
# Log received data
print(f"Received location from {device_id}:")
print(f" Location: {latitude}, {longitude}")
print(f" Timestamp: {timestamp}")
print(f" Alert: {alert_type or 'None'}")
print(f" Signal: {signal_strength}")
# Store in database (implement your storage logic here)
store_location_data({
'device_id': device_id,
'latitude': latitude,
'longitude': longitude,
'timestamp': timestamp,
'alert_type': alert_type or None,
'signal_strength': signal_strength
})
# Return success response
return jsonify({
'status': 'success',
'message': 'Location data received',
'deviceId': device_id
}), 200
except Exception as e:
print(f"Error processing location data: {e}")
return jsonify({'error': 'Internal server error'}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3000, debug=True)<?php
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo json_encode(['error' => 'Method not allowed']);
exit;
}
$input = file_get_contents('php://input');
$data = json_decode($input, true);
// Validate required fields
$required_fields = ['deviceId', 'latitude', 'longitude', 'timestamp'];
foreach ($required_fields as $field) {
if (!isset($data[$field])) {
http_response_code(400);
echo json_encode(['error' => "Missing field: $field"]);
exit;
}
}
// Extract data
$device_id = $data['deviceId'];
$latitude = floatval($data['latitude']);
$longitude = floatval($data['longitude']);
$timestamp = date('Y-m-d H:i:s', intval($data['timestamp']) / 1000);
$alert_type = $data['alertType'] ?? '';
$signal_strength = intval($data['signalStrength'] ?? -1);
// Log received data
error_log("Received location from $device_id:");
error_log(" Location: $latitude, $longitude");
error_log(" Timestamp: $timestamp");
error_log(" Alert: " . ($alert_type ?: 'None'));
error_log(" Signal: $signal_strength");
// Store in database and return success response
try {
store_location_data([
'device_id' => $device_id,
'latitude' => $latitude,
'longitude' => $longitude,
'timestamp' => $timestamp,
'alert_type' => $alert_type ?: null,
'signal_strength' => $signal_strength
]);
echo json_encode([
'status' => 'success',
'message' => 'Location data received',
'deviceId' => $device_id
]);
} catch (Exception $e) {
error_log("Error storing location data: " . $e->getMessage());
http_response_code(500);
echo json_encode(['error' => 'Internal server error']);
}
?>CREATE TABLE bike_locations (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
device_id VARCHAR(50) NOT NULL,
latitude DECIMAL(10, 8) NOT NULL,
longitude DECIMAL(11, 8) NOT NULL,
timestamp TIMESTAMP NOT NULL,
alert_type VARCHAR(50),
signal_strength INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_device_timestamp (device_id, timestamp),
INDEX idx_alert_type (alert_type)
);// Example document structure
{
_id: ObjectId("..."),
deviceId: "BIKE_TRACKER_001",
latitude: 40.7128,
longitude: -74.0060,
timestamp: ISODate("2023-01-01T12:00:00.000Z"),
alertType: "MOTION_DETECTED",
signalStrength: 25,
createdAt: ISODate("2023-01-01T12:00:05.000Z")
}
// Create indexes for better performance
db.bike_locations.createIndex({ "deviceId": 1, "timestamp": -1 });
db.bike_locations.createIndex({ "alertType": 1 });You can test your API endpoint using curl:
curl -X POST https://your-api.com/api/tracker \
-H "Content-Type: application/json" \
-d '{
"deviceId": "BIKE_TRACKER_001",
"latitude": 40.7128,
"longitude": -74.0060,
"timestamp": "1640995200000",
"alertType": "MOTION_DETECTED",
"signalStrength": 25
}'Expected response:
{
"status": "success",
"message": "Location data received",
"deviceId": "BIKE_TRACKER_001"
}void trackLocation() {
if (gps.available()) {
String nmea = gps.read();
if (nmea.startsWith("$GPGGA")) {
// Parse coordinates
// Extract latitude/longitude
// Store or transmit data
}
}
}void sendAlert(String alertType) {
String message = "BIKE ALERT: " + alertType +
" Location: " + getCurrentLocation();
gsm.sendSMS(OWNER_PHONE, message);
}// Comprehensive sleep mode implementation
void enterSleepMode(unsigned long durationMs = 300000) {
// Light sleep with wake conditions monitoring
// Maintains connections but reduces power
}
void enterDeepSleep(unsigned long durationMs = 1800000) {
// Deep sleep for maximum power savings
// Uses ESP8266 deep sleep functionality
}
void enableLowPowerMode(bool enabled = true) {
// Automatic sleep when inactive
// Configurable timeout settings
}- Real-time GPS tracking with NMEA parsing
- SMS notifications for alerts and status
- HTTP API data transmission over GPRS
- Motion detection based on GPS coordinates
- Speed monitoring and alerts
- Geofencing with breach detection
- Dual mode operation (Testing/Production)
- Serial command interface for testing
- Network connectivity monitoring
- Automatic GPRS reconnection
- LED status indication (requires LED on D8)
- Buzzer alerts (requires buzzer on D7)
- Pin configurations defined and implemented
- Modular code architecture
Our streamlined GPS and GSM tracking system includes robust power management capabilities:
- Light Sleep: Maintains connections while reducing power consumption
- Deep Sleep: Maximum power savings using ESP8266 deep sleep functionality
- Low Power Mode: Automatic sleep when inactive with configurable timeouts
- Activity Tracking: Monitors system activity to optimize sleep scheduling
- Wake Conditions: GPS updates, GSM messages, and timer-based wake events
Available commands in testing mode:
SLEEP- Enter light sleep mode (5 minutes default)DEEPSLEEP- Enter deep sleep mode (30 minutes default)LOWPOWER- Enable automatic low power modeWAKE- Wake from sleep modes and resume normal operation
| Problem | Symptoms | Solution |
|---|---|---|
| GPS No Fix | No coordinate data | โข Check antenna placement โข Verify power supply โข Wait for satellite acquisition |
| GSM No Network | SMS not sending | โข Check SIM card activation โข Verify network coverage โข Inspect antenna connection |
| Power Issues | Frequent resets | โข Check battery voltage โข Verify solar panel output โข Inspect wiring connections |
| Upload Failed | Code won't upload | โข Check COM port selection โข Try different USB cable โข Reset NodeMCU manually |
// Enable verbose debugging
#define DEBUG_MODE 1
// Serial monitor output
Serial.println("GPS Status: " + gps.getStatus());
Serial.println("GSM Signal: " + gsm.getSignalStrength());
Serial.println("Sleep Mode: " + String(status.inSleepMode ? "ACTIVE" : "DISABLED"));
Serial.println("Last Activity: " + String(millis() - status.lastActivity) + "ms ago");- ๐ง Email: Create an issue on GitHub
- ๐ Documentation: Check Wiki for detailed guides
- ๐ฌ Community: Join discussions in Issues section
- โ HTTP API Integration - Full GPRS connectivity with web API support
- โ Dual Mode Operation - Testing/Development and Production modes
- โ Enhanced GPS Module - Complete NMEA parsing and location processing
- โ Advanced GSM Module - HTTP POST, GPRS management, automatic reconnection
- โ Core Tracker Logic - State management, motion detection, alerts
- โ Comprehensive Power Management - Light sleep, deep sleep, and low power modes
- โ Activity Tracking - Automatic sleep optimization and wake condition monitoring
- โ Modular Architecture - Clean separation of concerns and components
- โ Removed Battery Monitoring - Eliminated sensor-dependent features for better reliability
- โ Removed Theft Detection - Streamlined focus on GPS+GSM core functionality
- โ Enhanced Power System - Comprehensive sleep modes with ESP8266 built-in capabilities
- โ Simplified Configuration - Reduced complexity by removing external sensor dependencies
- โ GPRS Connectivity: Full HTTP POST support over GPRS connection
- โ JSON Data Format: Structured location and alert data transmission
- โ Web API Communication: Real-time data push to cloud services
- โ Configurable Endpoints: Easy API URL and device ID configuration
- โ Alert Notifications: Automatic alert transmission to web APIs
- โ Regular Updates: Configurable interval-based location updates
- โ Connection Health Monitoring: Automatic reconnection and health checks
- โ Enhanced Error Handling: Robust error recovery and retry mechanisms
- โ Complete File Structure: All modules implemented with proper organization
- โ Configuration Management: Centralized configuration files for all settings
- โ Testing Framework: Comprehensive testing mode with serial commands
- โ Production Ready: Optimized production mode for deployment
- โ Documentation: Complete API documentation and setup guides
- โ Motion detection when armed (GPS-based)
- โ Speed limit monitoring with configurable thresholds
- โ Geofence boundary detection and breach alerts
- โ Emergency notifications via SMS and HTTP API
- โ Remote status monitoring via HTTP API
- โ Comprehensive power management with sleep modes
- โ Hardware failure detection and recovery
- โ Network connectivity monitoring and recovery
- โ Activity tracking and automatic sleep optimization
- โ SMS notification system for emergency alerts
- โ HTTP API data transmission for real-time monitoring
- โ Multiple carrier APN support (US, European, Asian carriers)
- โ Signal strength monitoring and reporting
- โ Network status checking and error handling
- โ Automatic GPRS connection management
- โ Solar power integration with dual 18650 battery backup
- โ Power optimization algorithms for extended battery life
- โ Comprehensive sleep modes: Light sleep, deep sleep, and automatic low power mode
- โ Activity tracking: Monitors system activity to optimize power consumption
- โ Wake condition management: GPS updates, GSM messages, and timer-based wake events
- โ Hardware component power control
- ๐ง Web dashboard for real-time monitoring
- ๐ง Mobile app integration for remote control
- ๐ง Advanced geofencing with custom boundary shapes
- ๐ง Historical route tracking and analytics
- ๐ง Battery voltage monitoring (requires external voltage sensor)
- ๐ง Motion-based theft detection (requires accelerometer/gyroscope)
- ๐ง OTA (Over-The-Air) update capability
- ๐ง Enhanced security features with encryption
- ๐ง SMS command processing for remote control
- ๐ง Historical data analysis and reporting
- ๐ง Multiple device management dashboard
- Phase 1: Basic GPS tracking and SMS notifications โ
- Phase 2: HTTP API integration and GPRS connectivity โ
- Phase 3: Enhanced error handling and recovery mechanisms โ
- Phase 4: Dual mode operation and comprehensive testing โ
- Phase 5: Complete documentation and setup guides โ
- Phase 6: Web dashboard and mobile app (Planned)
- Phase 7: Advanced features and optimizations (Planned)
We welcome contributions from the community! Here's how you can help:
-
๐ด Fork the Repository
git fork https://github.com/qppd/IoT-Bike-Tracker.git
-
๐ฟ Create Feature Branch
git checkout -b feature/amazing-feature
-
๐พ Commit Changes
git commit -m "Add amazing feature" -
๐ค Push to Branch
git push origin feature/amazing-feature
-
๐ Open Pull Request
- Describe your changes clearly
- Include testing information
- Reference any related issues
- Code Style: Follow Arduino/C++ conventions
- Documentation: Update README and comments
- Testing: Verify functionality before submission
- Issues: Use templates for bug reports and features
Thanks to all contributors who have helped improve this project!
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 qppd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
- ESP8266 Community for excellent documentation and support
- Arduino Foundation for the development platform
- Open Source Hardware movement for inspiration
- Contributors who have helped improve this project
- ESP8266 Arduino Core Documentation
- Neo6m GPS Module Datasheet
- SIM800L GSM Module Documentation
- 3D Printing Guidelines
- Arduino IDE - Primary development environment
- Fritzing - Circuit design and documentation
- Fusion 360 - 3D modeling and case design
- VS Code - Documentation and advanced editing