Browse Source

Change sensor read and report interval from web UI

fastled
Xose Pérez 7 years ago
parent
commit
439881a741
6 changed files with 3126 additions and 3120 deletions
  1. +9
    -2
      code/espurna/config/sensors.h
  2. BIN
      code/espurna/data/index.html.gz
  3. +21
    -17
      code/espurna/sensor.ino
  4. +1
    -3
      code/espurna/sensors/DallasSensor.h
  5. +3068
    -3058
      code/espurna/static/index.html.gz.h
  6. +27
    -40
      code/html/index.html

+ 9
- 2
code/espurna/config/sensors.h View File

@ -4,10 +4,16 @@
#define SENSOR_DEBUG 0 // Debug sensors
#define SENSOR_READ_INTERVAL 6000 // Read data from sensors every 6 seconds
#define SENSOR_READ_INTERVAL 6 // Read data from sensors every 6 seconds
#define SENSOR_READ_MIN_INTERVAL 6 // Minimum read interval
#define SENSOR_READ_MAX_INTERVAL 3600 // Maximum read interval
#define SENSOR_REPORT_EVERY 10 // Report every this many readings
#define SENSOR_REPORT_MIN_EVERY 1 // Minimum every value
#define SENSOR_REPORT_MAX_EVERY 12 // Maximum
#define SENSOR_USE_INDEX 0 // Use the index in topic (i.e. temperature/0)
// even if just one sensor (0 for backwards compatibility)
// even if just one sensor (0 for backwards compatibility)
#ifndef SENSOR_TEMPERATURE_UNITS
#define SENSOR_TEMPERATURE_UNITS TMP_CELSIUS // Temperature units (TMP_CELSIUS | TMP_FAHRENHEIT)
@ -146,6 +152,7 @@
#endif
#define DALLAS_RESOLUTION 9 // Not used atm
#define DALLAS_READ_INTERVAL 2000 // Force sensor read & cache every 2 seconds
//------------------------------------------------------------------------------
// DHTXX temperature/humidity sensor


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


+ 21
- 17
code/espurna/sensor.ino View File

@ -29,6 +29,8 @@ std::vector<sensor_magnitude_t> _magnitudes;
unsigned char _counts[MAGNITUDE_MAX];
bool _sensor_realtime = API_REAL_TIME_VALUES;
unsigned long _sensor_read_interval = 1000 * SENSOR_READ_INTERVAL;
unsigned int _sensor_report_every = SENSOR_REPORT_EVERY;
unsigned char _sensor_temperature_units = SENSOR_TEMPERATURE_UNITS;
double _sensor_temperature_correction = SENSOR_TEMPERATURE_CORRECTION;
@ -91,7 +93,6 @@ String _sensorUnits(magnitude_t type) {
if (type == MAGNITUDE_POWER_FACTOR) return String("%");
if (type == MAGNITUDE_ENERGY) return String("J");
if (type == MAGNITUDE_ENERGY_DELTA) return String("J");
if (type == MAGNITUDE_EVENTS) return String("/min");
if (type == MAGNITUDE_PM1dot0) return String("µg/m3");
if (type == MAGNITUDE_PM2dot5) return String("µg/m3");
if (type == MAGNITUDE_PM10) return String("µg/m3");
@ -133,38 +134,39 @@ void _sensorWebSocketSendData(JsonObject& root) {
}
//root["apiRealTime"] = _sensor_realtime;
root["tmpUnits"] = _sensor_temperature_units;
root["tmpCorrection"] = _sensor_temperature_correction;
if (hasTemperature) root["temperatureVisible"] = 1;
}
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["pwrVoltage"] = ((EmonAnalogSensor *) sensor)->getVoltage();
hasSensors = true;
}
#endif
#if HLW8012_SUPPORT
if (sensor->getID() == SENSOR_HLW8012_ID) {
root["hlwVisible"] = 1;
hasSensors = true;
}
#endif
}
if (hasSensors) root["sensorsVisible"] = 1;
if (_magnitudes.size() > 0) {
root["sensorsVisible"] = 1;
//root["apiRealTime"] = _sensor_realtime;
root["tmpUnits"] = _sensor_temperature_units;
root["tmpCorrection"] = _sensor_temperature_correction;
root["snsRead"] = _sensor_read_interval / 1000;
root["snsReport"] = _sensor_report_every;
}
/*
// Sensors manifest
@ -466,6 +468,8 @@ void _sensorConfigure() {
}
// General sensor settings
_sensor_read_interval = 1000 * constrain(getSetting("snsRead", SENSOR_READ_INTERVAL).toInt(), SENSOR_READ_MIN_INTERVAL, SENSOR_READ_MAX_INTERVAL);
_sensor_report_every = constrain(getSetting("snsReport", SENSOR_REPORT_EVERY).toInt(), SENSOR_REPORT_MIN_EVERY, SENSOR_REPORT_MAX_EVERY);
_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();
@ -590,10 +594,10 @@ void sensorLoop() {
_sensorTick();
// Check if we should read new data
if (millis() - last_update > SENSOR_READ_INTERVAL) {
if (millis() - last_update > _sensor_read_interval) {
last_update = millis();
report_count = (report_count + 1) % SENSOR_REPORT_EVERY;
report_count = (report_count + 1) % _sensor_report_every;
double current;
double filtered;
@ -631,9 +635,9 @@ void sensorLoop() {
_sensorUnits(magnitude.type).c_str()
);
}
#endif
#endif // SENSOR_DEBUG
// Time to report (we do it every SENSOR_REPORT_EVERY readings)
// Time to report (we do it every _sensor_report_every readings)
if (report_count == 0) {
filtered = magnitude.filter->result();
@ -653,7 +657,7 @@ void sensorLoop() {
} else {
mqttSend(_sensorTopic(magnitude.type).c_str(), buffer);
}
#endif
#endif // MQTT_SUPPORT
#if INFLUXDB_SUPPORT
if (SENSOR_USE_INDEX || (_counts[magnitude.type] > 1)) {
@ -661,12 +665,12 @@ void sensorLoop() {
} else {
idbSend(_sensorTopic(magnitude.type).c_str(), buffer);
}
#endif
#endif // INFLUXDB_SUPPORT
#if DOMOTICZ_SUPPORT
{
char key[15];
snprintf_P(key, sizeof(key), PSTR("dczSensor%d"), i);
snprintf_P(key, sizeof(key), PSTR("dczMagnitude%d"), i);
if (magnitude.type == MAGNITUDE_HUMIDITY) {
int status;
if (filtered > 70) {
@ -685,7 +689,7 @@ void sensorLoop() {
domoticzSend(key, 0, buffer);
}
}
#endif
#endif // DOMOTICZ_SUPPORT
} // if (fabs(filtered - magnitude.reported) >= magnitude.min_change)
} // if (report_count == 0)


+ 1
- 3
code/espurna/sensors/DallasSensor.h View File

@ -64,7 +64,6 @@ class DallasSensor : public BaseSensor {
if (!_dirty) return;
_dirty = false;
_interval = SENSOR_READ_INTERVAL / 2;
// OneWire
if (_wire) delete _wire;
@ -85,7 +84,7 @@ class DallasSensor : public BaseSensor {
void tick() {
static unsigned long last = 0;
if (millis() - last < _interval) return;
if (millis() - last < DALLAS_READ_INTERVAL) return;
last = millis();
// Every second we either start a conversion or read the scratchpad
@ -282,7 +281,6 @@ class DallasSensor : public BaseSensor {
std::vector<ds_device_t> _devices;
unsigned char _gpio;
unsigned long _interval;
OneWire * _wire = NULL;
};

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


+ 27
- 40
code/html/index.html View File

@ -300,24 +300,6 @@
<input class="pure-u-1 pure-u-md-1-4" name="haPrefix" type="text" tabindex="15" />
</div>
<div class="pure-g module module-temperature">
<label class="pure-u-1 pure-u-sm-1-4">Temperature units</label>
<select name="tmpUnits" tabindex="16" class="pure-u-1 pure-u-md-1-4">
<option value="0">Celsius (&deg;C)</option>
<option value="1">Fahrenheit (&deg;F)</option>
</select>
</div>
<div class="pure-g module module-temperature">
<label class="pure-u-1 pure-u-md-1-4">Temperature correction</label>
<input name="tmpCorrection" class="pure-u-1 pure-u-md-1-4" type="number" action="reboot" min="-100" step="0.1" max="100" tabindex="18" />
<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">
Temperature correction value is added to the measured value which may be inaccurate due to many factors. The value can be negative.
</div>
</div>
</fieldset>
</div>
</div>
@ -784,47 +766,52 @@
<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="snsRead">
<option value="2000">2 seconds</option>
<option value="6000">6 seconds</option>
<option value="10000">10 seconds</option>
<option value="15000">15 seconds</option>
<option value="30000">30 seconds</option>
<option value="60000">60 seconds</option>
<option value="6">6 seconds</option>
<option value="10">10 seconds</option>
<option value="15">15 seconds</option>
<option value="30">30 seconds</option>
<option value="60">1 minute</option>
<option value="300">5 minutes</option>
</select>
<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 readings. These will be filtered and averaged for the report.<br />
The default and recommended value is 6 seconds.
Select the interval between readings. These will be filtered and averaged for the report. The default and recommended value is 6 seconds.
</div>
</div>
<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="snsReport">
<option value="6000">6 seconds</option>
<option value="10000">10 seconds</option>
<option value="30000">30 seconds</option>
<option value="60000">1 minute</option>
<option value="300000">5 minutes</option>
</select>
<label class="pure-u-1 pure-u-sm-1-4">Report every</label>
<div class="pure-u-1 pure-u-sm-1-4"><input name="snsReport" class="pure-u-23-24" type="number" min="1" step="1" max="12" /></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">
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.
Select the number of readings to average and report
</div>
</div>
-->
<div class="pure-g module module-temperature">
<label class="pure-u-1 pure-u-sm-1-4">Temperature units</label>
<select name="tmpUnits" tabindex="16" class="pure-u-1 pure-u-md-1-4">
<option value="0">Celsius (&deg;C)</option>
<option value="1">Fahrenheit (&deg;F)</option>
</select>
</div>
<div class="pure-g module module-temperature">
<label class="pure-u-1 pure-u-md-1-4">Temperature correction</label>
<input name="tmpCorrection" class="pure-u-1 pure-u-md-1-4" type="number" action="reboot" min="-100" step="0.1" max="100" tabindex="18" />
<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">
Temperature correction value is added to the measured value which may be inaccurate due to many factors. The value can be negative.
</div>
</div>
<legend class="module module-hlw module-emon">Energy monitor</legend>


Loading…
Cancel
Save