DIY Tracker Device for Traccar

smartguy2 months ago

I have wired up a Tracker device with Arduino, neo-6m module and SIM800l GSM Module. When I use the Osmand protocol to push latlong to demo4.traccar.org it fails with error code 705. If I use api.thingspeak.com/update?api_key=XXXXXXX&field1=15.6&field2=70.33 it works flawlessly. If anybody is interested i can share the arduino code.

Luis123138262 months ago

Yes, please.

smartguy2 months ago
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include "SIM800L.h"
TinyGPSPlus gps;
//SoftwareSerial SerialGPS(4, 5);
SoftwareSerial SerialGPS(D2, D1);
#define SIM800_RX_PIN D6
#define SIM800_TX_PIN D5
#define SIM800_RST_PIN D7

const char* ssid = "VJS";
const char* password = "arduino20689";

float Latitude, Longitude;
int year, month, date, hour, minute, second;
String DateString, TimeString, LatitudeString, LongitudeString;
const char APN[] = "airtelgprs.com";

WiFiServer server(80);
SIM800L* sim800l;
void setup() {
  Serial.begin(9600);
  SerialGPS.begin(9600);
  Serial.println();
  Serial.print("Connecting");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  server.begin();
  Serial.println("Server started");
  Serial.println(WiFi.localIP());
  Serial.println(SerialGPS.available());
  SoftwareSerial* serial = new SoftwareSerial(SIM800_RX_PIN, SIM800_TX_PIN);

  //SoftwareSerial GSMSerial(SIM800_RX_PIN, SIM800_TX_PIN);
  serial->begin(9600);
  delay(1000);
  //Serial.println(SerialGPS.available());
  // Initialize SIM800L driver with an internal buffer of 200 bytes and a reception buffer of 512 bytes, debug disabled
  //sim800l = new SIM800L((Stream*)serial, SIM800_RST_PIN, 200, 512);
  sim800l = new SIM800L(serial, SIM800_RST_PIN, 200, 512);

  // Equivalent line with the debug enabled on the Serial
  // sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 200, 512, (Stream *)&Serial);

  // Setup module for GPRS communication
  setupModule();
}

void loop() {

  while (SerialGPS.available() > 0)
 
    if (gps.encode(SerialGPS.read())) {
      if (gps.location.isValid()) {
        Latitude = gps.location.lat();
        LatitudeString = String(Latitude, 6);
        Longitude = gps.location.lng();
        LongitudeString = String(Longitude, 6);
      }

      if (gps.date.isValid()) {
        DateString = "";
        date = gps.date.day();
        month = gps.date.month();
        year = gps.date.year();

        if (date < 10)
          DateString = '0';
        DateString += String(date);

        DateString += " / ";

        if (month < 10)
          DateString += '0';
        DateString += String(month);
        DateString += " / ";

        if (year < 10)
          DateString += '0';
        DateString += String(year);
      }

      if (gps.time.isValid()) {
        TimeString = "";
        hour = gps.time.hour() + 5;  //adjust UTC
        minute = gps.time.minute();
        second = gps.time.second();

        if (hour < 10)
          TimeString = '0';
        TimeString += String(hour);
        TimeString += " : ";

        if (minute < 10)
          TimeString += '0';
        TimeString += String(minute);
        TimeString += " : ";

        if (second < 10)
          TimeString += '0';
        TimeString += String(second);
      }
    }
  Serial.print(Latitude, 8);
  Serial.print(Longitude, 8);
  char url[300];
  Serial.println(SerialGPS.available());
  sprintf(url, "api.thingspeak.com/update?api_key=EU5P7FRH1QYEHZ2K&field1=%f&field2=%f", Latitude, Longitude);
  //sprintf(url, "http://demo4.traccar.org:5055/?id=9999&lat=%s&lon=%s&timestamp=1609459200000", dtostrf(gps.location.lat(), 5, 2, buflat), dtostrf(gps.location.lng(), 5, 2, buflon));
  Serial.println(url);
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  //Response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n <!DOCTYPE html> <html> <head> <title>NEO-6M GPS Readings</title> <style>";
  s += "table, th, td {border: 1px solid blue;} </style> </head> <body> <h1  style=";
  s += "font-size:300%;";
  s += " ALIGN=CENTER>NEO-6M GPS Readings</h1>";
  s += "<p ALIGN=CENTER style="
       "font-size:150%;"
       "";
  s += "> <b>Location Details</b></p> <table ALIGN=CENTER style=";
  s += "width:50%";
  s += "> <tr> <th>Latitude</th>";
  s += "<td ALIGN=CENTER >";
  s += LatitudeString;
  s += "</td> </tr> <tr> <th>Longitude</th> <td ALIGN=CENTER >";
  s += LongitudeString;
  s += "</td> </tr> <tr>  <th>Date</th> <td ALIGN=CENTER >";
  s += DateString;
  s += "</td></tr> <tr> <th>Time</th> <td ALIGN=CENTER >";
  s += TimeString;
  s += "</td>  </tr> </table> ";


  if (gps.location.isValid()) {
    s += "<p align=center><a style="
         "color:RED;font-size:125%;"
         " href="
         "http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=";
    s += LatitudeString;
    s += "+";
    s += LongitudeString;
    s += ""
         " target="
         "_top"
         ">Click here</a> to open the location in Google Maps.</p>";
  }

  s += "</body> </html> \n";

  client.print(s);
  delay(100);
  bool connected = false;
  for (uint8_t i = 0; i < 5 && !connected; i++) {
    delay(1000);
    Serial.print("*");
    connected = sim800l->connectGPRS();
  }

  // Check if connected, if not reset the module and setup the config again
  if (connected) {
    Serial.print(F("GPRS connected with IP "));
    Serial.println(sim800l->getIP());
  } else {
    Serial.println(F("GPRS not connected !"));
    Serial.println(F("Reset the module."));
    //sim800l->reset();
    setupModule();
    return;
  }

  Serial.println(F("Start HTTP GET..."));



  uint16_t rc = sim800l->doGet(url, 20000);
  if (rc == 200) {
    // Success, output the data received on the serial
    Serial.print(F("HTTP GET successful ("));
    Serial.print(sim800l->getDataSizeReceived());
    Serial.println(F(" bytes)"));
    Serial.print(F("Received : "));
    Serial.println(sim800l->getDataReceived());
  } else {
    // Failed...
    Serial.print(F("HTTP GET error "));
    Serial.println(rc);
  }

  delay(1000);

  // Close GPRS connectivity (5 trials)
  bool disconnected = sim800l->disconnectGPRS();
  for (uint8_t i = 0; i < 5 && !connected; i++) {
    Serial.print(".");
    delay(1000);
    disconnected = sim800l->disconnectGPRS();
  }

  if (disconnected) {
    Serial.println(F("GPRS disconnected !"));
  } else {
    Serial.println(F("GPRS still connected !"));
  }

  // Go into low power mode
  bool lowPowerMode = sim800l->setPowerMode(MINIMUM);
  if (lowPowerMode) {
    Serial.println(F("Module in low power mode"));
  } else {
    Serial.println(F("Failed to switch module to low power mode"));
  }

  // End of program... wait...
  delay(5000);
}
void setupModule() {
  // Wait until the module is ready to accept AT commands
  while (!sim800l->isReady()) {
    Serial.println(F("Problem to initialize AT command, retry in 1 sec"));
    delay(1000);
  }
  Serial.println(F("Setup Complete!"));

  // Wait for the GSM signal
  uint8_t signal = sim800l->getSignal();
  for (uint8_t j = 0; j < 5 && signal <= 0; j++) {
    //while (signal <= 0) {
    Serial.print("*");
    delay(1000);
    signal = sim800l->getSignal();
  }
  Serial.print(F("Signal OK (strength: "));
  Serial.print(signal);
  Serial.println(F(")"));
  delay(1000);
  int k = 0;
  // Wait for operator network registration (national or roaming network)
  NetworkRegistration network = sim800l->getRegistrationStatus();
  while (network != REGISTERED_HOME && network != REGISTERED_ROAMING && k < 5) {
    Serial.print("#");
    delay(1000);
    network = sim800l->getRegistrationStatus();
    k++;
  }
  Serial.println(F("Network registration OK"));
  delay(1000);

  // Setup APN for GPRS configuration
  bool success = sim800l->setupGPRS(APN);
  while (!success) {
    success = sim800l->setupGPRS(APN);
    delay(5000);
  }
  Serial.println(F("GPRS config OK"));
}
smartguy2 months ago
Luis123138262 months ago
const char* ssid = "VJS";
const char* password = "arduino20689";

The wifi connection is provided locally or is part of the 800l sim

smartguy2 months ago

Sorry I forgot to mention that I am using a Wemos D1 mini (I had a few lying around hence used one) and the setup has a local webserver also. You can remove the webserver code if you dont need it. I will post the PCB I designed later after I etch the PCB, assemble and test it.

Luis123138262 months ago

Please keep me informed

smartguya month ago

Have you tried the code? Let me know how it goes.

Luis12313826a month ago

I'm trying with the esp32, neo6m and sim800lv2 but I can't send data to the server

smartguya month ago

First try if you are getting the data from neo-6m and then check if the sim800l is connecting to the GPRS network. Thus you can isolate the problem.

smartguya month ago

Are you trying push the data to demo4.traccar.org or thingspeak.com? I could not push it to demo4.traccar.org hence posted it on this forum.