Karoino
Published © GPL3+

Car tracking with Wemos D1 mini

Webserver based system shows Car Position with Google Maps

BeginnerShowcase (no instructions)2 hours251
Car tracking with Wemos D1 mini

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
TinyShield GPS
TinyCircuits TinyShield GPS
×1
LED (generic)
LED (generic)
×4
Resistor 100 ohm
Resistor 100 ohm
×1
Resistor 221 ohm
Resistor 221 ohm
×3

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Server-Files (PHP)

Schematics

Fritzing

Code

The Arduino Code

Arduino
#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
const char *ssid = "YOUR WLAN SSID";
const char *password = "YOUR WLAN PASSWORD";
const char *host = "YOURDOMAIN.com";// Domain only!
// !!!!!! 
//Change your Website-Password for POST on row 111 
//Change your URL for HTTP-Request on row 117

// GPS-MODUL
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps;
SoftwareSerial ss(4, 5);// GPIO4 und GPIO5 (PIN D1 und D2)
float latitude , longitude;
String lat_str , lng_str;

// Timer for Send Data:
unsigned long previousMillis = 0;
const long interval = 120000;//2-Min.Send to Server

//=======================================================================
//                    Setup
//=======================================================================
 
void setup() {
    //LEDs:
  pinMode(12, OUTPUT); digitalWrite(12, LOW);//LED an D6: Valid GPS Data
  pinMode(14, OUTPUT); digitalWrite(14, LOW);//LED an D5: Send to Server
  pinMode(16, OUTPUT); digitalWrite(16, LOW);//LED an D0: WLAN OK
  
  delay(1000);
  // Serial:
Serial.begin(115200);
  // CONNECT WLAN:
  WiFi.mode(WIFI_OFF);
  delay(1000);
  WiFi.mode(WIFI_STA); 
  WiFi.begin(ssid, password);
Serial.println(""); 
Serial.print("Connecting");
  // Wait for connection ...
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
Serial.print(".");
  }

Serial.println("");
Serial.print("Connected SSID: ");
Serial.println(ssid);
Serial.print("Lokal-IP: ");
Serial.println(WiFi.localIP());

  // SoftwareSerial:
  ss.begin(9600);
}
 
//=======================================================================
//                    Main Program Loop
//=======================================================================

void loop() {

  // WLAN is connected (for LED only)
  if (WiFi.status() != WL_CONNECTED)
  {
  digitalWrite(16, LOW);    
  }else{
   digitalWrite(16, HIGH);   
  }

  // GPS:
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
    { 
      if (gps.location.isValid())
      {
Serial.println("Location is valid ...");
digitalWrite(12, HIGH); 
        latitude = gps.location.lat();
        lat_str = String(latitude , 6);
Serial.print("LAT:");
Serial.println(lat_str);        
        longitude = gps.location.lng();
        lng_str = String(longitude , 6);
Serial.print("LNG:"); 
Serial.println(lng_str);       
      }else{
digitalWrite(12, LOW);        
      }
    }

// Millis for Send-Data-Function:
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    senddata(lat_str, lng_str);
    digitalWrite(14, HIGH);
    delay(500);
    digitalWrite(14, LOW);
    }
}

//=======================================================================
//                    Send Data to Server
//=======================================================================

void senddata(String lat_str, String lng_str){
  HTTPClient http;
  String pass, postData;
  pass = "YOUR WEBSITE PASSWORD";//for accept POST on gps.php on server
 
  postData = "gps_data_lat=" + lat_str + "&gps_data_lng=" + lng_str +"&pass=" + pass ;
  //Change the complete URL for HTTP-Request:
  http.begin("https://YOURDOMAIN.com/GPS/gps.php");
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
 
  int httpCode = http.POST(postData);
  String payload = http.getString();

Serial.print("............... Http-Code:");
Serial.println(httpCode);   //Print HTTP return code
Serial.print("............... Request Response:");
Serial.println(payload);    //Print request response
 
  http.end();  //Close connection  
}

Credits

Karoino

Karoino

0 projects • 0 followers

Comments

Add projectSign up / Login