Hello !
i've read numerous threads on this topic, but, unfortunately, i can't get the data from the 8266 to reach the PHP file on the server.
I'm using the ESP8266-01, it connects to the network well (WiFiManager).
The code is supposed to send a string variable (data) to a PHP file: datacollector.php on the subdomain : "8266.morgulis.net". (the PHP file creates an HTML file - this works, only this...)
I've tried changing the permissions of the public_html folder (to be 777-RWX) and the permissions of the PHP file, but i guess that wasn't the problem.
here is the code, any help will be highly appreciated!
The Sketch:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiManager.h>
WiFiClient client;
const char server_name[] = "www.domain.com";
void setup() {
Serial.begin(115200);
WiFiManager wifiManager;
wifiManager.autoConnect("AutoConnectAP");
Serial.println("connected...)");
int V1 = 1234;
int V2 = 5678;
String data = "V1=" + (String) V1 + "&V2=" + (String) V2 ;
Serial.println("\nStarting connection to server...");
if (client.connect(server_name, 80))
{
Serial.println("connected to server");
delay(1000);
} //if client.connet
}
void loop() {
int V1 = 1234;
int V2 = 5678;
String data = "V1=" + (String) V1 + "&V2=" + (String) V2 ;
if (client.connect(server_name, 80))
{
Serial.println("connected to server");
delay(1000);
delay(1000);
//WiFi.printDiag(Serial);
client.println("POST /datacollector.php HTTP/1.0");
client.println("Host: www.domain.com");
client.println("User-Agent:ESP8266/1.0");
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Connection: close");
client.print("Content-Length: ");
client.println(data.length());
client.println(data);
client.stop();
Serial.println("\n");
Serial.println("My data string: ");
Serial.println(data);
Serial.println("It's size:: ");
Serial.println(data.length());
delay(2000);
}// if conneted to server
} //loop
The PHP code:
<?php
$TimeStamp = "The current time is " . date("h:i:sa");
file_put_contents('dataDisplayer.html', $TimeStamp, FILE_APPEND);
if( $_REQUEST["V1"] || $_REQUEST["V2"] )
{
echo " Value1 is: ". $_REQUEST['V1']. "
";
echo " Value2 is: ". $_REQUEST['V2']. "
";
}
$var1 = $_REQUEST['V1'];
$var2 = $_REQUEST['V2'];
$WriteMyRequest= "<p> Value1 is : " . $var1 . " </p>".
"<p> And Value2 is : " . $var2 . " </p>
";
file_put_contents('dataDisplayer.html', $WriteMyRequest, FILE_APPEND);
?>
Thank you!