Hallo,
ich habe gestern meinen ersten Wemos D1 mini bekommen und natürlich gleich losgebastelt
Dabei messe ich Temperatur und Luftfeuchtigkeit mit einem DHT11 und lasse sie im Browser anzeigen. Den Sketch habe ich mir aus Beispielen zusammengesetzt, funktioniert wunderbar:
/* DHTServer - ESP8266 Webserver with a DHT sensor as an input
Based on ESP8266Webserver, DHTexample, and BlinkWithoutDelay (thank you)
Version 1.0 5/3/2014 Version 1.0 Mike Barela for Adafruit Industries
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DHT.h>
#define DHTTYPE DHT11
#define DHTPIN 2
const char* ssid = "***";
const char* password = ":-)";
ESP8266WebServer server(80);
EthernetClient client;
// Initialize DHT sensor
// NOTE: For working with a faster than ATmega328p 16 MHz Arduino chip, like an ESP8266,
// you need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold. It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value. The default for a 16mhz AVR is a value of 6. For an
// Arduino Due that runs at 84mhz a value of 30 works.
// This is for the ESP8266 processor on ESP-01
DHT dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266
float humidity, temp_f; // Values read from sensor
int temp_c;
String webString=""; // String to display
// Generally, you should use "unsigned long" for variables that hold time
unsigned long previousMillis = 0; // will store last temp was read
const long interval = 2000; // interval at which to read sensor
void handle_root() {
server.send(200, "text/plain", "Hello from the weather esp8266, read from /temp or /humidity");
delay(100);
}
void setup(void)
{
// You can open the Arduino IDE Serial Monitor window to see what the code is doing
Serial.begin(115200); // Serial connection from ESP-01 via 3.3v console cable
dht.begin(); // initialize temperature sensor
// Connect to WiFi network
WiFi.begin(ssid, password);
Serial.print("\n\r \n\rWorking to connect");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("DHT Weather Reading Server");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", handle_root);
if (client.connect(HomematicIP,80)) {
Serial.println(temp_c);
client.print("GET /config/xmlapi/statechange.cgi?ise_id=6014&new_value=");
client.print(temp_c);
client.println(" HTTP/1.0");
}
server.on("/humidity", [](){ // if you add this subdirectory to your webserver call, you get text below :)
gettemperature(); // read sensor
webString="Humidity: "+String((int)humidity)+"%";
server.send(200, "text/plain", webString); // send to someones browser when asked
});
server.begin();
Serial.println("HTTP server started");
}
void loop(void)
{
server.handleClient();
}
void gettemperature() {
// Wait at least 2 seconds seconds between measurements.
// if the difference between the current time and last time you read
// the sensor is bigger than the interval you set, read the sensor
// Works better than delay for things happening elsewhere also
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
// save the last time you read the sensor
previousMillis = currentMillis;
// Reading temperature for humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
humidity = dht.readHumidity(); // Read humidity (percent)
temp_f = dht.readTemperature(true); // Read temperature as Fahrenheit
temp_c = (temp_f-32)*5/9;
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temp_f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
}
}
Nun möchte ich die Temperatur auch gern zu meiner Homematic CCU2 senden, dort kann sie gespeichert und als chart ausgegeben werden. Dazu kann ich folgende Zeile im Browser eingeben:"192.168.178.4/config/xmlapi/statechange.cgi?ise_id=6014&new_value=50 HTTP/1.0"
Nur bekomme ich es nicht hin, das in Arduino -Code umzusetzen. Im Forum habe ich eigentlich schon eine Lösung gefunden:
https://forum.arduino.cc/index.php?topic=491624.0
Aber bei mir kommen nur Fehlermeldungen, selbst wenn ich SPI.h und Ethernet.h mit einbinde. client oder connect mochte die IDE beim kompilieren nicht, ich habe es Mitternacht genervt wieder verworfen.
Was mache ich falsch?
Vielen Dank
Thomas