Hello,
could it be possible to help here? I am trying to connect to server and trying to add some data from ESP8266 - 01
This is ESP end code
#include <ESP8266WiFi.h>
const char* ssid = "pramod";
const char* password = "772663";
const char* host = "aryarobotics.com";
void setup() {
Serial.begin(115200);
delay(100);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Netmask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway: ");
Serial.println(WiFi.gatewayIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "/monitoring/dbconfig.php";
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(500);
// 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);
}
Serial.println();
Serial.println("closing connection");
}
Attached is server side php
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("sql312.in", "ltm_21917076", "772663", "ltm_21917076_wp391");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sensordevice = $_REQUEST['Sensor_Device'];
$values = $_REQUEST['Values'];
// Attempt insert query execution
$sql = "INSERT INTO wpim_soil_sensor_data (date_time, sensor_device, sensor_value) VALUES
(now(), '$sensordevice','$Values')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
I was trying to enter some data using
"http://aryarobotics.com/monitoring/dbconfig.php?Sensor_Device=Pramod&sensor_value=3"
and MySQL get updated with data. But above code run but data is not updated.
It would be great help if someone could help me.
Thanks