Browse Source

New sensors tab in web UI for all sensors

fastled
Xose Pérez 7 years ago
parent
commit
d91d5eedb1
9 changed files with 3191 additions and 3134 deletions
  1. +1
    -1
      code/espurna/config/sensors.h
  2. BIN
      code/espurna/data/index.html.gz
  3. +78
    -31
      code/espurna/sensor.ino
  4. +2
    -2
      code/espurna/sensors/EmonSensor.h
  5. +3051
    -3079
      code/espurna/static/index.html.gz.h
  6. +4
    -0
      code/espurna/ws.ino
  7. +2
    -1
      code/html/custom.css
  8. +3
    -1
      code/html/custom.js
  9. +50
    -19
      code/html/index.html

+ 1
- 1
code/espurna/config/sensors.h View File

@ -240,7 +240,7 @@
//------------------------------------------------------------------------------
#ifndef EMON_ANALOG_SUPPORT
#define EMON_ANALOG_SUPPORT 0 // Do not build support by default
#define EMON_ANALOG_SUPPORT 1 // Do not build support by default
#endif
#if EMON_ANALOG_SUPPORT


BIN
code/espurna/data/index.html.gz View File


+ 78
- 31
code/espurna/sensor.ino View File

@ -107,12 +107,6 @@ double _sensorProcess(magnitude_t type, double value) {
return roundTo(value, _sensorDecimals(type));
}
void _sensorConfigure() {
_sensor_realtime = getSetting("apiRealTime", API_REAL_TIME_VALUES).toInt() == 1;
_sensor_temperature_units = getSetting("tmpUnits", SENSOR_TEMPERATURE_UNITS).toInt();
_sensor_temperature_correction = getSetting("tmpCorrection", SENSOR_TEMPERATURE_CORRECTION).toFloat();
}
#if WEB_SUPPORT
void _sensorWebSocketSendData(JsonObject& root) {
@ -147,6 +141,24 @@ void _sensorWebSocketSendData(JsonObject& root) {
void _sensorWebSocketStart(JsonObject& root) {
bool hasSensors = false;
for (unsigned char i=0; i<_sensors.size(); i++) {
BaseSensor * sensor = _sensors[i];
#if EMON_ANALOG_SUPPORT
if (sensor->getID() == SENSOR_EMON_ANALOG_ID) {
root["emonVisible"] = 1;
root["pwrRatioC"] = ((EmonAnalogSensor *) sensor)->getCurrentRatio(0);
root["pwrVoltage"] = ((EmonAnalogSensor *) sensor)->getVoltage();
hasSensors = true;
}
#endif
}
if (hasSensors) root["sensorsVisible"] = 1;
/*
// Sensors manifest
JsonArray& manifest = root.createNestedArray("manifest");
@ -166,13 +178,6 @@ void _sensorWebSocketStart(JsonObject& root) {
}
void _sensorWebSocketReceiveData() {
//_emon.setCurrentRatio(getSetting("pwrRatioC", EMON_CURRENT_RATIO).toFloat());
//_power_voltage = getSetting("pwrVoltage", POWER_VOLTAGE).toFloat();
}
void _sensorAPISetup() {
for (unsigned char magnitude_id=0; magnitude_id<_magnitudes.size(); magnitude_id++) {
@ -222,17 +227,12 @@ void _sensorPost() {
// Sensor initialization
// -----------------------------------------------------------------------------
void _sensorRegister(BaseSensor * sensor) {
sensor->begin();
_sensors.push_back(sensor);
}
void _sensorInit() {
#if ANALOG_SUPPORT
{
AnalogSensor * sensor = new AnalogSensor();
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -240,7 +240,7 @@ void _sensorInit() {
{
BMX280Sensor * sensor = new BMX280Sensor();
sensor->setAddress(BMX280_ADDRESS);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -248,7 +248,7 @@ void _sensorInit() {
{
DallasSensor * sensor = new DallasSensor();
sensor->setGPIO(DALLAS_PIN);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -257,7 +257,7 @@ void _sensorInit() {
DHTSensor * sensor = new DHTSensor();
sensor->setGPIO(DHT_PIN);
sensor->setType(DHT_TYPE);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -267,7 +267,7 @@ void _sensorInit() {
sensor->setGPIO(DIGITAL_PIN);
sensor->setMode(DIGITAL_PIN_MODE);
sensor->setDefault(DIGITAL_DEFAULT_STATE);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -278,7 +278,7 @@ void _sensorInit() {
sensor->setVoltage(EMON_MAINS_VOLTAGE);
sensor->setReference(EMON_REFERENCE_VOLTAGE);
sensor->setCurrentRatio(0, EMON_CURRENT_RATIO);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -294,7 +294,7 @@ void _sensorInit() {
sensor->setCurrentRatio(1, EMON_CURRENT_RATIO);
sensor->setCurrentRatio(2, EMON_CURRENT_RATIO);
sensor->setCurrentRatio(3, EMON_CURRENT_RATIO);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -304,7 +304,7 @@ void _sensorInit() {
sensor->setVoltage(EMON_MAINS_VOLTAGE);
sensor->setReference(EMON_REFERENCE_VOLTAGE);
sensor->setCurrentRatio(0, EMON_CURRENT_RATIO);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -315,7 +315,7 @@ void _sensorInit() {
sensor->setMode(EVENTS_PIN_MODE);
sensor->setDebounceTime(EVENTS_DEBOUNCE);
sensor->setInterruptMode(EVENTS_INTERRUPT_MODE);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -324,7 +324,7 @@ void _sensorInit() {
MHZ19Sensor * sensor = new MHZ19Sensor();
sensor->setRX(MHZ19_RX_PIN);
sensor->setTX(MHZ19_TX_PIN);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -333,7 +333,7 @@ void _sensorInit() {
PMSX003Sensor * sensor = new PMSX003Sensor();
sensor->setRX(PMS_RX_PIN);
sensor->setTX(PMS_TX_PIN);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -341,7 +341,7 @@ void _sensorInit() {
{
SHT3XI2CSensor * sensor = new SHT3XI2CSensor();
sensor->setAddress(SHT3X_I2C_ADDRESS);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
@ -349,12 +349,56 @@ void _sensorInit() {
{
SI7021Sensor * sensor = new SI7021Sensor();
sensor->setAddress(SI7021_ADDRESS);
_sensorRegister(sensor);
_sensors.push_back(sensor);
}
#endif
}
void _sensorConfigure() {
for (unsigned char i=0; i<_sensors.size(); i++) {
BaseSensor * sensor = _sensors[i];
#if EMON_ANALOG_SUPPORT
if (sensor->getID() == SENSOR_EMON_ANALOG_ID) {
unsigned int expected = getSetting("pwrExpectedP", 0).toInt();
if (expected > 0) {
((EmonAnalogSensor *) sensor)->expectedPower(0, expected);
setSetting("pwrRatioC", ((EmonAnalogSensor *) sensor)->getCurrentRatio(0));
}
if (getSetting("pwrResetCalibration", 0).toInt() == 1) {
((EmonAnalogSensor *) sensor)->setCurrentRatio(0, EMON_CURRENT_RATIO);
delSetting("pwrRatioC");
}
((EmonAnalogSensor *) sensor)->setCurrentRatio(0, getSetting("pwrRatioC", EMON_CURRENT_RATIO).toFloat());
((EmonAnalogSensor *) sensor)->setVoltage(getSetting("pwrVoltage", EMON_MAINS_VOLTAGE).toInt());
delSetting("pwrExpectedP");
delSetting("pwrResetCalibration");
}
#endif
// Force sensor to reload config
sensor->begin();
}
// General sensor settings
_sensor_realtime = getSetting("apiRealTime", API_REAL_TIME_VALUES).toInt() == 1;
_sensor_temperature_units = getSetting("tmpUnits", SENSOR_TEMPERATURE_UNITS).toInt();
_sensor_temperature_correction = getSetting("tmpCorrection", SENSOR_TEMPERATURE_CORRECTION).toFloat();
// Save settings
saveSettings();
}
void _magnitudesInit() {
for (unsigned char i=0; i<_sensors.size(); i++) {
@ -430,6 +474,9 @@ void sensorSetup() {
// Load sensors
_sensorInit();
// Configure stored values
_sensorConfigure();
// Load magnitudes
_magnitudesInit();


+ 2
- 2
code/espurna/sensors/EmonSensor.h View File

@ -36,7 +36,7 @@ class EmonSensor : public BaseSensor {
unsigned int actual = _current[channel] * _voltage;
if (actual == 0) return;
if (expected == actual) return;
_current_ratio[channel] = _current_ratio[channel] * (expected / actual);
_current_ratio[channel] = _current_ratio[channel] * ((double) expected / (double) actual);
_dirty = true;
}
@ -66,7 +66,7 @@ class EmonSensor : public BaseSensor {
double getVoltage() {
return _voltage;
}
double getReference() {
return _reference;
}


+ 3051
- 3079
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 4
- 0
code/espurna/ws.ino View File

@ -159,6 +159,8 @@ void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) {
#if POWER_PROVIDER != POWER_PROVIDER_NONE
/*
if (key == "pwrExpectedP") {
powerCalibrate(POWER_MAGNITUDE_ACTIVE, value.toFloat());
changed = true;
@ -191,6 +193,8 @@ void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) {
continue;
}
*/
#endif
// -----------------------------------------------------------------


+ 2
- 1
code/html/custom.css View File

@ -79,9 +79,10 @@
.pure-g {
margin-bottom: 20px;
}
.pure-g legend {
.pure-form legend {
font-weight: bold;
letter-spacing: 0;
margin-bottom: 1em;
}
.l-box {
padding-right: 1px;


+ 3
- 1
code/html/custom.js View File

@ -486,7 +486,9 @@ function initMagnitudes(data) {
}
function getManifest(sensor_id) {
for (row of manifest) if (row.sensor_id == sensor_id) return row;
for (i in manifest) {
if (manifest[i].sensor_id == sensor_id) return manifest[i];
}
return null;
}


+ 50
- 19
code/html/index.html View File

@ -106,6 +106,10 @@
<a href="#" class="pure-menu-link" data="panel-color">LIGHTS</a>
</li>
<li class="pure-menu-item module module-sensors">
<a href="#" class="pure-menu-link" data="panel-sensors">SENSORS</a>
</li>
<li class="pure-menu-item module module-dcz">
<a href="#" class="pure-menu-link" data="panel-domoticz">DOMOTICZ</a>
</li>
@ -114,10 +118,6 @@
<a href="#" class="pure-menu-link" data="panel-idb">INFLUXDB</a>
</li>
<li class="pure-menu-item module module-hlw module-emon module-v9261f">
<a href="#" class="pure-menu-link" data="panel-power">POWER</a>
</li>
<li class="pure-menu-item module module-rfb">
<a href="#" class="pure-menu-link" data="panel-rfb">RFBRIDGE</a>
</li>
@ -171,6 +171,7 @@
<div id="magnitudes">
</div>
<!--
<div class="pure-g module module-emon module-hlw module-v9261f module-ech1560">
<label class="pure-u-1 pure-u-sm-1-4">Current</label>
<input class="pure-u-1 pure-u-sm-3-4" type="text" name="pwrCurrent" post=" A" readonly />
@ -205,6 +206,7 @@
<label class="pure-u-1 pure-u-sm-1-4">Energy</label>
<input class="pure-u-1 pure-u-sm-3-4" type="text" name="pwrEnergy" post=" J (aggregated)" readonly />
</div>
-->
<div class="pure-u-1 state">
@ -868,12 +870,12 @@
</div>
<div class="panel" id="panel-power">
<div class="panel" id="panel-sensors">
<div class="header">
<h1>POWER CALIBRATION</h1>
<h1>SENSOR CONFIGURATION</h1>
<h2>
Configure and calibrate your power monitor device. Use a pure resistive load and introduce the expected values for active power, current and voltage. Use the nominal values or a multimeter to get the proper numbers. Set any field to 0 to leave the calibration value untouched.
Configure and calibrate your device sensors.
</h2>
</div>
@ -881,9 +883,13 @@
<fieldset>
<!--
<legend>General</legend>
<div class="pure-g">
<label class="pure-u-1 pure-u-sm-1-4">Read interval</label>
<select class="pure-u-1 pure-u-sm-1-4" name="pwrReadEvery">
<select class="pure-u-1 pure-u-sm-1-4" name="snsRead">
<option value="2000">2 seconds</option>
<option value="6000">6 seconds</option>
<option value="10000">10 seconds</option>
@ -901,7 +907,7 @@
<div class="pure-g">
<label class="pure-u-1 pure-u-sm-1-4">Report interval</label>
<select class="pure-u-1 pure-u-sm-1-4" name="pwrReportEvery">
<select class="pure-u-1 pure-u-sm-1-4" name="snsReport">
<option value="6000">6 seconds</option>
<option value="10000">10 seconds</option>
<option value="30000">30 seconds</option>
@ -911,19 +917,49 @@
<div class="pure-u-0 pure-u-md-1-2">&nbsp;</div>
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">
Select the interval between reports via MQTT.<br />
Select the interval between reports via MQTT / InfluxDB / Domoticz / ...<br />
This can't be less than the reading interval above.<br />
The default and recommended value is 1 minute.
</div>
</div>
-->
<legend>Energy monitor</legend>
<!--
<div class="pure-g module module-emon">
<label class="pure-u-1 pure-u-md-1-4">Current Ratio</label>
<input class="pure-u-1 pure-u-md-3-4" name="pwrRatioC" type="text" size="8" tabindex="51" />
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">In A/V. This number is usually written in the CT if it has a built-in burden resistor, otherwise you will have to calculate it according to the resistor you are using.</div>
</div>
-->
<div class="pure-g module module-emon">
<label class="pure-u-1 pure-u-md-1-4">Voltage</label>
<input class="pure-u-1 pure-u-md-3-4" name="pwrVoltage" type="text" size="8" tabindex="52" />
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">Mains voltage in your system (in V).</div>
</div>
<div class="pure-g module module-hlw module-emon module-v9261f">
<label class="pure-u-1 pure-u-md-1-4">AC RMS Active Power</label>
<input class="pure-u-1 pure-u-md-3-4 pwrExpected" name="pwrExpectedP" type="text" size="8" tabindex="51" placeholder="0" />
<label class="pure-u-1 pure-u-md-1-4">Expected Power</label>
<input class="pure-u-1 pure-u-md-3-4 pwrExpected" name="pwrExpectedP" type="text" size="8" tabindex="53" placeholder="0" />
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">In Watts (W). If you are using a pure resistive load like a bulb this will be writen on it, otherwise use a socket multimeter to get this value.</div>
<div class="pure-u-1 pure-u-md-3-4 hint">Calibrate your sensor connecting a pure resistive load (like a bulb) and enter here the its nominal power or use a multimeter. In Watts.</div>
</div>
<div class="pure-g module module-hlw module-emon module-v9261f">
<div class="pure-u-1 pure-u-sm-1-4"><label>Reset calibration</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="pwrResetCalibration" tabindex="59" /></div>
<div class="pure-u-0 pure-u-md-1-2">&nbsp;</div>
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">Move this switch to ON and press "Update" to revert to factory calibration values.</div>
</div>
<!--
<div class="pure-g module module-v9261f">
<label class="pure-u-1 pure-u-md-1-4">AC Power Factor</label>
<input class="pure-u-1 pure-u-md-3-4 pwrExpected" name="pwrExpectedF" type="text" size="8" tabindex="51" placeholder="0" />
@ -945,12 +981,7 @@
<div class="pure-u-1 pure-u-md-3-4 hint">In Ampers (A). If you are using a pure resistive load like a bulb this will the ratio between the two previous values, i.e. power / voltage. You can also use a current clamp around one fo the power wires to get this value.</div>
</div>
<div class="pure-g module module-hlw module-emon module-v9261f">
<div class="pure-u-1 pure-u-sm-1-4"><label>Reset calibration</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="pwrResetCalibration" /></div>
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">Move this switch to ON and press "Update" to revert to factory calibration values.</div>
</div>
-->
</fieldset>
</div>


Loading…
Cancel
Save