Here is my code.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
// RaspPi Access Point w/ DHCP Login Cred
const char WiFiSSID[] = "TheAlamo";
const char WiFiPSK[] = "12345678";
const int LED_PIN = 5;
const int ANALOG_PIN = A0;
const char host[] = "192.168.4.1";
void setup()
{
pinMode(LED_PIN, OUTPUT);
pinMode(ANALOG_PIN, INPUT);
byte ledStatus = LOW;
WiFi.mode(WIFI_STA);
WiFi.begin(WiFiSSID, WiFiPSK);
while (WiFi.status() != WL_CONNECTED)
{
// Blink the LED
digitalWrite(LED_PIN, ledStatus); // Write LED high/low
ledStatus = (ledStatus == HIGH) ? LOW : HIGH;
delay(100);
}
digitalWrite(LED_PIN, HIGH);
}
void loop()
{
//for testing purposes set temp to a default value.
//int temp = analogRead(ANALOG_PIN);
int temp = 43;
digitalWrite(LED_PIN, LOW);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 8000;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
//temp variable is set with a function to check the temp of an DS18B20 sensor. Let me know if you need it
String data = "temp1=" + (String)temp;
// "temp1=" is what is going to be sent using GET to the apache server, see code in add.php
// We now create a URI for the request
String url = "GET /add.php?" + data + " HTTP/1.1";
client.println(url);
client.println("Host: 192.168.4.1");
client.println("Connection: close");
client.println();
delay(500);
//End of Send.
digitalWrite(LED_PIN, HIGH);
// 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);
}
client.stop(); //Stopping client
ESP.deepSleep(60U*60*1000000); //U for unsigned
delay(1000); //for above sleep
}
}
I'm not throwing any errors, which is good but makes it more difficult to debug.