On-line vehicle tracking system

Published Oct 23, 2018
 10 hours to build
 Intermediate

I built a system which will track the location of a vehicle also shows a speed of vehicle on-line on Adafruit

display image

Components Used

GPS Receiver Module
GPS Receiver Module
1
ESP8266 WiFi Module
ESP8266 is a system on chip (SoC) which provides WIFI capability for embedded applications. This enables internet connectivity to embedded applications. ESP8266 modules are mostly used in Internet of Things(IoT) applications.
1
Description

Introduction

On-line vehicle tracking system track the location and speed of vehicle. It shows the real-time location and speed of vehicle on Dashboard created on Adafruit IO. For tracking location and speed GPS receiver is used. This tracking data send to the cloud using wi-fi module ESP8266.

Circuit Diagram

Vehicle Tracking using GPS & ESP8266 wifi Module

Project Working   

  • GPS module read the frame from satellites continuously. By reading this GPS information serially using MBED controller and extracted the required information like Latitude, Longitude, Speed, Altitude.
  • Latitude, Longitude, Speed, Altitude these parameters are calculated from valid frame(GPRMC, GPGGA NMEA string).
  • These tracking parameter along with vehicle speed are uploaded to Adafruit IO's Dashboard. On Adafruit Dashboard, we can see on-line vehicle tracking.
On-line vehicle tracking system

Latitude & Longitude Extraction

 if(sscanf(msg, "GPRMC,%f,%c,%f,%c,%f,%c,%f,%d", &time,&m, &latitude, &ns, &longitude, &ew,&speed, &lock) >= 1) {  
               { 
           if(!lock) { 
               longitude = 0.0; 
               latitude = 0.0;         
               return 0; 
           } else { 
               sscanf(msg,"GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%d", &time, &latitude1, &ns, &longitude1, &ew, &fq, &nst, &tst, &altitude); 
               if(ns == 'S') {    latitude  *= -1.0; } 
               if(ew == 'W') {    longitude *= -1.0; } 
               float degrees = trunc(latitude / 100.0f); 
               float minutes = latitude - (degrees * 100.0f); 
               latitude = degrees + minutes / 60.0f;     
               degrees = trunc(longitude / 100.0f); //* 0.01f); 
               minutes = longitude - (degrees * 100.0f); 
               longitude = degrees + minutes / 60.0f; 
  • In above code latitude and longitude converted in to degree and minutes and then using this degree and minutes latitude and longitude are calculated.

Speed Calculation

  • Speed given by GPS is in knots to convert it into kmph multiply it by 1.85.
 float a=gps.spd*1.85;         //converting speed in to kmph

Connect to Internet

  • System is connected to internet using ESP8266 wifi-module.
NetworkInterface* network = easy_connect(true); 
   if (!network) { 
       return -1; 
   }

Adafruit IO

  • System is connected to io.adafruit.com
const char* hostname = "io.adafruit.com"; 
   int port = 1883; 
   logMessage("Connecting to %s:%d\r\n", hostname, port); 
   int rc = mqttNetwork.connect(hostname, port); 
   if (rc != 0) 
       logMessage("rc from TCP connect is %d\r\n", rc);
data.clientID.cstring = "username/feed/name/csv"; 
   data.username.cstring = "username"; 
   data.password.cstring = "AIO key"; 
   if ((rc = client.connect(data)) != 0) 
       logMessage("rc from MQTT connect is %d\r\n", rc);
  • This data is published to adafruit using MQTT protocol.
//publishing latitude, longitude and altitude 
   char buf[200]; 
   sprintf(buf, "%f,%f,%f,%d",a,b,c,d); 
   message.qos = MQTT::QOS0; 
   message.retained = false; 
   message.dup = false; 
   message.payload = (void*)buf; 
   message.payloadlen = strlen(buf)+1; 
   rc = client.publish(topic, message); 
   output.printf("rc=%d",rc); 
    
 //Publishing speed     
   sprintf(buf,"%f",a); 
   message.qos = MQTT::QOS0; 
   message.retained = false; 
   message.dup = false; 
   message.payload = (void*)buf; 
   message.payloadlen = strlen(buf)+1; 
   rc = client.publish(topic1, message); 
   output.printf("rc=%d",rc);
 

Adafruit Dashboard

Video

 

Codes
Comments
Ad