I am learning and trying to send data to a php file to then insert in a html page. I know the ESP8266 is working because I was able to send data to favoriot. I made a php file (ESP.php) and a blank html file (ESPdisplay.html).
<?php $Temp=$_POST["temperature"] ; // create a variable that will receive $WindSpKph=$_POST["windSpeed"] ; // create a variable that will receive the temperature $Write="Temperature: " .$Temp. " Celcius
" ; // create a variable that will receive the wind $Write="Wind speed: " .$WindSpKph. " kph
"; // create an HTML file to display the data within File_put_contents ('ESPdisplay.html',$Write); ?>#include <SPI.h>
#include <ESP8266WiFi.h>
char ssid[] = "??????????"; // change it!
char pass[] = "???????????"; // change it!
int status = WL_IDLE_STATUS;
WiFiClient client;
void setup() {
Serial.begin(115200);
WiFi.disconnect();
Serial.println("Start connecting");
WiFi.begin(ssid,pass);
while((!(WiFi.status() == WL_CONNECTED))){
delay(300);
Serial.print("...");
}
Serial.println(WiFi.status());
Serial.println("Connected");
Serial.println("");
}
void loop() {
String data = "temperature=25&windSpeed=6";
Serial.println(data);
if (client.connect("www.blackkitty.com.au", 80)) {
//Serial.println("client connected");
client.println("POST /esp.php HTTP/1.1");
client.println("Host: www.blackkitty.com.au");
client.println("Connection: close");
client.print("Content-Length: ");
int thisLength = data.length();
//int thisLength = 26;
client.println(thisLength);
Serial.print("Content-Length: ");
Serial.println(thisLength);
client.println(data);
}
while (client.available()) {
char c = client.read();
Serial.write(c);
}
if (!client.connected()) {
client.stop();
}
delay(5000);
}