Bonjour,
Après avoir compilé 2 programmes différents j’arrive presque à mets fin mais j’ai le problème suivant :
la variable f déclaré double me renvoie 0 et non 0.05 da ns la page web.
le code html web est créé dans une variable word si je comprends bien le programme.
Comment dois-je convertir cette variable double en une variable qui me renverra 0.05 ?
j’aurais bien voulu surligner dans le code la source de mon problème mais je n’y arrive pas.
#include <EtherCard.h>
#define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)
#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,0,176};
// gateway ip address
static byte gwip[] = { 192,168,0,1 };
#endif
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
#include <Wire.h>
#include <LiquidCrystal_ESP.h>
LiquidCrystal_ESP lcd(0x3f,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
int currentPins[3] = {1,2,3}; //Assign phase CT inputs to analog pins
double calib[3] = {4.15,4.15,4.15};
double kilos[3];
unsigned long startMillis[3];
unsigned long endMillis[3];
double RMSCurrent[3];
int RMSPower[3];
int peakPower[3];
byte Ethernet::buffer[500];
BufferFiller bfill;
static word homePage() {
word a = (RMSPower[0]);
word b = (RMSPower[1]);
word c = (RMSPower[2]);
word d = (kilos[0]);
word e = (kilos[1]);
double f = (0,05);
bfill = ether.tcpOffset();
bfill.emit_p(PSTR(
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"\r\n"
"<meta http-equiv='refresh' content='1'/>"
"<title>Home Consomation Power</title>"
"<html>POWER
</html><html>L1 : $D W
</html><html> L2 : $D W
</html><html> L3 : $D W
</html><html>
</html><html>KWh
</html><html>L1 : $D KWh
</html><html>L2 : $D KWh
</html><html>L3 : $D KWh
</html>")
,a,b,c,d,e,f
);
return bfill.position();
}
void setup(){
pinMode(4, INPUT);
Serial.begin(9600);
Serial.println("\n[backSoon]");
// Change 'SS' to your Slave Select pin, if you arn't using the default pin
if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
Serial.println( "Failed to access Ethernet controller");
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
#endif
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print("3 Phase");
lcd.setCursor(0,1);
lcd.print("Energy Meter");
delay(2000);
}
void loop(){
if (digitalRead(4) == LOW){
readPhase();
displayKilowattHours ();
delay(2000);
readPhase();
displayCurrent ();
delay(2000);
readPhase();
displayRMSPower ();
delay(2000);
readPhase();
displayPeakPower ();
delay(2000);
}
readPhase();
}
void readPhase () //Method to read information from CTs
{
for(int i=0;i<=2;i++)
{
int current = 0;
int maxCurrent = 0;
int minCurrent = 1000;
for (int j=0 ; j<=200 ; j++) //Monitors and logs the current input for 200 cycles to determine max and min current
{
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (pos) // check if valid tcp data is received
ether.httpServerReply(homePage());
current = analogRead(currentPins[i]); //Reads current input and records maximum and minimum current
if(current >= maxCurrent)
maxCurrent = current;
else if(current <= minCurrent)
minCurrent = current;
}
if (maxCurrent <= 517)
{
maxCurrent = 516;
}
RMSCurrent[i] = ((maxCurrent - 516)*0.707)/calib[i]; //Calculates RMS current based on maximum value and scales according to calibration
RMSPower[i] = 240*RMSCurrent[i]; //Calculates RMS Power Assuming Voltage 220VAC, change to 110VAC accordingly
if (RMSPower[i] > peakPower[i])
{
peakPower[i] = RMSPower[i];
}
endMillis[i]= millis();
unsigned long time = (endMillis[i] - startMillis[i]);
kilos[i] = kilos[i] + ((double)RMSPower[i] * ((double)time/60/60/1000000)); //Calculate kilowatt hours used
startMillis[i]= millis();
}
}
void displayKilowattHours () //Displays all kilowatt hours data
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(kilos[0]);
lcd.print("kWh");
lcd.setCursor(9,0);
lcd.print(kilos[1]);
lcd.print("kWh");
lcd.setCursor(0,1);
lcd.print(kilos[2]);
lcd.print("kWh");
lcd.setCursor(9,1);
lcd.print("Energy");
}
void displayCurrent () //Displays all current data
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(RMSCurrent[0]);
lcd.print("A");
lcd.setCursor(9,0);
lcd.print(RMSCurrent[1]);
lcd.print("A");
lcd.setCursor(0,1);
lcd.print(RMSCurrent[2]);
lcd.print("A");
lcd.setCursor(9,1);
lcd.print("Current");
}
void displayRMSPower () //Displays all RMS power data
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(RMSPower[0]);
lcd.print("W");
lcd.setCursor(9,0);
lcd.print(RMSPower[1]);
lcd.print("W");
lcd.setCursor(0,1);
lcd.print(RMSPower[2]);
lcd.print("W");
lcd.setCursor(9,1);
lcd.print("Power");
}
void displayPeakPower () //Displays all peak power data
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(peakPower[0]);
lcd.print("W");
lcd.setCursor(9,0);
lcd.print(peakPower[1]);
lcd.print("W");
lcd.setCursor(0,1);
lcd.print(peakPower[2]);
lcd.print("W");
lcd.setCursor(9,1);
lcd.print("Max Pwr");
}