From 7bccc9b547db343f7d5fd64d40a53b9e17c1cf9c Mon Sep 17 00:00:00 2001 From: Familie <75-eshszg@users.noreply.edugit.org> Date: Sat, 12 Jun 2021 21:23:57 +0200 Subject: [PATCH] =?UTF-8?q?Option=20Impulse=5Fpro=5FkWh=20hinzugef=C3=BCgt?= =?UTF-8?q?,=20Issue=20#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wlan_energie_thingspeak.ino | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/wlan_energie_thingspeak/wlan_energie_thingspeak.ino b/wlan_energie_thingspeak/wlan_energie_thingspeak.ino index 2217c36..e04472e 100644 --- a/wlan_energie_thingspeak/wlan_energie_thingspeak.ino +++ b/wlan_energie_thingspeak/wlan_energie_thingspeak.ino @@ -1,22 +1,27 @@ // https://tttapa.github.io/ESP8266/Chap13%20-%20OTA.html // ESP32 oder ESP8266? -#define ESP32 +#define ESP8266 // Boardverwaltung: -// ESP8266: NodeMCU 1.0 (ESP-12E Module) -// ESP32: NodeMCU-32S +// ESP8266: NodeMCU 1.0 (ESP-12E Module) // http://arduino.esp8266.com/stable/package_esp8266com_index.json +// ESP32: NodeMCU-32S // https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json // // Werkzeuge --> Bibliotheksverwaltung: Thingspeak +// Hardware Circuit: +// CNY70 IR RX/TX with IR-Transistor +// Emitter: Ground, Collector D6 (GPIO12) +// optional: 5GHz Radarsensor: GND, 3V, D7 (GPIO13) +#define IMPULSE_PRO_KWH 250 #ifdef ESP32 #include <WiFi.h> #include <WiFiMulti.h> WiFiMulti wifiMulti; #else -#include <ESP8266WiFi.h> +#include <ESP8266WiFi.h> #include <ESP8266WiFiMulti.h> ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti' #endif @@ -54,8 +59,6 @@ const char * myWriteAPIKey = PASSWORTE_myWriteAPIKey; // Paste your ThingSpea // https://randomnerdtutorials.com/interrupts-timers-esp8266-arduino-ide-nodemcu/ // - - WiFiClient client; // Startvalue of Counter kWh @@ -161,7 +164,7 @@ void loop() { unsigned long diff_last = last_pulse - last_pulse_before_thingspeak; if (diff_last > 0 && new_impulse > 0) { - rate = (1000 * 60 * 60 * new_impulse) / (diff_last); // ergibt Watt + rate = (1000 * 60 * 60 * new_impulse) / (diff_last) / (1000/IMPULSE_PRO_KWH); // ergibt Watt Serial.print("Thingspeak: "); } else { @@ -169,13 +172,13 @@ void loop() { Serial.print("divide by zero! "); } - counter_electricity_Wh += new_impulse; + counter_electricity_Wh += new_impulse * (1000/IMPULSE_PRO_KWH); // der Zähler macht 1000 Impulse pro kWh, also einen pro Wh Serial.print("Thingspeak: "); Serial.print(rate); Serial.print(" ,"); - Serial.print(counter_electricity_Wh / 1000); + Serial.print(counter_electricity_Wh / 1000); // kWh Serial.print("."); - Serial.print(counter_electricity_Wh % 1000); + Serial.print(counter_electricity_Wh % 1000); // Nachkommastelle Serial.print(" ,"); Serial.println(digitalRead(13)); -- GitLab