I accidentally deleted my previous post while editing his (just the way things are going for me now)
SO a quick rundown. I’m a complete beginner to HTML and PHP, I’m trying to post data from my Arduino over WiFi to a table on my webpage. I’m making a POST request, as you can see in my Ardunio code, to my index.php. My understanding, which is not much, is that the php code I slipped into index.php should respond to the request and store the value of “Temperature” to a variable and then echo it to the webpage at the position where I slipped in the php code.
I wanted to post data to a mySQL table and then take the data from there to post onto my webpage, but I had no luck. At this stage I just want to be able to do this basic process.
Here is a snapshot of my webpage and the table I’m trying to poste data to:
.
.
.
EDIT
Full Arduino code:
/*
WiFiEsp example: WebClient
This sketch connects to google website using an ESP8266 module to
perform a simple web search.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-client.html
*/
#include "WiFiEsp.h"
char ssid[] = "vodafone-43C5"; // wireless network name
char pass[] = "*****"; // wireless password
int status = WL_IDLE_STATUS;
char server[] = "markrigz.000webhostapp.com";
// This is the data that will be passed into your POST and matches your mysql column
int yourarduinodata = 999;
String yourdatacolumn = "Temperature=";
String yourdata;
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
// you're connected now, so print out the data
Serial.println("You're connected to the network");
printWifiStatus();
Serial.println();
Serial.println("Starting connection to server...");
}
void loop()
{
postData();
delay(2000);
}
void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void postData() {
// Combine yourdatacolumn header (yourdata=) with the data recorded from your arduino
// (yourarduinodata) and package them into the String yourdata which is what will be
// sent in your POST request
yourdata = yourdatacolumn + yourarduinodata;
// If there's a successful connection, send the HTTP POST request
if (client.connect(server, 80))
{
Serial.println("connecting...");
// EDIT: The POST 'URL' to the location of your insert_mysql.php on your web-host
client.println("POST /index.php HTTP/1.1");
// EDIT: 'Host' to match your domain
client.println("Host: markrigz.000webhostapp.com");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
client.print("Content-Length: ");
client.println(yourdata.length());
client.println();
client.println(yourdata);
Serial.println("Done!");
Serial.println("Disconnecting from server...");
client.stop();
}
else
{
// If you couldn't make a connection:
Serial.println("Connection failed");
Serial.println("Disconnecting.");
client.stop();
}
}
And here is my index.php:
<html> <head> <title>AQWAH Dashboard</title> </head> <body> <h1 style="text-align: center;"><span style="background-color: #33cccc;">AQ</span>WAH</h1> <hr /><hr /> <h3 style="text-align: center;">LATEST READINGS: <?php echo date("d-m-Y h:i:sa"); ?></h3> <table style="width: 299.5px; border-color: blue; background-color: #33cccc; margin-left: auto; margin-right: auto;" border="10" cellspacing="10" cellpadding="10"> <tbody> <tr style="height: 20.25px;"> <td style="width: 104px; text-align: center; height: 20.25px;"><strong>Temperature:</strong></td> <td style="width: 197.5px; height: 20.25px;"> <?php $Temp=$POST['Temperature']; echo $Temp; ?> </td> </tr> <tr style="height: 36px;"> <td style="width: 104px; text-align: center; height: 36px;"><strong>Heater Status:</strong></td> <td style="width: 197.5px; height: 36px;"> <?php $Temp=$_POST['Temperature']; echo "Here it is ". $Temp; ?> </td> </tr> <tr style="height: 18px;"> <td style="width: 104px; text-align: center; height: 18px;"><strong>Pump Status:</strong></td> <td style="width: 197.5px; height: 18px;"> </td> </tr> <tr style="height: 18px;"> <td style="width: 104px; text-align: center; height: 18px;"><strong>Messages:</strong></td> <td style="text-align: left; width: 197.5px; height: 18px;"> </td> </tr> </tbody> </table> <p> </p> <hr /><hr /> <h3 style="text-align: center;"> </h3> </body> </html>