Skip to content

ESP8266 softAP webserver with GPS is not working.  #5970

Open
@amissu89

Description

@amissu89

Settings in IDE

  • Module: Nodemcu
  • Upload Using: SERIAL
  • Upload Speed: 9600

Problem Description

When I launching only ESP8266WebServer with softAP mode, it works fine.
(I could see the webpage I made.)
When I checking only gps data with TinyGPS library, it works fine.

But When I add reading gps data function to my webserver routine, it doesn't work.
``

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>

//server setting
const char* ssid = "uuuu";
const char* password = "123456789";
ESP8266WebServer server(80);

//GPS setting
#define RXPIN 14
#define TXPIN 12
#define GPSBAUD 9600

TinyGPS gps;
SoftwareSerial ss(TXPIN, RXPIN);
float flat=0, flon=0;
String strDate = "";

void handleRoot() {
    server.send(200, "text/html", prepareHtmlPage());
}

String prepareHtmlPage()
{
   String htmlPage =
     String("<!DOCTYPE HTML>") +
            "<html>" +
            "<meta http-equiv=\"Content-Type\" Content=\"text/html; charset=utf-8\">\r\n" +
            "<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">\r\n"+
            "<style>body {margin: 0;font-family: Arial, Helvetica, sans-serif;}\r\n"+
            ".topnav {overflow: hidden;background-color: #333;}\r\n"+
            ".topnav a {float: left;color: #f2f2f2;text-align: center;padding: 14px 16px;text-decoration: none;font-size: 17px;}\r\n"+
            ".topnav a:hover {background-color: #ddd;color: black;}</style></head>\r\n"+
            "<body onload='status1()'>\r\n"+
            "<div class='topnav'>\r\n"+
            "<a class='active' href='#home' onclick='status1()'>현재 상태</a><a href='#about' onclick='about()'>About</a>\r\n" +
            "</div><div id='content' style='padding-left:16px'></div></body>\r\n"+
            "<div id='btm'> <input type='button' onclick='location.reload(true)' value='Refresh'> </div>\r\n"+
            "<script>\r\n"+
            "function status1()\r\n"+
            "{var str = '<h3>current : sss </h3>'\r\n;"+
            "str += '<h3> Lat, Lon : dsd </h3>'\r\n;" +
            //"{var str = '<h3>current : " + strDate + "</h3>'\r\n;"+
            //"str += '<h3> Lat, Lon : " + flat + ", " + flon + "</h3>'\r\n;" +
            "document.getElementById('btm').style.display='block'\r\n"+
            "document.getElementById('content').innerHTML = str; }\r\n"+
            "function about()\r\n"+
            "{var str = '<h2>water</h2>';\r\n"+
            "str += '<p> xxxx : xxxx </p>';str += '<p> HP : xxxxxx </p>';\r\n"+
            "document.getElementById('btm').style.display='none'\r\n"+
            "document.getElementById('content').innerHTML = str;}\r\n"+
            "</script>\r\n"+
            "</html>\r\n" +
            "\r\n";
  Serial.println(htmlPage);
  return htmlPage;
}

void setup() {
  // put your setup code here, to run once:
  delay(10);
  Serial.begin(115200);
  //ss.begin(GPSBAUD);

  Serial.println("Initializing Soft AP Config mode...");
  IPAddress Ip(192, 168, 20, 1);
  IPAddress NMask(255, 255, 255, 0);

  WiFi.softAPConfig(Ip, Ip, NMask);
  
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.begin();
  Serial.println("HTTP server started");
  
}

void loop() {
  // put your main code here, to run repeatedly:
  server.handleClient();
  bool newData = false;
  unsigned long chars;
  unsigned short sentences, failed;

  // For one second we parse GPS data and report some key values
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (ss.available())
    {
      char c = ss.read();
       //Serial.write(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
        newData = true;
    }
  }

  if (newData)
  {
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    Serial.print(" LAT=");
    Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    Serial.print(" LON=");
    Serial.println(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
   }
  
  gps.stats(&chars, &sentences, &failed);
  if (chars == 0)
    Serial.println("** No characters received from GPS: check wiring **");
}

And then.

  1. I couldn't find wifi in my wifi list in laptop.
  2. I could check normal GPS data.

So When I comment line below "server.handleClient();", I could find nodeMCU wifi and open
web page what I made.

I think this problem related with SoftwareSerial and handclient().
I'm not sure...

Please help me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions