What's new

C & C++ GPS data not showing on my web server

PHC-Shade

Honorary Poster
Established
Joined
Oct 23, 2018
Posts
480
Solutions
1
Reaction
222
Points
240
Hello, everyone. I'm working on a project with two systems, and my board is the ESP8266. The 1st system is the mq9 gas sensor, and the second is the ublox neo6mv2 gps. The gas sensor works fine, but the GPS web server is not displaying any data. Here's my code for it


Code:
#define sensor A0

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


TinyGPSPlus gps;

SoftwareSerial ss(4, 5);

const char* ssid = "realme 9";

const char* password = "realme123";

float latitude , longitude;

int year , month , date, hour , minute , second;

String date_str , time_str , lat_str , lng_str;

int pm;

int green_led = 14;
int yellow_led = 12;
int red_led = 13;


WiFiServer server(80);

void setup()

{
  pinMode(sensor, INPUT);
  pinMode(green_led, OUTPUT);
  pinMode(yellow_led, OUTPUT);
  pinMode(red_led, OUTPUT);

  Serial.begin(9600);

  ss.begin(9600);

  Serial.println();

  Serial.print("Connecting to ");

  Serial.println(ssid);

  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()

{
  int value = analogRead(sensor);

  Serial.print("Value: ");
  Serial.println(value);
  delay(1000);
 
    if (value < 199) {
    digitalWrite(green_led, LOW);
    digitalWrite(yellow_led, LOW);
    digitalWrite(red_led, LOW);
  } else if(value >= 200 && value <299) {
    digitalWrite(green_led, HIGH);
    digitalWrite(yellow_led, LOW);
    digitalWrite(red_led, LOW);

  } else if(value >= 300 && value < 499) {
    digitalWrite(green_led, LOW);
    digitalWrite(yellow_led, HIGH);
    digitalWrite(red_led, LOW);
  } else if (value > 500) {
    digitalWrite(green_led, LOW);
    digitalWrite(yellow_led, LOW);
    digitalWrite(red_led, HIGH);
  }

  while (ss.available() > 0)

    if (gps.encode(ss.read()))

    {

      if (gps.location.isValid())

      {

        latitude = gps.location.lat();

        lat_str = String(latitude , 6);

        longitude = gps.location.lng();

        lng_str = String(longitude , 6);

      }

      if (gps.date.isValid())

      {

        date_str = "";

        date = gps.date.day();

        month = gps.date.month();

        year = gps.date.year();

        if (date < 10)

          date_str = '0';

        date_str += String(date);

        date_str += " / ";

        if (month < 10)

          date_str += '0';

        date_str += String(month);

        date_str += " / ";

        if (year < 10)

          date_str += '0';

        date_str += String(year);

      }

      if (gps.time.isValid())

      {

        time_str = "";

        hour = gps.time.hour();

        minute = gps.time.minute();

        second = gps.time.second();

        minute = (minute + 30);

        if (minute > 59)

        {

          minute = minute - 60;

          hour = hour + 1;

        }

        hour = (hour + 5) ;

        if (hour > 23)

          hour = hour - 24;


        if (hour >= 12)

          pm = 1;

        else

          pm = 0;

        hour = hour % 12;


        if (hour < 10)

          time_str = '0';

        time_str += String(hour);

        time_str += " : ";

        if (minute < 10)

          time_str += '0';

        time_str += String(minute);

        time_str += " : ";

        if (second < 10)

          time_str += '0';

        time_str += String(second);

        if (pm == 1)

          time_str += " PM ";

        else

          time_str += " AM ";

      }

    }

  WiFiClient client = server.available();

  if (!client)

  {

    return;

  }


  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n <!DOCTYPE html> <html> <head> <title>GPS Interfacing with NodeMCU</title> <style>";

  s += "a:link {background-color: YELLOW;text-decoration: none;}";

  s += "table, th, td {border: 1px solid black;} </style> </head> <body> <h1  style=";

  s += "font-size:300%;";

  s += " ALIGN=CENTER> GPS Interfacing with NodeMCU</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 += lat_str;

  s += "</td> </tr> <tr> <th>Longitude</th> <td ALIGN=CENTER >";

  s += lng_str;

  s += "</td> </tr> <tr>  <th>Date</th> <td ALIGN=CENTER >";

  s += date_str;

  s += "</td></tr> <tr> <th>Time</th> <td ALIGN=CENTER >";

  s += time_str;

  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 += lat_str;

    s += "+";

    s += lng_str;

    s += """ target=""_top"">Click here!</a> To check the location in Google maps.</p>";

  }

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

  client.print(s);

  delay(1000);

}



also, I have tried to use code solely for the GPS, and it displays the data on the web server. What seems to be the problem of it

Here's my output too

You do not have permission to view the full content of this post. Log in or register now.
 
From your code, it seems like you are trying to read GPS data from the u-blox NEO-6M GPS module using SoftwareSerial and display the GPS location details on a web server hosted on the ESP8266 board. The issue you are facing is that the GPS data is not being displayed on the web server.

Looking at your code snippet, it appears that the logic for reading GPS data and constructing the HTML response to be sent to the client seems correct. However, there are a few potential issues that might be causing the problem:

1. Check GPS Connection: Ensure that the u-blox NEO-6M GPS module is properly connected to the ESP8266 board and is transmitting data correctly. You can try running a simple GPS data reading code to verify if the GPS module is functioning as expected.

2. Data Parsing: Make sure that the GPS data parsing logic is working correctly. Check if the GPS data is being successfully parsed and stored in the lat_str, lng_str, date_str, and time_str variables.

3. HTML Response: Verify the HTML response being constructed in the String s. Make sure the HTML tags are properly formatted and closed. You can print the s string to the Serial Monitor for debugging purposes.

4. Client Handling: Ensure that the client connection is being properly handled. Check if the client is successfully connecting to the server and receiving the HTML response.

5. Timing and Delays: The delay(1000) in the loop() function might cause delays in handling client connections and reading GPS data. Consider using non-blocking techniques like millis() for timing instead of delay().

6. Debugging: Add debug statements throughout your code to check the flow and values of variables during execution. This will help in identifying any potential issues in the code logic.

By addressing these points and debugging your code step by step, you should be able to identify the root cause of why the GPS data is not being displayed on the web server. Let me know if you need further assistance or if you have any specific error messages or debug output to share.
 

Similar threads

Back
Top