NodeMCU board! I thought I had cracked it - but although my code now compiles and seems to work - it doesnt actually add to my database?
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <SPI.h>
// GPS Variables
static const int TXPin = 5; //(RX GPS -> D1(MCU)/TX(MCU)
static const int RXPin = 4; //(TX GPS -> D2(MCU)/RX(MCU)
static const uint32_t GPSBaud = 9600;
int i = 0, x = 0, loop1 = 0;
float latitude;
float longitude;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
//WiFi Variables
const char* ssid = "Pretty Fly for a Wifi";
const char* password = "!153Rolleston153!";
WiFiServer server(80);
//Server Variables
const char* host = "192.168.0.11";
WiFiClient client;
void setup()
{
//Starts GPS modules
Serial.begin(115200);
ss.begin(GPSBaud);
// Connect to WiFi network
connectwifi();
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
Serial.println("Setup Complete.");
}
void loop()
{
Serial.println("\nTest: ");
Serial.println(i);
delay(500);
while (ss.available() < 0)
{
}
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
if (gps.encode(ss.read()))
{
displayInfo();
}
else
{
Serial.println("Data not encoded");
}
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while (true);
}
i++;
if (x == 10)
while (1) {
Serial.println("LOOP STUCK");
}
}
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid())
{
latitude = gps.location.lat();
longitude = gps.location.lng();
Serial.print(gps.location.lat(), 6);
Serial.print(F(", "));
Serial.print(gps.location.lng(), 6);
if (client.connect(host, 80))
{
Serial.println("\nAdding to database...");
client.print("GET / send_data.php ? latitude = ");
client.print(latitude);
client.print("&longitude = ");
client.print(longitude);
client.println(" HTTP / 1.1");
client.println("Host : 192.168.0.11"); // SERVER ADDRESS
client.println( "Content - Type : text / php" );
client.println("Connection : close");
client.println();
client.println();
x++;
}
delay(5000);
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}
void connectwifi() {
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("\nAttempting to Connect..");
}
//Acknowledge the connection
Serial.println("");
Serial.printf("\nConnected to the host : % s...", host);
}