first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
// ------------------------------
// LED
// ------------------------------
const byte LED_PIN = 13;
#define DEBUG TRUE
#define A1 20
#define A2 21
// ------------------------------
// Energie
// ------------------------------
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
int boucle = 0;
// ----------------------------
// Interruption
// ----------------------------
const byte interruptPin = 3;
//volatile byte backlight_status = LOW;
/******************************************************************/
/******************************************************************/
/******************************************************************/
#define SolaireProduction "1087"
#define Consommation_Apparente "1123"
#define CONSOMMATION_GENERALE "1115"
void setup()
{
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
pinMode(interruptPin, INPUT);
emon1.voltage(A1, 320 , 2.6); // Voltage: input pin, calibration, phase_shift
emon1.current(A2, 30); // Current: input pin, calibration.
delay(1000);
digitalWrite(interruptPin, LOW);
}
void loop()
{
// if (digitalRead(interruptPin) == HIGH) {
// lcd.backlight();
// }
// else {
// lcd.noBacklight();
// }
double Irms[2];
boucle ++;
emon1.calcVI(20, 200); // 1 Demande a Emonlib de tout calculer, (puissance relle, volts moyen, ampère moyen et facteur de puissance)
// Irms[0] = emon1.calcIrms(5440) * 230; //emon1.apparentPower);
Irms[0] = emon1.apparentPower;
float verif_voltage = emon1.Vrms; // 1 creation de la variable "volts moyen" (mesurable avec un voltmètre pour l'etalonnage)
float verif_ampere = emon1.Irms; // 1 creation de la variable "Ampères Moyen" (mesurable avec une pince ampèremétrique pour l'etalonnage))
float Cos_phi = emon1.powerFactor;
Serial.print(verif_voltage);
Serial.print(" V ");
Serial.print(verif_ampere);
Serial.print(" A ");
Serial.print(emon1.realPower);
Serial.print(" Wr ");
Serial.print(emon1.apparentPower); // Calculate Irms only
Serial.print(" Wcap ");
Serial.print(Irms[0]); // Calculate Irms only
Serial.print(" Wc ");
if (boucle < 10) {
Serial.println("Calibration :" + String(boucle));
delay (500);
}
else {
//Serial.println(getJson(String(Consommation_Apparente), emon1.realPower));
//delay(500);
// Serial.println(getJson(String(CONSOMMATION_GENERALE), emon1.apparentPower));
if (boucle % 2 == 0) {
Serial.println("Cso:" + String(emon1.apparentPower, 0) + " R " + String(emon1.realPower, 0));
}
delay (2000);
if (boucle > 1000) {
boucle = 11;
}
}
Serial.println();
}
String getJson(String idx, double value)
{
String json = "/json.htm?type=command&param=udevice&idx=" + idx + "&svalue=" + String(value) + ";0&nvalue=0&nvalue=0&nvalue=0";
//Serial.println(json);
return json;
}