My Neo 6M gps doesnt works on hosted site but it works on localhost!

Hello I am making a gps device with esp8266 for web. when i try my code with localhost it works smoothly but when i try with my hosted site my gps device doesnt works,, gps device is GPS NEO 6M. it doest return any think... not even finds satelight,, please help me how to solve that!!

Here is the Hosted site code which doesnt works..

#include <TinyGPS++.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <SoftwareSerial.h>

  
TinyGPSPlus gps;
SoftwareSerial SerialGPS(4, 5); 

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

float Latitude , Longitude;
int id = 1;
String LatitudeString="0", LongitudeString="0";


WiFiServer server(80);
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());
}

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); 
        Serial.println(LongitudeString);      
      }
    }
  WiFiClient client;
  HTTPClient http;
  String serverPath = "http://******.org/api/locationUpdate/" + String(id) + "/" + LongitudeString + "/" + LatitudeString + "/3";
   
    http.begin(client, serverPath);
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
   
    int httpResponseCode = http.GET();
     
    if (httpResponseCode>0) {
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);   
        Serial.println(LongitudeString);  
    }
    else {
      Serial.print("Error code: ");
      Serial.println(httpResponseCode);
    }
    http.end();


  delay(200);

}

This one on localhost works very well..

#include <TinyGPS++.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <SoftwareSerial.h>

  
TinyGPSPlus gps;
SoftwareSerial SerialGPS(4, 5); 

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

float Latitude , Longitude;
int year , month , date, hour , minute , second, id = 1;
String DateString , TimeString , LatitudeString="0", LongitudeString="0";

const char* serverName = "http://192.168.43.254/lut2ms/sensor-data.php";
String apiKeyValue = "xxxxx";


WiFiServer server(80);
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());
}

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

    }
  WiFiClient client;
  HTTPClient http;
    http.begin(client, serverName);
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    
    String httpRequestData = "api_key=" + apiKeyValue + "&id=" + id
                          + "&latitude=" + LatitudeString + "&longitude=" + LongitudeString
                         + "&date=" + DateString + "&time=" + TimeString + "";
    
    int httpResponseCode = http.POST(httpRequestData);
     
    if (httpResponseCode>0) {
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
    }
    else {
      Serial.print("Error code: ");
      Serial.println(httpResponseCode);
    }
    http.end();


  delay(200);

}

Please help me solve this!! Do I need to add someting to the code to use it with hosted website or its similar as localhost?

What for it mean? What do you see?

I mean my Gps device (UBLOX NEO6M) doesnt work it doesnt even lights up with the top code, which is in a live website. but it works perfectly with the bottom code, which is in localhost. Do i have to do any thing extra for sending data in a live domain?
Its for vechile tracking purpose. To track a veichle. the device shoud send its location to the websites database.

You do have both GPSs outside with a good view of the sky ?

The delay(200) at the end of the loop is a bad idea, it will prevent you from getting your GPS Serial communication in time

At 9600 bauds you can get up to 960 chars in a second so ~190 characters can come in while you do nothing. The buffer is only 64 bytes deep so your GPS sentences might be severely impacted

Also the communication might be slower with a remote site which can lead as well to missing bytes

Delay ,might not be the issue cause i tried with 10000 milis it doesnt work! And on GPS sentences how to improve that??Thank You!!

Yes, It works on one code and doesnt works on other if it is hardware problem then it shouldn't work on both..I tried everything i this the error is in code.. how to solve that or how can i check what is causing the error? Thank you!!

Indeed, there is heaps of stuff going on in the program after a character is read from the GPS and encoded, including the dealy, so it would seem likely that characters will be missed, so no position decode.

You have a fundamental missunderstanding of how to read a GPS. The GPS puts out characters in a stream, and you have to read each and every one of about 60 characters, that are a complete NMEA sentence, to get a position decode.

There is a buffer in the 8266, so in theory you could wander off in the program doing other stuff for 64 characters at 9600baud, about 64mS, and still read all the characters in a sentence, but remember you cannot stop them comming.

You need to change the program so that it exclusivly reads the GPS (with a timeout) and keeps reading it until you get a gps.location.isUpdated(), then go off and do other stuff .......................

And maybe read up on the difference between gps.location.isValid() and gps.location.isUpdated()

http://arduiniana.org/libraries/tinygpsplus/

how is that a demonstration that delay is not the issue.... :roll_eyes: :hushed:

How much should i delay then?

Please tell me the process.. how can i make it working!! i need it done very badly, thanks1

no delay whatsoever.

structure the code so that you always get a chance to listen to the GPS as soon as possible and hope that the network activity won't take too long

1 Like

this blocking function

will screw up the GPS data being received on serial, switch to this instead ?

and you don't have to push data to your hosted server that fast ie: delay(200) ,

say at 2 seconds interval will be more than enough, using millis not delay() AND post data only when latitude or longitude gets changed

If your updating a Web page with locations etc, there is little point in updating the Web page data unless the location changes, and that only happens when the GPS library reports that the location has been updated.

So I would try something like this;

bool gpsWaitFix(uint32_t waitSecs)
{
  //waits a specified number of seconds for a fix, returns true for good fix
  uint32_t startmS, waitmS;
  bool GPSfix = false;
  uint8_t GPSchar;

  Serial.print(F("Wait GPS Fix "));
  Serial.print(waitSecs);
  Serial.println(F("s"));
  Serial.flush();                                        //so there are no Serial out interrupts to interfere with software serial

  waitmS = waitSecs * 1000;                              //convert seconds wait into mS
  startmS = millis();

  while ((uint32_t) (millis() - startmS) < waitmS)
  {
    if (GPSserial.available() > 0)
    {
      GPSchar = GPSserial.read();
      gps.encode(GPSchar);
      //Serial.write(GPSchar);                           //dont print GPS chars here if using software serial for GPS
    }

    if (gps.location.isUpdated() && gps.altitude.isUpdated())
    {
      GPSfix = true;
      Serial.println(F("Have GPS Fix "));

      TXLat = gps.location.lat();
      TXLon = gps.location.lng();
      TXAlt = gps.altitude.meters();
      TXSats = gps.satellites.value();

      Serial.print(TXLat, 5);
      Serial.print(F(","));
      Serial.print(TXLon, 5);
      Serial.print(F(","));
      Serial.print(TXAlt, 1);
      Serial.print(F(","));
      Serial.println(TXSats);
    }
    else
    {
      GPSfix = false;
    }
  }

  return GPSfix;
}

If you call it with something like this;

  if (gpsWaitFix(2))
  {
  //do have a fix stuff
  }
  else
  {
  //oh er - GPS appears not to be working
  }

You can then update the web page if the GPS has provided an updated location and also deal with the situation if the GPS appears to have stopped working.

thanks but i have solved the issue!! by stucturing the code again.. now i am having another problem the neo 6M doesnt connects to the satellight if i am in hogh crowded place (near buildings) but under open sky.. is there any way to change the antena of neo6m.. which antena should i prefer?

Depends on which Neo6M module you have, there are lots of different types.

Mine one is ublox NEO 6M. better antena for this one.. i dont know about other types..

Some modules 'NEO 6M' boards can accept different antennas, some not.

And you may already have the best antenna on that module, but how is the forum supposed to know ?

Do you have a camera ?


i am thinking of this antena