My hardware is on photo. I prepare hardware from emoncms site for 3 phases. My sketh working good so far about 3 weeks. My controler is pidome and send values to emoncms on mys NAS.
My hardware is on photo. I prepare hardware from emoncms site for 3 phases. My sketh working good so far about 3 weeks. My controler is pidome and send values to emoncms on mys NAS.
This is my last and my final sketch
#include <SPI.h>
#include <MySensor.h>
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
EnergyMonitor emon2; // Create an instance
EnergyMonitor emon3; // Create an instance
#define CHILD_ID 0
#define CHILD_ID2 1
#define CHILD_ID3 2
MySensor gw;
unsigned long lastSend;
unsigned long SEND_FREQUENCY = 10000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
unsigned long lastSend2;
unsigned long SEND_FREQUENCY2 = 300000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
MyMessage realPowerMsg(CHILD_ID,V_VAR1);
MyMessage apparentPowerMsg(CHILD_ID,V_VAR2);
MyMessage powerFActorMsg(CHILD_ID,V_VAR3);
MyMessage supplyVoltageMsg(CHILD_ID,V_VAR4);
MyMessage IrmsMsg(CHILD_ID,V_VAR5);
MyMessage realPowerMsg2(CHILD_ID2,V_VAR1);
MyMessage apparentPowerMsg2(CHILD_ID2,V_VAR2);
MyMessage powerFActorMsg2(CHILD_ID2,V_VAR3);
MyMessage supplyVoltageMsg2(CHILD_ID2,V_VAR4);
MyMessage IrmsMsg2(CHILD_ID2,V_VAR5);
MyMessage realPowerMsg3(CHILD_ID3,V_VAR1);
MyMessage apparentPowerMsg3(CHILD_ID3,V_VAR2);
MyMessage powerFActorMsg3(CHILD_ID3,V_VAR3);
MyMessage supplyVoltageMsg3(CHILD_ID3,V_VAR4);
MyMessage IrmsMsg3(CHILD_ID3,V_VAR5);
void setup()
{
gw.begin(NULL, 4, false, 0);
Serial.begin(115200); // opens serial port, sets data rate to 9600 bps
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Energy Meter x 3v2", "1.2");
// Register this device as power sensor
gw.present(CHILD_ID, S_POWER);
gw.present(CHILD_ID2, S_POWER);
gw.present(CHILD_ID3, S_POWER);
emon1.voltage(A3, 116.26, 1.7); // Voltage: input pin, calibration, phase_shift
emon1.current(A0, 29.0); // Current: input pin, calibration.
emon2.voltage(A4, 116.66, 1.7); // Voltage: input pin, calibration, phase_shift
emon2.current(A1, 29.0); // Current: input pin, calibration.
emon3.voltage(A5, 115.91, 1.7); // Voltage: input pin, calibration, phase_shift
emon3.current(A2, 29.0); // Current: input pin, calibration.
}
void loop()
{
gw.process();
unsigned long now = millis();
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)
emon2.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
//emon2.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
emon3.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
//emon3.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
bool sendTime = now - lastSend > SEND_FREQUENCY;
if (sendTime) {
float realPower = emon1.realPower; //extract Real Power into variable
float realPower2 = emon2.realPower; //extract Real Power into variable
float realPower3 = emon3.realPower; //extract Real Power into variable
if(realPower > 0 && realPower < 10000){
gw.send(realPowerMsg.set(realPower,1));
}
if(realPower2 > 0 && realPower2 < 10000){
gw.send(realPowerMsg2.set(realPower2,1));
}
if(realPower3 > 0 && realPower3 < 10000){
gw.send(realPowerMsg3.set(realPower3,1));
}
lastSend = now;
}
bool sendTime2 = now - lastSend2 > SEND_FREQUENCY2;
if(sendTime2){
float apparentPower = emon1.apparentPower; //extract Apparent Power into variable
float powerFactor = emon1.powerFactor; //extract Power Factor into Variable
float supplyVoltage = emon1.Vrms; //extract Vrms into Variable
float Irms = emon1.Irms; //extract Irms into Variable
float apparentPower2 = emon2.apparentPower; //extract Apparent Power into variable
float powerFactor2 = emon2.powerFactor; //extract Power Factor into Variable
float supplyVoltage2 = emon2.Vrms; //extract Vrms into Variable
float Irms2 = emon2.Irms; //extract Irms into Variable
float apparentPower3 = emon3.apparentPower; //extract Apparent Power into variable
float powerFactor3 = emon3.powerFactor; //extract Power Factor into Variable
float supplyVoltage3 = emon3.Vrms; //extract Vrms into Variable
float Irms3 = emon3.Irms; //extract Irms into Variable
if(apparentPower > 0 && apparentPower < 10000){
gw.send(apparentPowerMsg.set(apparentPower,1));
}
if(powerFactor > 0 && powerFactor < 10000){
gw.send(powerFActorMsg.set(powerFactor,1));
}
if(supplyVoltage > 0 && supplyVoltage < 1000){
gw.send(supplyVoltageMsg.set(supplyVoltage,1));
}
if(Irms > 0 && Irms < 1000){
gw.send(IrmsMsg.set(Irms,1));
}
if(apparentPower2 > 0 && apparentPower2 < 10000){
gw.send(apparentPowerMsg2.set(apparentPower2,1));
}
if(powerFactor2 > 0 && powerFactor2 < 10000){
gw.send(powerFActorMsg2.set(powerFactor2,1));
}
if(supplyVoltage2 > 0 && supplyVoltage2 < 1000){
gw.send(supplyVoltageMsg2.set(supplyVoltage2,1));
}
if(Irms2 > 0 && Irms2 < 1000){
gw.send(IrmsMsg2.set(Irms2,1));
}
if(apparentPower3 > 0 && apparentPower3 < 10000){
gw.send(apparentPowerMsg3.set(apparentPower3,1));
}
if(powerFactor3 > 0 && powerFactor3 < 10000){
gw.send(powerFActorMsg3.set(powerFactor3,1));
}
if(supplyVoltage3 > 0 && supplyVoltage3 < 1000){
gw.send(supplyVoltageMsg3.set(supplyVoltage3,1));
}
if(Irms3 > 0 && Irms3 < 1000){
gw.send(IrmsMsg3.set(Irms3,1));
}
lastSend2 = now;
}
}