Go Down

Topic: Esp8266 (Read 189 times) previous topic - next topic


Hi. I want to write data to web page but ı can't write web page

My arduino code---------------------------------
#include "SoftwareSerial.h"
String ssid ="*****";
String password="*****";
SoftwareSerial esp(6,7);// RX, TX
String data;
String server = "files.000webhost.com"; // www.example.com
String uri = "https://veriyukle16.000webhostapp.com/esppost.php";// our example is /esppost.php
int DHpin = 8;//sensor pin
byte dat [5];
String temp ,hum;
void setup() {
pinMode (DHpin, OUTPUT);
//reset the esp8266 module
void reset() {
if(esp.find("OK") ) Serial.println("Modüle reset atıldı");
//connect to your wifi network
void connectWifi() {
String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\"";
if(esp.find("OK")) {
Serial.println("İnternete bağlanıldı.");
else {
Serial.println("internete bağlanılamadı"); }
byte read_data () {
byte data;
for (int i = 0; i < 8; i ++) {
if (digitalRead (DHpin) == LOW) {
while (digitalRead (DHpin) == LOW); // wait for 50us
delayMicroseconds (30); // determine the duration of the high level to determine the data is '0 'or '1'
if (digitalRead (DHpin) == HIGH)
data |= (1 << (7-i)); // high front and low in the post
while (digitalRead (DHpin) == HIGH);
// data '1 ', wait for the next one receiver
} return data; }
void start_test () {
digitalWrite (DHpin, LOW); // bus down, send start signal
delay (30); // delay greater than 18ms, so DHT11 start signal can be detected
digitalWrite (DHpin, HIGH);
delayMicroseconds (40); // Wait for DHT11 response
pinMode (DHpin, INPUT);
while (digitalRead (DHpin) == HIGH);
delayMicroseconds (80);
// DHT11 response, pulled the bus 80us
if (digitalRead (DHpin) == LOW);
delayMicroseconds (80);
// DHT11 80us after the bus pulled to start sending data
for (int i = 0; i < 4; i ++)
// receive temperature and humidity data, the parity bit is not considered
dat = read_data ();
pinMode (DHpin, OUTPUT);
digitalWrite (DHpin, HIGH);
// send data once after releasing the bus, wait for the host to open the next Start signal
void loop () {
start_test ();
// convert the bit data to string form
hum = String(dat[0]);
temp= String(dat[2]);
data = "temperature=" + temp + "&humidity=" + hum;// data sent must be under this form //name1=value1&name2=value2.
void httppost () {
esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.
if( esp.find("OK")) {
Serial.println("TCP HAZIR");
} delay(1000);
String postRequest =
"POST " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Length: " + data.length() + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" + //-------------------------------------------
"\r\n" + data;
String sendCmd = "AT+CIPSEND=";//---------------------------------
Serial.println("sendcmd here");
if(esp.find(">")) { Serial.println("Gönderiliyor"); Serial.println(hum); Serial.println(temp); esp.print(postRequest);
if( esp.find("SEND OK")) { Serial.println("Paket gönderildi.");
while (esp.available()) {
String tmpResp = esp.readString();
// close the connection

my php code--------------------------------------------------

$Write="<p>Temperature :" . $Temp . "Celcius </p>" . "<p>Humidity : " . $Humidity . " % </p>";


The console log does not appear to have any errors so there is nothing there to imply that the POST of your data via esppost.php failed and it appears even to have created the file "sensor.html" which is what you intend.

It does look, however, like the values for temperature and humidity have failed to get across into sensor.html.

Try deleting sensor.html in case it is from an old test, then hardcode test values here to see what happens:

Code: [Select]

hum = String(dat[0]);
temp= String(dat[2]);
data = "temperature=" + temp + "&humidity=" + hum;// data sent must be under this form


Code: [Select]

data = "temperature=99&humidity=88";


Unfortunately, it did not happen.

String sendCmd = "AT+CIPSEND=";  What should ı write here?


What did not happen ?

You were asked to perform 2 tests:

1. Delete the file sensor.html to demonstrate that your esp code is capable of calling the php script esppost.php  to recreate it. If that works, the problem must be simple to solve.

2. Force some values for temperature and humidity to see if there is a problem with the values somehow derived from the sensor.

If you still have problems, show the code you used for test 2 but format it using the format tool in the arduino IDE to make it more readable and also use code tags to post it.

Go Up