Hello i wrote this sketch that upload a temperature reading of a DHT22 sensor to a phpMyAdmin server in localHost, the sketch work fine, the data been upload every 5 min to the server than ESP go t sleep, but every time the code has been executed i have the printout in the console of this error which i don't understand what mean.
[ 1937][E][WiFiClient.cpp:517] flush(): fail on fd 48, errno: 11, "No more processes"
here below my sketch: the sketch include the timer every 5 min to wakeup esp read the temperature and post to the server.
#include <Arduino.h>
#include <DHT.h>
#include <Adafruit_Sensor.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
// FOR T sensor
#define TsensorPin 4
#define DHTTYPE DHT22
DHT dht(TsensorPin, DHTTYPE);
String sensorName = "DHT22";
String sensorLocation = "Casa1";
float h;
float t;
float f;
float hif;
float hic;
// for wifi connection
const char* ssid = "Captain Spiko";
const char* password = "123456789d";
// server data
const char* serverName = "http://192.168.50.158/esp_web/post_esp.php";
String apiKeyValue = "123456789";
// for awake and sleep
#define uS_TO_S_FACTOR 1000000
#define TIME_TO_SLEEP 300
RTC_DATA_ATTR int bootCount = 0;
void print_wakeup_reason(){
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
}
}
void readTemperature(){
h = dht.readHumidity();
t = dht.readTemperature();
f = dht.readTemperature(true); // in F
// Compute heat index in Fahrenheit (the default)
hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}
void activateSleep(){
Serial.println("Going to sleep now");
delay(1000);
Serial.flush();
esp_deep_sleep_start();
}
bool setupWifi(){
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
if (WiFi.status() == WL_CONNECTED){
return true;
} else {
return false;
}
}
void postData(){
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
http.begin(client, serverName);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Prepare your HTTP POST request data
String httpRequestData = "api_key=" + apiKeyValue + "&sensor=" + sensorName
+ "&location=" + sensorLocation + "&value1=" + String(h)
+ "&value2=" + String(t) + "&value3=" + String(f) + "";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);
int httpResponseCode = http.POST(httpRequestData);
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();
}else {
Serial.println("WiFi Disconnected");
}
}
/// @brief Set up
void setup() {
Serial.begin(115200);
delay(1000);
++bootCount; // tiene il conto dei restart
Serial.println("Boot number: " + String(bootCount));
print_wakeup_reason();
if (setupWifi() == true){
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);// set up next wake up after 30 sec
Serial.println(F("DHTxx test!"));
dht.begin();
};
}
/// @brief loop func
void loop() {
readTemperature();
postData();
activateSleep();
}
setupWifi() == false
, thendht.begin();
is never called but it still entersloop()
and tries to read temperatures. Not sure if that's good or eventually runs into undefined behavior.esp_sleep_enable_timer_wakeup()
is only activated if it was possible to connect to the Wifi. If it was not possible to connect to the Wifi, you still goto into deep sleep. But you don't want to wake up after 30 seconds then?