Post your annotated schematic as well be sure to show all connections and power connections. Also post links to technical information on each of the hardware devices.
The problem is always the same:
When i connect it with my pc and check the serial output, all works.
If i connect it with my usb-charger and check, if the ardunio send the value via http, it also works, BUT
after a few minutes, i always get nan
this is my code:
//WIFI und HTTP ESP8266 Libary ##############################
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include "certs.h"
#include <ESP8266HTTPClient.h>
//WIFI ENDE#################################################
//WLAN und HTTP############################################
//#########################################################
#ifndef STASSID
#define STASSID "mynetwork"
#define STAPSK "mypwd"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
X509List cert(cert_DigiCert_Global_Root_CA);
HTTPClient http;
WiFiClient client;
//WLAN und HTTP ENDE#######################################
//#########################################################
//DHT22 Begin ##############################################
//##########################################################
//#include "DHTesp.h"
//DHTesp dht;
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define DHTPIN 4 // Digital pin connected to the DHT sensor connect it on D2
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
//DHT22 Ende ###############################################
//##########################################################
// ZEITVERZOEGERUNG, d.h. falls bspw. nur alle 10sekunden ein request erfolgen soll
//##########################################################
//delay Zeit festlegen
int loop_verzeogerung = 1000;
//festsetzen wie viel verzoegerung zwischen den http request vergehen soll
int request_delay_max = 10000;
//variable welche mitzählt bis request_delay_max erreicht wird
int request_delay_min = 0;
//falls staendig error auftaucht
int count_error = 0;
bool reset_request_delay_min = false;
// ZEITVERZOEGERUNG Ende####################################
//##########################################################
void setup() {
//Serial begin##############################
Serial.begin(115200);
//DHT22
dht.begin();
//WLAN connection aufbauen und ausgeben#####
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
//WLAN ENDE##############################
}
//void setup ENDE
void loop() {
//ZEITVERZOEGERUNG ###################################################################
//ALLES WAS LANGSAMER ALS NORMALER LOOP GESCHEHEN SOLL################################
//####################################################################################
if (request_delay_min >= request_delay_max){
//zähler zurücksetzen,
request_delay_min = 0;
reset_request_delay_min = false;
//############### Hier alles was Zeitverzoegert erfolgen soll##################
//DHT22 Begin ##############################################
//##########################################################
float luftfeuchtigkeit_dht22 = dht.readHumidity();
float temperatur_dht22 = dht.readTemperature();
Serial.print("Temperature_DHT22 = ");
Serial.print(temperatur_dht22);
Serial.println(" *C");
Serial.print("Luftfeuchtigkeit = ");
Serial.print(luftfeuchtigkeit_dht22);
Serial.println(" %");
//DHT22 Ende ##############################################
//##########################################################
// SENDE DHT_22 Temp_aussen und Luftfeuchtigkeit MITTELS HTTP#####################################################
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
String url = "http://10.0.0.142/terminal/includes/helpers/DHT22_1.php";
String temp_url_part = "?temperatur=";
String luftfeuchtigkeit_url_part = "&luftfeuchtigkeit=";
String serverurl = url + temp_url_part + temperatur_dht22 + luftfeuchtigkeit_url_part + luftfeuchtigkeit_dht22;
Serial.println(serverurl);
// Your Domain name with URL path or IP address with path
http.begin(client, serverurl);
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
//SENDE Temp_aussen und Luftfeuchtigkeit ENDE##############################################################
// ENDE VON DEN AUSGABEN - hier/darunter nichts mehr eintragen################################
//###################################################################################
//###################################################################################
//ZEITVERZOEGERUNG ##################################################################
//request_delay_max mit der verzoegerungszeit addieren, falls er nicht zurueckgesetzt wurde
if (reset_request_delay_min != true){
request_delay_min = request_delay_min + loop_verzeogerung;
}
//ZEITVERZOEGERUNG ENDE##########################################
//Delay für jede normale Schleife
delay(loop_verzeogerung);
}//Void loop Ende
please be not surprised.... the delay is 1000ms. so it replay all 1 second. i use a if clause to check wenn the loop reaches a specific time, becuase i use multiple sensors.
Some sensors need to loop all 1000ms
Yes the delay is 1000ms.
But in the void loop is a if function which check, if 10 000ms are done and than it read the dht Infos.
So I read the dht only all 10 000ms
in my code, you can see, that i send the data to a php file via http-reuest.
if i plug my wemos d1 with the charger, it will send the data to my file, after the wemos conntected to my network.
that works.
than i get for the first 5minutes the correct data.
After the 5 minutes, it don't work .
I can see this, because the wemos don't send the humaditiy and temperature. i only get nan
I know emwhat nan means.
The question is, why i get nan always....
It only works for a few mintues. Than i always get nan....
Today i tested my last ideas.
Changing usb charger plug
Changing usb cable
Check all cables
Use another sensor
(I bought a package with two pieces for only 10€)
Second piece, same problem... now i orderd a htu21d
okay. thank you!
i checked the sensor for a few seconds.
Unfortunately, it doesn't show how much ohm the resistance has.
if the resistance on the platine has 10k and i also use a 10k resistance, i would get 20k.
Is it dangerous becuase it can be burn? so much heat because the high resistance
okay. i use my multimeter and put the pins on the resitance. it shows 3,37k
than i put one pin from the multimeter on the + and the other pin on the data. It shows also 3,37k
does it means, the resitancd hav 3.37k????
is it a possible value?
Thank you