Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Marnix
#47685 Hi all, thanks in advance for any help. I have a Sprint Wifi hotspot with a built-in GPS that I got from Freedompop. I want to read the GPS data from the hotspot on my ESP8266. There are two ways that may work

1. Parse the landing page of the device at http://192.168.0.1, deep in the HTML the lat/lon are coded. This feels slow and above the capabilities of the ESP8266 without having something more powerful available

2. If I navigate my laptop browser to http://sprinthotspot:5502, I will get the data in NMEA format like this every few seconds:

$GPGSV,3,1,10,03,35,292,22,22,42,258,16,31,65,029,16,32,35,125,14*71
$GPGSV,3,2,10,14,42,118,,16,28,202,,23,10,307,,25,16,042,*7D
$GPGSV,3,3,10,26,59,192,,29,21,073,*76
$GPGGA,140359.1,4045.576754,N,07358.430937,W,1,03,666.6,-4.7,M,,,,*3F
$GPVTG,,T,,M,,N,,K,N*2C
$GPRMC,140359.1,A,4045.576754,N,07358.430937,W,,,190516,,,A*79
$GPGSA,A,3,03,22,31,,,,,,,,,,666.6,666.6,666.6*33
$PSTIS,*61

Image
I have tried the code below

Code: Select all#include <ESP8266WiFi.h>

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

void setup() {
  Serial.begin(115200);
  delay(10);

  // We start by connecting to a WiFi network

  Serial.println();
  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"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

int value = 0;

void loop() {
  delay(5000);
  ++value;

  Serial.print("connecting to ");
  Serial.println(host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 5502;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

 
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
 
  Serial.println();
  Serial.println("closing connection");
} - See more at: http://www.esp8266.com/viewtopic.php?p=13806


but it doesn't seem to be able to connect to 5502, only port 80, and I get "connection failed" if I set the port to 5502.

Any thoughts or help great appreciated!
User avatar
By ajaybnl
#47768
martinayotte wrote:After having done the client.connect(), you need to send a HTTP GET request and wait for its response.


True

Code: Select all/**
 * BasicHTTPClient.ino
 *
 *  Created on: 24.05.2015
 *
 */

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;

void setup() {

    USE_SERIAL.begin(115200);
   // USE_SERIAL.setDebugOutput(true);

    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();

    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }

    WiFiMulti.addAP("SSID", "PASSWORD");

}

void loop() {
    // wait for WiFi connection
    if((WiFiMulti.run() == WL_CONNECTED)) {

        HTTPClient http;

        USE_SERIAL.print("[HTTP] begin...\n");
        // configure traged server and url
        //http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS
        http.begin("http://192.168.1.12/test.html"); //HTTP

        USE_SERIAL.print("[HTTP] GET...\n");
        // start connection and send HTTP header
        int httpCode = http.GET();

        // httpCode will be negative on error
        if(httpCode > 0) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

            // file found at server
            if(httpCode == HTTP_CODE_OK) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
            USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }

        http.end();
    }

    delay(10000);
}

User avatar
By Marnix
#47777 Got it working, but didn't need to send any GET commands as the data was just streaming from that port. For posterity, here is the code that I'm using to:

1. read NMEA data from a Sierra Wireless 4G LTE Hotspot over port 5502
2. parse it using TinyGPS++ (this is inefficient, I'm sure I could have figured out a way to read/parse in one go but was having issues getting it to work directly on the wifi stream)
3. Send this data to dweet.io to track and display on freeboard

Code: Select all#include <TinyGPS++.h>
#include <ESP8266WiFi.h>

const char* ssid     = "my-ssid";
const char* password = "my-password";
const char* gps_host = "192.168.0.1"; //Hotspot homepage
const char* data_host = "dweet.io";   //Send data to dweet.io
const char* dweet_line = "/dweet/for/[my thing name]";

TinyGPSPlus gps;


void setup() {
  Serial.begin(115200);
  delay(10);

  // We start by connecting to a WiFi network

  Serial.print("Connecting to WiFi: ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

int value = 0;

void loop() {
  delay(5000);
  ++value;

  Serial.print("Connecting to GPS host: ");
  Serial.println(gps_host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
 
  const int gps_httpPort = 5502; //I found the hotspot transmitting NMEA sentences on this port
  if (!client.connect(gps_host, gps_httpPort)) {
    Serial.println("connection failed");
    return;
  }
   if (client.connect(gps_host, gps_httpPort)) {
    Serial.println("connection succeeded");
  }
               
  bool found = false; //Set flag to see if I've hit the NMEA sentence I want
  String NMEAline = "";
  while(!found){
   NMEAline = client.readStringUntil('\r'); //Read one line of the NMEA output
    if(NMEAline.startsWith("GPRMC",2)){ //Check if it is the GPRMC one which contains the info I want
     Serial.println(NMEAline); //Print it out over serial
      found = true;
    }
  }
    for (int i = 0; i < NMEAline.length(); i++) {
    gps.encode(NMEAline.charAt(i)); //Feed the NMEA sentence into TinyGPS++, probably a more elegant way to do this
  }
   //Output the data
Serial.print("LAT=");  Serial.println(gps.location.lat(), 6);
Serial.print("LONG="); Serial.println(gps.location.lng(), 6);
Serial.print("ALT=");  Serial.println(gps.altitude.meters());
  if (gps.location.lat() == 0) return;
 
  Serial.println();
  Serial.println("closing gps connection");
  client.stop();
 
  const int data_httpPort = 80; //Switch to port 80 for dweet
  if (!client.connect(data_host, data_httpPort)) {
    Serial.println("connection failed");
    return;
  }
   Serial.println("sending data...");
  //Send the data to Dweet.io
  client.print("GET " + String(dweet_line) + "?lat=" + String(gps.location.lat(), 6) + "&lon=" +  String(gps.location.lng(), 6) + " HTTP/1.1\r\n" +
               "Host: " + data_host + "\r\n" +
               "Connection: close\r\n\r\n");
    Serial.println("closing data connection");
  client.stop();
}