So I've tested the server side and it is solid. Bolted on a little bit more to the previously posted PHP code. Now if you add this after the PHP tags.
<HTML>
<HEAD>
<meta http-equiv="refresh" content="5">
</HEAD>
<BODY>
</BODY>
</HTML>
The page will refresh itself every 5 seconds. Makes it easier to monitor if data is coming through. I have a 2nd computer connected to the server constantly updating to see how data transmission is going.
Now I've tested the server using some Java test code available here: https://www3.ntu.edu.sg/home/ehchua/programming/webprogramming/HTTP_Basics.html
I also pushed data from my 2nd computer to the server using "192.168.4.1/data.php?temp1=33" something to that effect and it does receive it and display it. What I can't seem to get is the microcontroller to send data. It connects and gets an IP address on the network but data does not transmit !
#include <ESP8266WiFi.h>
//Raspberry Pi Login Credentials.
const char WiFiSSID[] = "Alamo";
const char WiFiPSK[] = "12345678";
//Pin Definitions
const int LED_PIN = 5;
const int ANALOG_PIN = A0;
//Variables
const char host[] = "192.168.44.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);
}
}
void loop()
{
//for testing purposes set temp to a default value.
//int temp = analogRead(ANALOG_PIN);
int temp = 43;
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
digitalWrite(LED_PIN, HIGH);
Serial.println("connection failed");
return;
}
String data = "temp1=" + (String)temp;
String url = "GET /data.php?" + data + " HTTP/1.1";
client.println(url);
client.println("Host: 192.168.44.1");
client.println("Connection: close");
client.println();
client.flush();
delay(500);
//End of Send.
digitalWrite(LED_PIN, HIGH);
delay(100);
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
client.stop(); //Stopping client
//Deep sleep not necessary for testing
//ESP.deepSleep(60U*60*1000000); //U for unsigned
delay(100); //for above sleep
}
What do you guys think? Where is my code faulty?