Hello,
I'm looking for some help to solve my problem, I would like sending GPS Data over ESP8266 Module to Dweet.io
The ESP with Arduino Code :
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <TinyGPS.h>
static const int RXPin = 2, TXPin = 3;
TinyGPS gps;
SoftwareSerial ss(RXPin, TXPin);
const char* ssid = "MyNET";
const char* password = "TCRT877441";
const char* host = "dweet.io";
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
float flat, flon;
void setup() {
ss.begin(9600);
Serial.begin(9600);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
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());
}
void loop() {
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
String url = "/dweet/for/RPI";
url += "?Lat=";
url += String(flat, 6);
url += "&Long=";
url += String(flon, 6);
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
delay(5000);
}
And the GPS Call
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (ss.available())
{
if (gps.encode(ss.read()))
{
gps.f_get_position(&flat, &flon);
Serial.print("LAT=");
Serial.println(flat,6);
Serial.print("LON=");
Serial.println(flon,6);
}
}
}
How I can integrate correctly the GPS Call with the principal code because all the time it return 0 and there's something wrong I don't found it to make the good call for Lat and Long,
Thanks for helping