/*
Arduino & OpenEnergyMonitor
Test & Calibration sketch
author Mirco Piccin aka pitusso
*/
// Include Emon Library
#include <Esp8266EasyIoT.h>
#include <SoftwareSerial.h>
#include "EmonLib.h"
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define ANALOGSENSORPIN A0
float lastvalue;
float valuekw;
Esp8266EasyIoT esp;
SoftwareSerial serialEsp(11, 12);
//DHT dht;
//float lastTemp;
//float lastHum;
//Esp8266EasyIoTMsg msgHum(CHILD_ID_HUM, V_HUM);
// Esp8266EasyIoTMsg(uint8_t sensor, uint8_t type);
Esp8266EasyIoTMsg corrente(CHILD_ID_HUM, V_ANALOG_VALUE);
Esp8266EasyIoTMsg correntekw(CHILD_ID_HUM, V_ANALOG_VALUE);
//Calibrations
const int volt = 220;
const float ct_calibration = 29;
//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("Sensors test starting...");
//initialize Emon instance
emon1.current(currentSensorPin, ct_calibration);
serialEsp.begin(9600);
Serial.begin(115200);
Serial.println("EasyIoTEsp init");
esp.begin(NULL, 13, &serialEsp, &Serial);
//esp.begin(NULL, &serialEsp);
// dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
pinMode(A0, INPUT);
// Serial.println("present S_HUM");
esp.present(CHILD_ID_HUM,S_ANALOG_INPUT);
//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) ; //diviso 10 per leggere Kw/h
if (isnan(value)) {
Serial.println("Failed reading value from SCT");
}
else if (value != lastvalue)
{
lastvalue = value;
valuekw = value / 1000 ;
esp.send(corrente.set(value, 1));
esp.send(correntekw.set(value, 1));
//print values
Serial.print("Power W ");
Serial.println(value);
Serial.print("Power KW ");
Serial.println(valuekw);
delay(5000);
}
}
Please Log in or Create an account to join the conversation.
cdj wrote: Hi people,
Someone know how to display two values under same sensor ?
I've add a field Sensor.AnalogValue2 to EasyIot node config but how to assign to this field a value?
this is my sketch, something is wrong, i know...
/* Arduino & OpenEnergyMonitor Test & Calibration sketch author Mirco Piccin aka pitusso */ // Include Emon Library #include <Esp8266EasyIoT.h> #include <SoftwareSerial.h> #include "EmonLib.h" #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define ANALOGSENSORPIN A0 float lastvalue; float valuekw; Esp8266EasyIoT esp; SoftwareSerial serialEsp(11, 12); //DHT dht; //float lastTemp; //float lastHum; //Esp8266EasyIoTMsg msgHum(CHILD_ID_HUM, V_HUM); // Esp8266EasyIoTMsg(uint8_t sensor, uint8_t type); Esp8266EasyIoTMsg corrente(CHILD_ID_HUM, V_ANALOG_VALUE); Esp8266EasyIoTMsg correntekw(CHILD_ID_HUM, V_ANALOG_VALUE); //Calibrations const int volt = 220; const float ct_calibration = 29; //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("Sensors test starting..."); //initialize Emon instance emon1.current(currentSensorPin, ct_calibration); serialEsp.begin(9600); Serial.begin(115200); Serial.println("EasyIoTEsp init"); esp.begin(NULL, 13, &serialEsp, &Serial); //esp.begin(NULL, &serialEsp); // dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); pinMode(A0, INPUT); // Serial.println("present S_HUM"); esp.present(CHILD_ID_HUM,S_ANALOG_INPUT); //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) ; //diviso 10 per leggere Kw/h if (isnan(value)) { Serial.println("Failed reading value from SCT"); } else if (value != lastvalue) { lastvalue = value; valuekw = value / 1000 ; esp.send(corrente.set(value, 1)); esp.send(correntekw.set(value, 1)); //print values Serial.print("Power W "); Serial.println(value); Serial.print("Power KW "); Serial.println(valuekw); delay(5000); } }
Thanks
Dario
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
cdj wrote: But in thermostat you print forecast in a second line...
i need only same value of first line (w) /1000....
So is it possible to send only one value and print a line with same value/1000 ?
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.