hii everyone i've been working on nodemcu and taking ultrasonic sensor values from serial monitor of arduino uno's serial monitor and trying to send the data from node mcu to my created database by WAMP but the values are not reaching at the database help me with that
HERE IS THE NODE MCU CODE
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
char ssid[] = "Nodemcu";
char pass[] = "yonexcarbonex";
const char* host = "192.168.43.57";
void setup() {
Serial.begin(115200);
while (!Serial) {
;
}
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Waiting for connection");
}
Serial.println("WiFi connected");
Serial.println("IP Address");
Serial.println(WiFi.localIP());
}
void loop() {
if (Serial.available()) {
Serial.read();
}
String postData;
String val = String (Serial.read());
if (WiFi.status() == WL_CONNECTED) {
Serial.println("connected");
HTTPClient http;
http.begin("http://192.168.43.57/UltraValues/index.php");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
postData = "inches" + val;
// getData = "inches" + val;
// Link = "http://192.168.56.1:3306/UltraValues/index.php" + getData;
// http.begin(Link);
int httpCode = http.POST(postData);
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
http.end();
}]
}
else {
Serial.println("Error in WiFi connection");
}
delay(30000);
}
HERE IS THE PHP CODE
<?php //Creates new record as per request //Connect to database $servername = "localhost"; $username = "root"; $password = ""; $dbname = "ultravalue"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Database Connection failed: " . $conn->connect_error); } else { echo "Connected"; } if(!empty($_POST['val'])) { $val = $_POST['val']; $sql = "INSERT INTO value (val) VALUES ('$val')"; if ($conn->query($sql) === TRUE) { echo "OK"; } else { echo "Error: " . $sql . " " . $conn->error; } }else{ echo "Value not going"; } $conn->close(); ?>ultrasonictonodemcu.ino (1.28 KB)
index.txt (807 Bytes)