I want to send data from DHT11 to URL using an ESP8266 NodeMCU. I use the board "NodeMCU 1.0 (ESP-12E Module)".
My code is as follows:
#include <dht.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <SPI.h>
#include <MFRC522.h>
dht DHT;
#define DHTPIN 2
float humidityData;
float temperatureData;
const char* ssid = "My_SSID";
const char* password = "Wifi_Password";
//WiFiClient client;
char server[] = "192.168.1.1";
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
// server.begin();
Serial.println("Server started");
Serial.print(WiFi.localIP());
delay(1000);
Serial.println("connecting...");
}
void loop()
{
int chk = DHT.read11(DHTPIN);
humidityData = DHT.temperature;
temperatureData = DHT.humidity;
Sending_To_phpmyadmindatabase();
delay(30000); // interval
}
void Sending_To_phpmyadmindatabase() //CONNECTING WITH MYSQL
{
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
Serial.print("GET localhost/project_folder/dht.php?humidity=");
client.print("GET localhost/project_folder/dht.php?humidity=");
Serial.println(humidityData);
client.print(humidityData);
client.print("&temperature=");
Serial.println("&temperature=");
client.print(temperatureData);
Serial.println(temperatureData);
client.print(" "); //SPACE BEFORE HTTP/1.1
client.print("HTTP/1.1");
client.println();
client.println("Host: Your Local IP");
client.println("Connection: close");
client.println();
} else {
// if connection to the server failed:
Serial.println("connection to the server failed");
}
}
When it works correctly (1/3 of the running time), i get this serial message:
Connecting to Omni_777318
...........
WiFi connected
Server started
192.168.39.178connecting...
connected
GET localhost/michael/dht11.php?humidity=26.00
&temperature=
40.00
BUT! 2/3 of the time, i get a weird error that i dont understand:
tail 4
chksum 0xc9
csum 0xc9
v00044840
~ld
Connecting to Omni_777318
.....
ets Jan 8 2013,rst cause:4, boot mode:(3,7)
wdt reset
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v00044840
~ld
Anyone here who can help me solve this issue?
Cause 4 is a hardware watchdog reset, and in that case I suspect a power problem. During the connection phases we observe current peak, and if the power supply is too weak ESP Reboot, as voltage falls under limit. In this case you must either change the power source, or put a capacitor of a few hundred microfarads on the supply terminals, as close as possible to ESP.