HELLO GUYS
I AM FACING A PROBLEM I HAVE TRY ALOT BUT PROBLEM IS TILL THERE EVEN I CANNOT SEND ANY VALUE MANUALLY
KINDLY GUIDE ME SO THAT I COULD COME OUT FROM THIIS PROBLEM
NODE MCU CODE
#include <ESP8266HTTPClient.h>
#include<WiFiClient.h>
#include <ESP8266WiFi.h>
const char* ssid = "DOCTORS";
const char* password = "aimcblu123";
char server[] = "192.168.1.4";
WiFiClient client;
const int ledPin = 5;
const int ldrPin = A0;
String power_status_HIGH="ON";
String power_status_LOW="OFF";
double V=3.6; // we are using blue led
double I=36; // MILLIAMPER because we to find CURRENT I= V/R WE HAVE RESISTOR 10k IN Series
double start_time=0, current_time=0,actual_time;
unsigned long power;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
Serial.print("wifi connecting to : ");
Serial.println( ssid );//SERIAL= COUT
WiFi.begin(ssid,password );
while (WiFi.status() != WL_CONNECTED) { //Wait for the WiFI connection completion
delay(500);//DELAY 500 milliseconds
Serial.print(". ");
}
Serial.println(" ");
Serial.println("Wi-Fi Connected successfully");
// Print the IP address
Serial.print("IP Address is ");
Serial.println(WiFi.localIP());
Serial.begin(115200);
delay(1000);
}
void loop() {
int ldrStatus = analogRead(ldrPin);
if (ldrStatus <=300) {
digitalWrite(ledPin, HIGH);
start_time = millis();
current_time=start_time/1000;
actual_time=current_time/4.4;
power=6*V*I*1000*actual_time;
delay(1000);
Serial.println(power);
String data= "power="+String(power);
}
else {
digitalWrite(ledPin, LOW);
delay(1000);
Serial.println( power);
String data= "power="+String(power);
// put your main code here, to run repeatedly:
if (client.connect(server, 8080)) {
Serial.println("connecting...");
// EDIT: The POST 'URL' to the location of your insert_mysql.php on your web-host
client.println("POST /smart_city/insert.php HTTP/1.1");
// EDIT: 'Host' to match your domain
client.println("Host: 192.168.1.4");
client.println("User-Agent: ESP8266/1.0");
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded;");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.println(data);
Serial.println("\n");
Serial.println(data);
Serial.println(data.length());
delay(1000);
}}}
INSERT.PHP
<?php
include ('arduino_connection.php');
$sql_insert = "INSERT INTO power (report) VALUES ('".$_POST["data"]."')";
//if (isset($_POST['data'])){}
if(mysqli_query($con,$sql_insert))
{
echo "Done";
mysqli_close($con);
}
else
{
echo "error is ".mysqli_error($con );
}
?>
ARDUINO_CONNECTION.PHP
<?php
$username = "root";
$pass = "";
$host = "localhost";
$db_name = "greenvorx";
$con = mysqli_connect ($host, $username, $pass);
$db = mysqli_select_db ( $con, $db_name );
?>