/*
Arduino & OpenEnergyMonitor
Test & Calibration sketch
author Mirco Piccin aka pitusso
*/
/* mod by Cdj for EasyIOT
* Using PRESSURE Widget to print watt in forecast space
*/
// Include Emon Library
#include <Esp8266EasyIoT.h>
#include <SoftwareSerial.h>
#include "EmonLib.h"
#define CORRENTE 0
float lastvalue;
float valuekw;
Esp8266EasyIoT esp;
SoftwareSerial serialEsp(11, 12);
// Esp8266EasyIoTMsg(uint8_t sensor, uint8_t type);
Esp8266EasyIoTMsg correntekw(CORRENTE, V_PRESSURE);
Esp8266EasyIoTMsg corrente(CORRENTE, V_FORECAST);
//Calibrations
const int volt = 210;
const float ct_calibration = 29.75; //orig 29
//Nel caso specifico, leggo un consumo di 260w, mentre in realtà in mio lettore di consumi ne registra 220w. Quindi:
//nuova_calibrazione = (220 / 260) * 29 = 24.5
//Sensor pins
const int currentSensorPin = A0;
float Irms = 0;
// Create an Emon instance
EnergyMonitor emon1;
void setup() {
// start serial port:
Serial.begin(115200);
Serial.println("DomoDesk Energy Monitor Start...");
//initialize Emon instance
emon1.current(currentSensorPin, ct_calibration);
serialEsp.begin(9600);
Serial.begin(115200);
Serial.println("EasyIoTEsp init");
esp.begin(NULL, 13, &serialEsp, &Serial);
pinMode(A0, INPUT);
esp.present(CORRENTE,S_BARO);
//void present(uint8_t sensorId, uint8_t sensorType, bool ack=false);
}
void loop() {
//read sensors
Irms = emon1.calcIrms(1480);
while(!esp.process());
float value = (Irms*volt) ;
if (isnan(value)) {
Serial.println("Failed reading value from SCT");
}
else if (value != lastvalue )
{
lastvalue = value;
valuekw = value / 1000 ;
}
esp.send(correntekw.set(valuekw, 1));
esp.send(corrente.set(value, 2));
//print values
Serial.print("Consumo in W/h ");
Serial.println(value);
Serial.print("Consumo in KW/h ");
Serial.println(valuekw);
delay(8000);
}
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
cdj wrote: If someone could be interested there's a link to use it only with ESP but my technical skill is not sufficient to modify it.
www.esp8266.com/viewtopic.php?f=32&t=3112
Please Log in or Create an account to join the conversation.