Skip to content

An advanced, solar-powered GPS bike tracker with real-time location monitoring and GSM communication capabilities.

Notifications You must be signed in to change notification settings

qppd/IoT-Bike-Tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

53 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿšดโ€โ™‚๏ธ IoT Bike Tracker

Arduino ESP8266 C++ License Version

An advanced, solar-powered GPS bike tracker with real-time location monitoring and GSM communication capabilities

๐Ÿš€ Quick Start โ€ข ๐Ÿ“‹ Features โ€ข ๐Ÿ”ง Hardware โ€ข ๐Ÿ“– Documentation โ€ข ๐Ÿค Contributing


๐Ÿ“‹ Table of Contents


๐ŸŒŸ Overview

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.

๐ŸŽฏ Key Highlights

  • ๐Ÿ›ฐ๏ธ 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)

๐Ÿ“Š Implementation Status

โœ… Core Features (Ready to Use)

  • 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

โญ Optional Hardware Enhancements

  • LED status indication (requires LED on D8)
  • Audio alerts (requires buzzer on D7)

๐Ÿšง Future Enhancements

  • OTA updates
  • Mobile app integration

โœจ Features

๐Ÿ›ฐ๏ธ GPS Tracking System

  • 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

๐Ÿ“ก GSM Communication

  • 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)

โšก Power Management

  • 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

๐Ÿ—๏ธ Hardware Design

  • 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

๐Ÿงฉ Bike Tracker Case Models (Stackable Modular Parts)

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 View
Case 1 Bottom View
Case 1 โ€” Top & Bottom Views
Top View PNG ยท Bottom View PNG ยท STL ยท GCODE
Case 2 Top View
Case 2 Bottom View
Case 2 โ€” Top & Bottom Views
Top View PNG ยท Bottom View PNG ยท STL ยท GCODE
Case 2 Cover (Top View)
Case 2 Cover (Bottom View)
Case 2 Cover โ€” Top & Bottom Views
Top View PNG ยท Bottom View PNG ยท STL ยท GCODE
Clamp Case 2 Cover Support (Top View)
Clamp Case 2 Cover Support (Bottom View)
Clamp Case 2 Cover Support โ€” Top & Bottom Views
Top View PNG ยท Bottom View PNG ยท STL ยท GCODE
Clamp (Top View)
Clamp (Bottom View)
Bike Tracker Clamp โ€” Top & Bottom Views
Top View PNG ยท Bottom View PNG ยท STL ยท GCODE
Case Cover Solar Mount (Top View)
Case Cover Solar Mount (Bottom View)
Case Cover Solar Mount โ€” Top & Bottom Views
Top View PNG ยท Bottom View PNG ยท STL
All Parts Joined (Top View)
All Parts Joined (Bottom View)
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.

Assembly Guide

  1. Print all required parts and clean off support material.
  2. Install electronics (NodeMCU, SIM800L, Neo6m, batteries) into the Case 1 bottom. Secure the PCB and components.
  3. Place Case 1 top onto the bottom and loosely fasten screws. If routing wires upward, leave screws slightly loose.
  4. Stack Case 2 bottom on top of Case 1 top. Align pegs and holes for a snug fit.
  5. Fasten the stacked cases together using M3 screws or clips. Make sure the joint is tight and secure.
  6. For weatherproofing, apply a thin bead of silicone or use a gasket between the mating faces.
  7. Route antennas or cables through the upper compartment as needed. Seal any cable exits with silicone or cable glands.

Recommended Print Settings

  • 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

Quick Fit Checklist

  1. Check alignment and fit of all stacked parts before final assembly.
  2. Verify clearance for antennas, SIM slot, and cables.
  3. Confirm screw lengths do not interfere with electronics.
  4. Inspect gasket or seal for full coverage.

๐Ÿ’พ Software Architecture

  • 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

Complete File Architecture

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

Enhanced System Features

๐Ÿ”„ 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 control
  • STATUS - Detailed system status
  • DIAG - Hardware diagnostics
  • ALERT/SPEED/FENCE - Simulate GPS-based alerts
  • LOCATE - Send location SMS
  • API - Test HTTP API connectivity
  • CONNECT - Test internet connectivity
  • RESET - Reset GPRS connection
  • SLEEP - Enter sleep mode (5 min)
  • DEEPSLEEP - Enter deep sleep (30 min)
  • LOWPOWER - Toggle low power mode
  • WAKE - Wake from sleep
  • HELP - Command reference

Note: Full power management system implemented with comprehensive sleep modes.


๐Ÿ”ง Hardware Requirements

๐Ÿ“ฆ Bill of Materials (BOM)

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

๐Ÿ”Œ Power Specifications

  • 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)

โšก Feature Compatibility

โœ… Basic Hardware (GPS + GSM + MCU)

  • ๐Ÿ›ฐ๏ธ 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

โญ Optional Hardware Enhancements

  • ๐Ÿ”Š 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.


๐Ÿ’ป Software Requirements

๐Ÿ› ๏ธ Development Environment

  • Arduino IDE 1.8.19 or later
  • ESP8266 Board Package 3.0.0 or later
  • USB to Serial Driver (CP2102/CH340)

๐Ÿ“š Required Libraries

// 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

๐Ÿ“‹ Library Installation

# Install ESP8266 Board Package
# File โ†’ Preferences โ†’ Additional Board Manager URLs:
# http://arduino.esp8266.com/stable/package_esp8266com_index.json

๐Ÿš€ Quick Start

1๏ธโƒฃ Clone Repository

git clone https://github.com/qppd/IoT-Bike-Tracker.git
cd IoT-Bike-Tracker/Source/BikeTracker

2๏ธโƒฃ Hardware Setup

  • Assemble components according to wiring diagram
  • Connect solar panels and battery system
  • Mount GPS and GSM antennas appropriately

3๏ธโƒฃ Software Upload

  • Open BikeTracker.ino in Arduino IDE
  • Select NodeMCU 1.0 (ESP-12E Module) board
  • Choose appropriate COM port
  • Upload code to device

4๏ธโƒฃ Initial Configuration

  • Insert activated SIM card into SIM800L module
  • Power on the system and monitor serial output
  • Test GPS acquisition and GSM connectivity

โšก Hardware Assembly

๐Ÿ”Œ Power System Connection

Solar Panels โ†’ Buck Converter โ†’ 2S BMS โ†’ 18650 Batteries
     โ†“              โ†“             โ†“           โ†“
   5V Input    โ†’  Regulated   โ†’  7.4V    โ†’  Power
                   Voltage      Storage     Backup

๐Ÿ–ผ๏ธ Wiring Diagram

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.

Wiring Diagram

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.

๐Ÿ“ก Module Integration

  1. GPS Module (Neo6m)

    • Connect VCC to 3.3V regulated output
    • Connect GND to common ground
    • Wire RX/TX to designated GPIO pins
  2. GSM Module (SIM800L)

    • Connect VCC to 5V regulated output (high current)
    • Ensure stable power supply with capacitors
    • Connect antenna for optimal signal reception
  3. NodeMCU Integration

    • Power via VIN pin (5V) or 3.3V pin
    • Configure GPIO pins for SoftwareSerial communication
    • Implement proper grounding across all modules

๐Ÿ“ก Pin Configuration

๐ŸŽ›๏ธ NodeMCU v3.1.0 Pin Mapping

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

โš ๏ธ Important Notes

  • Avoid using GPIO0, GPIO2, GPIO15 during boot
  • Ensure proper pull-up/pull-down resistors where needed
  • Use level shifters if voltage mismatch occurs

๐Ÿ› ๏ธ Software Installation

๐Ÿ“ฅ Step-by-Step Installation

  1. Prepare Development Environment

    # Install Arduino IDE
    # Add ESP8266 board support
    # Install required drivers
  2. Configure Board Settings

    Board: "NodeMCU 1.0 (ESP-12E Module)"
    CPU Frequency: "80 MHz"
    Flash Size: "4MB (FS:2MB OTA:~1019KB)"
    Upload Speed: "115200"
    
  3. Compile and Upload

    // Verify code compilation
    // Select correct COM port
    // Upload to device
    // Monitor serial output

๐Ÿ”ง Configuration Options

The system uses modular configuration files for easy customization:

Mode Configuration (ModeConfig.h)

// 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

API Configuration (APIConfig.h)

// 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

Pin Configuration (PinConfig.h)

// 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 D8

๐Ÿ“– API Documentation

๐Ÿ“ Neo6mGPS Class

Constructor

Neo6mGPS(SoftwareSerial &serial)

Initializes GPS module with specified serial interface.

Methods

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

Enhanced 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)

Usage Example

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 Class

Constructor

Sim800L(SoftwareSerial &serial)

Initializes GSM module with specified serial interface.

Methods

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

Enhanced Features

  • 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

Usage Example

SoftwareSerial SerialGSM(D5, D6);
Sim800L gsm(SerialGSM);

void setup() {
    gsm.begin(9600);
}

void sendLocation() {
    gsm.sendSMS("+1234567890", "Bike Location: lat,lng");
}

๐ŸŒ HTTP API Integration

The bike tracker now supports sending location data to web APIs via HTTP POST requests over GPRS with comprehensive internet connectivity features.

Configuration

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 true

JSON Data Format

The 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"
}

Alert Types

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.

API Endpoint Requirements

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"
}

Usage Example

// 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();

Testing Commands

In testing mode, use these serial commands:

  • ARM - Arm the tracker
  • DISARM - Disarm the tracker
  • STATUS - View detailed system status
  • DIAG - Run hardware diagnostics
  • ALERT - Simulate motion alert
  • SPEED - Simulate speed alert
  • FENCE - Simulate geofence breach
  • LOCATE - Send location SMS
  • API - Manually send location to web API
  • CONNECT - Test internet connectivity
  • RESET - Reset GPRS connection
  • SLEEP - Enter sleep mode (5 minutes)
  • DEEPSLEEP - Enter deep sleep (30 minutes)
  • LOWPOWER - Toggle low power mode
  • WAKE - Wake from sleep
  • HELP - Show command menu

Note: Comprehensive power management system with multiple sleep modes is fully implemented.


๐Ÿ“ก SIM800L Internet Setup Guide

๐ŸŒ Internet Connectivity Overview

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.

๐Ÿ“‹ SIM Card Setup Requirements

1. SIM Card Requirements

  • 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

2. Testing Your SIM Card

Before installation, test your SIM card in a phone to verify:

  • Network registration works
  • Data connectivity is functional
  • APN settings are correct

โš™๏ธ Advanced Configuration Options

Carrier-Specific APN Settings

// === 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

Connection Optimization Settings

#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)

๐Ÿš€ Enhanced Features

1. Automatic Reconnection

  • Automatically detects lost GPRS connections
  • Attempts reconnection with exponential backoff
  • Falls back to connection reset if needed

2. Connection Monitoring

  • Continuous health monitoring
  • Inactive connection detection
  • Preventive connection maintenance

3. Robust HTTP Handling

  • Automatic retry logic for failed requests
  • Proper error code handling
  • Enhanced JSON payload with metadata

4. Comprehensive Logging

  • Detailed connection status reporting
  • HTTP transaction logging
  • Error diagnosis information

๐Ÿงช Testing and Diagnostics

Connection Test Commands

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

Expected Test Output

=== 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 ===

๐Ÿ”ง Troubleshooting Common Issues

Issue: "GSM Network: No network connection"

Solutions:

  • Check antenna connection
  • Verify SIM card is properly inserted
  • Ensure SIM card is activated and has credit
  • Check signal strength in your area

Issue: "GPRS Status: Disconnected"

Solutions:

  • Verify APN settings for your carrier
  • Check if data plan is active
  • Try different APN from the list
  • Ensure sufficient signal strength (>10)

Issue: "Internet Test: FAILED"

Solutions:

  • Verify carrier data settings
  • Check for network restrictions
  • Try resetting the connection: RESET command
  • Contact carrier about data connectivity

Issue: "HTTP POST result: FAILED"

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)

โšก Power Management for SIM800L

Critical Power Requirements

  • 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

Power-Related Issues

  • Insufficient current causes connection drops
  • Voltage fluctuations cause module resets
  • Poor power supply affects signal quality

๐Ÿ” Security Considerations

SIM Card Security

  • Use SIM cards with secure profiles
  • Monitor for unauthorized usage
  • Implement data usage limits

API Security

  • Use HTTPS endpoints when possible
  • Implement API authentication
  • Validate device identifiers server-side

Network Security

  • Monitor for unusual network activity
  • Implement rate limiting on API endpoints
  • Use device certificates for enhanced security

๐Ÿ“Š Performance Optimization

Connection Optimization

  • Maintain persistent GPRS connections
  • Use connection pooling when possible
  • Implement smart retry algorithms

Data Optimization

  • Compress JSON payloads
  • Batch multiple updates when appropriate
  • Use efficient data formats

Power Optimization

  • Power down module during inactive periods (not implemented)
  • Optimize power consumption with comprehensive sleep modes
  • Optimize update frequencies (implemented via configurable intervals)

โœ… Troubleshooting Checklist

  1. Hardware Check

    • Antenna properly connected
    • SIM card inserted correctly
    • Power supply adequate (2A+)
    • Voltage stable (3.7V-4.2V)
  2. SIM Card Check

    • Data plan active
    • PIN code disabled
    • Network registration working
    • Sufficient credit/data allowance
  3. Configuration Check

    • Correct APN for carrier
    • Valid API URL
    • Proper timeout settings
    • Debug logging enabled
  4. Network Check

    • Signal strength >10
    • GPRS registration successful
    • Internet connectivity confirmed
    • API endpoint accessible
  5. Software Check

    • Latest firmware version
    • No compilation errors
    • Debug output showing proper flow
    • Error handling working correctly

๏ฟฝ Web API Integration Guide

๐Ÿ“ก API Endpoint Specification

HTTP POST Request

  • Endpoint: Your API URL (configured in APIConfig.h)
  • Method: POST
  • Content-Type: application/json
  • Expected Response: HTTP 200-299 for success

๐Ÿ“‹ Field Descriptions

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

๐Ÿ’ป Sample API Implementations

Node.js/Express Example

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');
});

Python/Flask Example

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 Example

<?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']);
}
?>

๐Ÿ—„๏ธ Database Schema Examples

MySQL/PostgreSQL Schema

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)
);

MongoDB Schema

// 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 });

๐Ÿงช Testing Your API

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"
}

๐Ÿ“ Basic GPS Tracking

void trackLocation() {
    if (gps.available()) {
        String nmea = gps.read();
        if (nmea.startsWith("$GPGGA")) {
            // Parse coordinates
            // Extract latitude/longitude
            // Store or transmit data
        }
    }
}

๐Ÿ“ฑ SMS Notifications

void sendAlert(String alertType) {
    String message = "BIKE ALERT: " + alertType + 
                    " Location: " + getCurrentLocation();
    gsm.sendSMS(OWNER_PHONE, message);
}

โšก Power Management

// 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
}

๐Ÿ” Troubleshooting

โœ… What's Fully Implemented and Working

GPS + GSM Core Features โœ…

  • 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

Hardware Features โœ…

  • LED status indication (requires LED on D8)
  • Buzzer alerts (requires buzzer on D7)
  • Pin configurations defined and implemented
  • Modular code architecture

โœ… Comprehensive Power Management System

Our streamlined GPS and GSM tracking system includes robust power management capabilities:

Sleep Mode Features โœ…

  • 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

Power Management Testing โœ…

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 mode
  • WAKE - Wake from sleep modes and resume normal operation

โ“ Common Issues

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

๐Ÿ› Debug Commands

// 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");

๐Ÿ“ž Support Resources

  • ๐Ÿ“ง Email: Create an issue on GitHub
  • ๐Ÿ“– Documentation: Check Wiki for detailed guides
  • ๐Ÿ’ฌ Community: Join discussions in Issues section

๐Ÿ“‹ Changelog

๐Ÿ”– Version 1.0.0 (Current) - Streamlined Implementation

โญ Core Features Implemented

  • โœ… 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

๐Ÿ”ง Architectural Improvements

  • โŒ 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

๐ŸŒ HTTP API Features

  • โœ… 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

๐Ÿ”ง System Architecture

  • โœ… 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

๐Ÿ›ก๏ธ Security & Reliability Features

  • โœ… 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

๐Ÿ“ฑ Communication Features

  • โœ… 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

๐Ÿ”‹ Power 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

๐Ÿ”ฎ Future Enhancements (v1.1.0)

  • ๐Ÿšง 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

๐Ÿ“ˆ Development Timeline

  • 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)

๐Ÿค Contributing

We welcome contributions from the community! Here's how you can help:

๐ŸŽฏ How to Contribute

  1. ๐Ÿด Fork the Repository

    git fork https://github.com/qppd/IoT-Bike-Tracker.git
  2. ๐ŸŒฟ Create Feature Branch

    git checkout -b feature/amazing-feature
  3. ๐Ÿ’พ Commit Changes

    git commit -m "Add amazing feature"
  4. ๐Ÿ“ค Push to Branch

    git push origin feature/amazing-feature
  5. ๐Ÿ”„ Open Pull Request

    • Describe your changes clearly
    • Include testing information
    • Reference any related issues

๐Ÿ“ Contribution Guidelines

  • Code Style: Follow Arduino/C++ conventions
  • Documentation: Update README and comments
  • Testing: Verify functionality before submission
  • Issues: Use templates for bug reports and features

๐Ÿ† Contributors

Thanks to all contributors who have helped improve this project!


๐Ÿ“„ License

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.

๐Ÿ™ Acknowledgments

๐ŸŽ–๏ธ Special Thanks

  • 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

๐Ÿ“š Resources & References

๐Ÿ› ๏ธ Development Tools

  • Arduino IDE - Primary development environment
  • Fritzing - Circuit design and documentation
  • Fusion 360 - 3D modeling and case design
  • VS Code - Documentation and advanced editing

๐Ÿšดโ€โ™‚๏ธ Happy Tracking! ๐Ÿšดโ€โ™€๏ธ

Built with โค๏ธ by qppd

GitHub Made with

About

An advanced, solar-powered GPS bike tracker with real-time location monitoring and GSM communication capabilities.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published