update
This commit is contained in:
parent
2a71bcbafd
commit
99db005d4c
|
@ -2,15 +2,12 @@
|
|||
#include "WiFi.h"
|
||||
#include "WiFiMulti.h"
|
||||
#include "src/InfluxDB-Client-for-Arduino/src/InfluxDbClient.h"
|
||||
#include "src/EmonLib/EmonLib.h"
|
||||
#include "src/PZEM-004T-v30/PZEM004Tv30.h"
|
||||
#include "config.h"
|
||||
|
||||
#define Apin 32
|
||||
#define Vpin 33
|
||||
|
||||
EnergyMonitor emon1; // Create an instance
|
||||
WiFiMulti WiFiMulti;
|
||||
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_DB_NAME);
|
||||
PZEM004Tv30 pzem(&Serial2);
|
||||
|
||||
// Data point
|
||||
Point sensor("solar_status");
|
||||
|
@ -46,26 +43,53 @@ void setup() {
|
|||
Serial.begin(115200);
|
||||
ConnectToWiFiMulti();
|
||||
ConnectToInflux();
|
||||
analogReadResolution(12);
|
||||
pinMode(Apin, INPUT);
|
||||
Serial.println(ADC_COUNTS);
|
||||
emon1.voltage(Vpin, 406, 1.7); // Voltage: input pin, calibration, phase_shift
|
||||
emon1.current(Apin, 66); // Current: input pin, calibration.
|
||||
// Add constant tags - only once
|
||||
sensor.addTag("device", "ESP32-Solar");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println(analogRead(Vpin));
|
||||
emon1.calcVI(20, 2000); // Calculate all. No.of half wavelengths (crossings), time-out
|
||||
Serial.print(emon1.Vrms);
|
||||
Serial.print(" Volts | ");
|
||||
Serial.print(emon1.Irms);
|
||||
Serial.print(" Amps | ");
|
||||
Serial.print(emon1.Vrms*emon1.Irms);
|
||||
Serial.println(" Watts");
|
||||
Serial.println(emon1.calcIrms(1480));
|
||||
//emon1.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
|
||||
delay(5000);
|
||||
float voltage = pzem.voltage();
|
||||
if(!isnan(voltage)){
|
||||
Serial.print("Voltage: "); Serial.print(voltage); Serial.println("V");
|
||||
} else {
|
||||
Serial.println("Error reading voltage");
|
||||
}
|
||||
|
||||
//influx to be implemented...
|
||||
Point sensor("wifi_status");
|
||||
float current = pzem.current();
|
||||
if(!isnan(current)){
|
||||
Serial.print("Current: "); Serial.print(current); Serial.println("A");
|
||||
} else {
|
||||
Serial.println("Error reading current");
|
||||
}
|
||||
|
||||
float power = pzem.power();
|
||||
if(!isnan(power)){
|
||||
Serial.print("Power: "); Serial.print(power); Serial.println("W");
|
||||
} else {
|
||||
Serial.println("Error reading power");
|
||||
}
|
||||
|
||||
float energy = pzem.energy();
|
||||
if(!isnan(energy)){
|
||||
Serial.print("Energy: "); Serial.print(energy,3); Serial.println("kWh");
|
||||
} else {
|
||||
Serial.println("Error reading energy");
|
||||
}
|
||||
|
||||
float frequency = pzem.frequency();
|
||||
if(!isnan(frequency)){
|
||||
Serial.print("Frequency: "); Serial.print(frequency, 1); Serial.println("Hz");
|
||||
} else {
|
||||
Serial.println("Error reading frequency");
|
||||
}
|
||||
|
||||
float pf = pzem.pf();
|
||||
if(!isnan(pf)){
|
||||
Serial.print("PF: "); Serial.println(pf);
|
||||
} else {
|
||||
Serial.println("Error reading power factor");
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
delay(2000);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue