Skip to content
Snippets Groups Projects
Commit 7bccc9b5 authored by Egmont Schreiter's avatar Egmont Schreiter
Browse files

Option Impulse_pro_kWh hinzugefügt, Issue #1

parent cf494fda
Branches master
No related tags found
No related merge requests found
// https://tttapa.github.io/ESP8266/Chap13%20-%20OTA.html // https://tttapa.github.io/ESP8266/Chap13%20-%20OTA.html
// ESP32 oder ESP8266? // ESP32 oder ESP8266?
#define ESP32 #define ESP8266
// Boardverwaltung: // Boardverwaltung:
// ESP8266: NodeMCU 1.0 (ESP-12E Module) // ESP8266: NodeMCU 1.0 (ESP-12E Module) // http://arduino.esp8266.com/stable/package_esp8266com_index.json
// ESP32: NodeMCU-32S // ESP32: NodeMCU-32S // https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
// //
// Werkzeuge --> Bibliotheksverwaltung: Thingspeak // 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 #ifdef ESP32
#include <WiFi.h> #include <WiFi.h>
#include <WiFiMulti.h> #include <WiFiMulti.h>
WiFiMulti wifiMulti; WiFiMulti wifiMulti;
#else #else
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h> #include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti' ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti'
#endif #endif
...@@ -54,8 +59,6 @@ const char * myWriteAPIKey = PASSWORTE_myWriteAPIKey; // Paste your ThingSpea ...@@ -54,8 +59,6 @@ const char * myWriteAPIKey = PASSWORTE_myWriteAPIKey; // Paste your ThingSpea
// https://randomnerdtutorials.com/interrupts-timers-esp8266-arduino-ide-nodemcu/ // https://randomnerdtutorials.com/interrupts-timers-esp8266-arduino-ide-nodemcu/
// //
WiFiClient client; WiFiClient client;
// Startvalue of Counter kWh // Startvalue of Counter kWh
...@@ -161,7 +164,7 @@ void loop() { ...@@ -161,7 +164,7 @@ void loop() {
unsigned long diff_last = last_pulse - last_pulse_before_thingspeak; unsigned long diff_last = last_pulse - last_pulse_before_thingspeak;
if (diff_last > 0 && new_impulse > 0) { 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: "); Serial.print("Thingspeak: ");
} }
else { else {
...@@ -169,13 +172,13 @@ void loop() { ...@@ -169,13 +172,13 @@ void loop() {
Serial.print("divide by zero! "); 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("Thingspeak: ");
Serial.print(rate); Serial.print(rate);
Serial.print(" ,"); Serial.print(" ,");
Serial.print(counter_electricity_Wh / 1000); Serial.print(counter_electricity_Wh / 1000); // kWh
Serial.print("."); Serial.print(".");
Serial.print(counter_electricity_Wh % 1000); Serial.print(counter_electricity_Wh % 1000); // Nachkommastelle
Serial.print(" ,"); Serial.print(" ,");
Serial.println(digitalRead(13)); Serial.println(digitalRead(13));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment