Hi again
im riky, here to ask question again
excuse me for my bad english…
i learn a little about html and php
i was made a button for led and connect it as command to my nodemcu and it works expected.
now im going to next level, but im stuck with POST…
i wil start with how to POST with ESP8266 ?
i want to POST some value to the internet, my own website, just a simple value or text
example
send it to http://mywebsite.com/read.php “HELLO WEBSITE” and save the text to text.log
i get some code from some website
here is the php code
<?php
$handle = fopen('text.log', 'w');
fwrite($handle, date('d/m/Y H:i:s') . " - " . $_POST['words']) . "\n";
fclose($handle);
?>
with ‘words’ as a variable $words to call my text
and this is the esp8266 side
i use nodemcu
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "------";
const char* password = "------";
void setup()
{
Serial.begin(115200);
Serial.println(" Hi! Riky");
delay(1000);
Serial.println("Connecting...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi Connected");
delay(1000);
Serial.println(WiFi.localIP());
delay(1000);
}
void loop()
{
if (WiFi.status() == WL_CONNECTED)
{
HTTPClient http;
http.begin("http://mywebsite.com/read.php");
http.POST("Content-Type: application/x-www-form-urlencoded");
http.POST("POST /read.php HTTP/1.1");
http.POST("Host: http://rwmarduino.000webhostapp.com");
http.POST("Content-Length: 7");
http.POST("");
http.POST("words=HELLO WEBSITE");
http.end();
}
}
when i upload this sketch it work and access my site (http://mywebsite.com/read.php) and triggered /read.php side to write to file (text.file) but it won’t write my text (HELLO WEBSITE), the ‘read.php’ just write the time without my text…
here is the result from my website file (text.log)
07/05/2018 04:05:52 -
where is my mistake ?
is it the code on website ? or my sketch on arduino ?
can you help me to the next level ??
any suggestions would be greatly appreciated
regards
RWM