0% found this document useful (0 votes)
10 views5 pages

GPS Tracker with SIM808 Integration

The document is a code for a GPS tracker using TinyGPSPlus and SIM808 modules. It initializes the GPS and SIM808, connects to a GPRS network, and sends GPS data (latitude, longitude, and speed) to a specified server. The loop continuously checks for valid GPS data and sends it to the server at regular intervals.

Uploaded by

awakurd2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

GPS Tracker with SIM808 Integration

The document is a code for a GPS tracker using TinyGPSPlus and SIM808 modules. It initializes the GPS and SIM808, connects to a GPRS network, and sends GPS data (latitude, longitude, and speed) to a specified server. The loop continuously checks for valid GPS data and sends it to the server at regular intervals.

Uploaded by

awakurd2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <TinyGPSPlus.

h>

#include <HardwareSerial.h>

TinyGPSPlus gps;

HardwareSerial gpsSerial(1); // TX=18, RX=19

HardwareSerial sim808(2); // TX=26, RX=27

const char* apn = "[Link]";

const char* vehicle_id = "car1";

const char* server = "[Link]

bool sendAT(String cmd, String expected, int timeout = 5000) {

[Link](cmd);

String resp = "";

long start = millis();

while (millis() - start < timeout) {

while ([Link]()) {

char c = [Link]();

resp += c;

if ([Link](expected) != -1) {

[Link]("✅ " + cmd);

return true;

[Link]("❌ " + cmd + " — Got: " + resp);


return false;

void setup() {

[Link](115200);

[Link](9600, SERIAL_8N1, 19, 18);

[Link](9600, SERIAL_8N1, 26, 27);

delay(3000);

[Link]("🚗 SIM808 + GPS Tracker Starting...");

sendAT("AT", "OK");

sendAT("ATE0", "OK");

sendAT("AT+CFUN=1", "OK");

sendAT("AT+CREG?", "0,1");

sendAT("AT+CSQ", "OK");

bool attached = false;

for (int i = 0; i < 5 && !attached; i++) {

attached = sendAT("AT+CGATT=1", "OK", 5000);

if (!attached) {

[Link]("⌛ Retrying GPRS attach...");

delay(3000);

if (!attached) {
[Link]("❌ Could not attach to GPRS");

return;

sendAT("AT+SAPBR=3,1,\"Contype\",\"GPRS\"", "OK");

sendAT("AT+SAPBR=3,1,\"APN\",\"" + String(apn) + "\"", "OK");

sendAT("AT+SAPBR=1,1", "OK", 10000);

delay(3000);

sendAT("AT+SAPBR=2,1", "OK");

[Link]("✅ Ready to send GPS data...");

void loop() {

while ([Link]()) [Link]([Link]());

if ([Link]() && [Link]()) {

double lat = [Link]();

double lon = [Link]();

double speed = [Link]();

[Link]("📡 Sending: lat=%.6f, lon=%.6f, speed=%.2f\n", lat, lon, speed);

String url = String(server);

url += "?vehicle_id=" + String(vehicle_id);

url += "&latitude=" + String(lat, 6);


url += "&longitude=" + String(lon, 6);

url += "&speed=" + String(speed, 2);

sendAT("AT+HTTPTERM", "OK", 2000); // Clean up old session

if (!sendAT("AT+HTTPINIT", "OK")) return;

if (!sendAT("AT+HTTPPARA=\"CID\",1", "OK")) return;

if (!sendAT("AT+HTTPPARA=\"URL\",\"" + url + "\"", "OK")) return;

if (!sendAT("AT+HTTPACTION=0", "+HTTPACTION: 0,200", 10000)) {

[Link]("❌ HTTP failed — check SIM/data/domain");

return;

sendAT("AT+HTTPREAD", "OK", 3000); // Optional: read server response

sendAT("AT+HTTPTERM", "OK", 2000);

[Link]("✅ GPS data sent to server\n");

} else {

[Link]("⌛ Waiting for GPS fix...");

delay(5000);

You might also like