First Commit

Project Structure
Base code.
This commit is contained in:
ZMiguel Valdiviesso 2020-06-24 17:36:32 +01:00
parent ad4e1985de
commit 407eff57a2
5 changed files with 86 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
config.h

6
.gitmodules vendored Normal file
View File

@ -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

View File

@ -0,0 +1,55 @@
#include <Arduino.h>
#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...
}

View File

@ -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

9
config_example.h Normal file
View File

@ -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";