diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..299bb98 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.h \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9eace41 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "ESP_influxdb"] + path = src/ESP_influxdb + url = https://github.com/hwwong/ESP_influxdb.git +[submodule "EmonLib"] + path = src/EmonLib + url = https://github.com/openenergymonitor/EmonLib.git diff --git a/ESP32-SolarPowerMonitor.ino b/ESP32-SolarPowerMonitor.ino new file mode 100644 index 0000000..bfc9e2f --- /dev/null +++ b/ESP32-SolarPowerMonitor.ino @@ -0,0 +1,55 @@ +#include +#include "WiFi.h" +#include "src/ESP_influxdb/ESPinfluxdb.h" +#include "src/EmonLib/EmonLib.h" +#include "config.h" + +#define Apin 32 +#define Vpin 33 + +EnergyMonitor emon1; // Create an instance + +void ConnectToWiFi(){ + WiFi.mode(WIFI_STA); + WiFi.begin(SSID, WiFiPassword); + Serial.print("Connecting to "); Serial.println(SSID); + + uint8_t i = 0; + while (WiFi.status() != WL_CONNECTED) + { + Serial.print('.'); + delay(500); + + if ((++i % 16) == 0) + { + Serial.println(F(" still trying to connect")); + } + } + Serial.print(F("Connected. My IP address is: ")); + Serial.println(WiFi.localIP()); +} + +Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT); + +void ConnectToInflux(){ + while (influxdb.opendb(DATABASE)!=DB_SUCCESS) { + Serial.println("Opend database failed"); + delay(10000); + } +} + +void setup() { + Serial.begin(115200); + ConnectToWiFi(); + ConnectToInflux(); + analogReadResolution(ADC_BITS); + emon1.voltage(Vpin, 234.26, 1.7); // Voltage: input pin, calibration, phase_shift + emon1.current(Apin, 111.1); // Current: input pin, calibration. +} + +void loop() { + emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out + emon1.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor) + + //influx to be implemented... +} diff --git a/README.md b/README.md index 617431c..36e0f6d 100644 --- a/README.md +++ b/README.md @@ -1 +1,15 @@ -ESP32-SolarPowerMonitor +# ESP32-SolarPowerMonitor + +# To be finished when the remaining parts arrive + +My take on a power measurement device using a ESP32, ACS712 Current Sensor & AC Voltage meter + +## Hardware requiered +- ESP32 dev board +- ACS712 Current Sensor +- AC Voltage meter for arduino +- InfluxDB server + +### Libraries used +- [openenergymonitor/EmonLib](https://github.com/openenergymonitor/EmonLib) - for sensor measuring +- [hwwong/ESP_influxdb](https://github.com/hwwong/ESP_influxdb) - for influxdb connection \ No newline at end of file diff --git a/config_example.h b/config_example.h new file mode 100644 index 0000000..7705116 --- /dev/null +++ b/config_example.h @@ -0,0 +1,9 @@ +const char *SSID = "ssid"; +const char *WiFiPassword = "password"; + +const char *INFLUXDB_HOST = "host_IP"; +const uint16_t INFLUXDB_PORT = 8086; + +const char *DATABASE = "dbname"; +const char *DB_USER = "dbuser"; +const char *DB_PASSWORD = "dbpassword";