Topic: simple code for DHT sensor shows wrong values on dashboard
Hi All,
I'am newbie and my simple code doesnt show nearly right values of the DHT Sensor in the mobile app. The Serial Monitor is correct.
#include <Wire.h>
#include "HT_SSD1306Wire.h" // OLED Display
#include <WiFi.h>
#include <WiFiClient.h>
#include <DHT.h> // Bibliothek für DHT-Sensor
#define DHTPIN 14 // Pin für DHT11 Sensor
#define DHTTYPE DHT11 // Sensortyp ist DHT11
#define PIN_RELEAISSWITCHLIGHT230V 17 // Pin für das Relais
// RemoteXY Konfiguration
#define REMOTEXY_MODE__WIFI_CLOUD
// RemoteXY connection settings
#define REMOTEXY_WIFI_SSID ""
#define REMOTEXY_WIFI_PASSWORD ""
#define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com"
#define REMOTEXY_CLOUD_PORT 6376
#define REMOTEXY_CLOUD_TOKEN ""
#include <RemoteXY.h>
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 112 bytes
{ 255,1,0,12,0,105,0,19,0,0,0,0,31,1,106,200,1,1,5,0,
2,4,11,50,7,0,2,26,31,31,79,78,0,79,70,70,0,129,3,4,
67,6,64,17,82,101,108,97,105,115,95,77,97,105,110,76,105,103,104,116,
50,51,48,86,0,68,6,72,95,43,49,8,36,86,97,114,105,97,98,108,
101,32,49,0,68,5,121,95,43,49,8,13,86,97,114,105,97,98,108,101,
32,49,0,67,4,35,40,10,78,2,26,2 };
struct {
uint8_t releaisSwitchLight230V; // =1 if switch ON and =0 if OFF
uint8_t connect_flag; // =1 if wire connected, else =0
float humidityGraph2; // actually a value widget for test purpose
float temperatureGraph; // graph widget
float humidityGraph; // graph widget
} RemoteXY;
#pragma pack(pop)
DHT dht(DHTPIN, DHTTYPE); // DHT-Sensor-Objekt erstellen
// OLED Display-Konfiguration
#ifdef WIRELESS_STICK_V3
static SSD1306Wire display(0x3c, 500000, SDA_OLED, SCL_OLED, GEOMETRY_64_32, RST_OLED);
#else
static SSD1306Wire display(0x3c, 500000, SDA_OLED, SCL_OLED, GEOMETRY_128_64, RST_OLED);
#endif
void setup() {
Serial.begin(115200);
RemoteXY_Init();
pinMode(PIN_RELEAISSWITCHLIGHT230V, OUTPUT);
digitalWrite(PIN_RELEAISSWITCHLIGHT230V, LOW); // Relais initial aus
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
display.clear();
display.drawString(0, 0, "Waiting for RemoteXY...");
display.display();
dht.begin(); // DHT-Sensor initialisieren
}
void loop() {
RemoteXY_Handler();
// Relaissteuerung
digitalWrite(PIN_RELEAISSWITCHLIGHT230V, RemoteXY.releaisSwitchLight230V == 1 ? HIGH : LOW);
// Sensordaten lesen und anzeigen
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
if (!isnan(temperature) && !isnan(humidity)) {
// Daten auf dem Display anzeigen
display.clear();
display.drawString(0, 0, "Temp: " + String(temperature) + " C");
display.drawString(0, 12, "Humidity: " + String(humidity) + " %");
display.display();
// Debug-Ausgabe auf der seriellen Konsole
Serial.print("Temperatur: ");
Serial.print(temperature);
Serial.print(" C, Luftfeuchtigkeit: ");
Serial.print(humidity);
Serial.println(" %");
// Die Sensorwerte direkt als float übertragen
RemoteXY.humidityGraph = humidity;
RemoteXY.temperatureGraph = temperature;
RemoteXY.humidityGraph2 = humidity;
RemoteXY_delay(1000);
} else {
Serial.println("Fehler beim Lesen des DHT11-Sensors!");
}
}
what I'm doint wrong here?
BR; zr1m