Browse Source

Added sensor IDs

fastled
Xose Pérez 6 years ago
parent
commit
6e839e3d72
16 changed files with 206 additions and 129 deletions
  1. +98
    -65
      code/espurna/config/sensors.h
  2. +46
    -38
      code/espurna/sensor.ino
  3. +1
    -0
      code/espurna/sensors/AnalogSensor.h
  4. +8
    -6
      code/espurna/sensors/BMX280Sensor.h
  5. +17
    -13
      code/espurna/sensors/BaseSensor.h
  6. +7
    -6
      code/espurna/sensors/DHTSensor.h
  7. +6
    -0
      code/espurna/sensors/DallasSensor.h
  8. +1
    -0
      code/espurna/sensors/DigitalSensor.h
  9. +1
    -0
      code/espurna/sensors/EmonADC121Sensor.h
  10. +1
    -1
      code/espurna/sensors/EmonADS1X15Sensor.h
  11. +1
    -0
      code/espurna/sensors/EmonAnalogSensor.h
  12. +1
    -0
      code/espurna/sensors/EventSensor.h
  13. +1
    -0
      code/espurna/sensors/MHZ19Sensor.h
  14. +1
    -0
      code/espurna/sensors/PMSX003Sensor.h
  15. +6
    -0
      code/espurna/sensors/SI7021Sensor.h
  16. +10
    -0
      code/html/custom.js

+ 98
- 65
code/espurna/config/sensors.h View File

@ -1,6 +1,6 @@
// -----------------------------------------------------------------------------
// SENSORS
// -----------------------------------------------------------------------------
// =============================================================================
// SENSORS - General data
// =============================================================================
#define SENSOR_DEBUG 0 // Debug sensors #define SENSOR_DEBUG 0 // Debug sensors
@ -25,53 +25,82 @@
#define HUMIDITY_MIN_CHANGE 0 // Minimum humidity change to report #define HUMIDITY_MIN_CHANGE 0 // Minimum humidity change to report
#endif #endif
#define SENSOR_TEMPERATURE_DECIMALS 1
#define SENSOR_HUMIDITY_DECIMALS 0
#define SENSOR_PRESSURE_DECIMALS 2
#define SENSOR_ANALOG_DECIMALS 0
#define SENSOR_EVENTS_DECIMALS 0
#define SENSOR_CURRENT_DECIMALS 3
#define SENSOR_VOLTAGE_DECIMALS 0
#define SENSOR_POWER_DECIMALS 0
#define SENSOR_POWER_FACTOR_DECIMALS 0
#define SENSOR_ENERGY_DECIMALS 0
#define SENSOR_PM1dot0_DECIMALS 0
#define SENSOR_PM2dot5_DECIMALS 0
#define SENSOR_PM10_DECIMALS 0
#define SENSOR_CO2_DECIMALS 0
#define SENSOR_UNKNOWN_TOPIC "unknown"
#define SENSOR_TEMPERATURE_TOPIC "temperature"
#define SENSOR_HUMIDITY_TOPIC "humidity"
#define SENSOR_PRESSURE_TOPIC "pressure"
#define SENSOR_CURRENT_TOPIC "current"
#define SENSOR_VOLTAGE_TOPIC "voltage"
#define SENSOR_ACTIVE_POWER_TOPIC "power"
#define SENSOR_APPARENT_POWER_TOPIC "apparent"
#define SENSOR_REACTIVE_POWER_TOPIC "reactive"
#define SENSOR_POWER_FACTOR_TOPIC "factor"
#define SENSOR_ENERGY_TOPIC "energy"
#define SENSOR_ENERGY_DELTA_TOPIC "energy_delta"
#define SENSOR_PM1dot0_TOPIC "pm1dot0"
#define SENSOR_PM2dot5_TOPIC "pm2dot5"
#define SENSOR_PM10_TOPIC "pm10"
#define SENSOR_ANALOG_TOPIC "analog"
#define SENSOR_DIGITAL_TOPIC "digital"
#define SENSOR_EVENTS_TOPIC "events"
#define SENSOR_CO2_TOPIC "co2"
#define HUMIDITY_NORMAL 0 #define HUMIDITY_NORMAL 0
#define HUMIDITY_COMFORTABLE 1 #define HUMIDITY_COMFORTABLE 1
#define HUMIDITY_DRY 2 #define HUMIDITY_DRY 2
#define HUMIDITY_WET 3 #define HUMIDITY_WET 3
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Magnitudes
//--------------------------------------------------------------------------------
#define MAGNITUDE_TEMPERATURE_DECIMALS 1
#define MAGNITUDE_HUMIDITY_DECIMALS 0
#define MAGNITUDE_PRESSURE_DECIMALS 2
#define MAGNITUDE_ANALOG_DECIMALS 0
#define MAGNITUDE_EVENTS_DECIMALS 0
#define MAGNITUDE_CURRENT_DECIMALS 3
#define MAGNITUDE_VOLTAGE_DECIMALS 0
#define MAGNITUDE_POWER_DECIMALS 0
#define MAGNITUDE_POWER_FACTOR_DECIMALS 0
#define MAGNITUDE_ENERGY_DECIMALS 0
#define MAGNITUDE_PM1dot0_DECIMALS 0
#define MAGNITUDE_PM2dot5_DECIMALS 0
#define MAGNITUDE_PM10_DECIMALS 0
#define MAGNITUDE_CO2_DECIMALS 0
#define MAGNITUDE_UNKNOWN_TOPIC "unknown"
#define MAGNITUDE_TEMPERATURE_TOPIC "temperature"
#define MAGNITUDE_HUMIDITY_TOPIC "humidity"
#define MAGNITUDE_PRESSURE_TOPIC "pressure"
#define MAGNITUDE_CURRENT_TOPIC "current"
#define MAGNITUDE_VOLTAGE_TOPIC "voltage"
#define MAGNITUDE_ACTIVE_POWER_TOPIC "power"
#define MAGNITUDE_APPARENT_POWER_TOPIC "apparent"
#define MAGNITUDE_REACTIVE_POWER_TOPIC "reactive"
#define MAGNITUDE_POWER_FACTOR_TOPIC "factor"
#define MAGNITUDE_ENERGY_TOPIC "energy"
#define MAGNITUDE_ENERGY_DELTA_TOPIC "energy_delta"
#define MAGNITUDE_PM1dot0_TOPIC "pm1dot0"
#define MAGNITUDE_PM2dot5_TOPIC "pm2dot5"
#define MAGNITUDE_PM10_TOPIC "pm10"
#define MAGNITUDE_ANALOG_TOPIC "analog"
#define MAGNITUDE_DIGITAL_TOPIC "digital"
#define MAGNITUDE_EVENTS_TOPIC "events"
#define MAGNITUDE_CO2_TOPIC "co2"
//--------------------------------------------------------------------------------
// Sensor ID
// These should remain over time, do not modify them, only add new ones at the end
//--------------------------------------------------------------------------------
#define SENSOR_DHT_ID 0x01
#define SENSOR_DALLAS_ID 0x02
#define SENSOR_EMON_ANALOG_ID 0x03
#define SENSOR_EMON_ADC121_ID 0x04
#define SENSOR_EMON_ADS1X15_ID 0x05
#define SENSOR_HLW8012_ID 0x06
#define SENSOR_V9261F_ID 0x07
#define SENSOR_ECH1560_ID 0x08
#define SENSOR_ANALOG_ID 0x09
#define SENSOR_DIGITAL_ID 0x10
#define SENSOR_EVENTS_ID 0x11
#define SENSOR_PMSX003_ID 0x12
#define SENSOR_BMX280_ID 0x13
#define SENSOR_MHZ19_ID 0x14
#define SENSOR_SI7021_ID 0x15
// =============================================================================
// Specific data for each sensor
// =============================================================================
//------------------------------------------------------------------------------
// Analog sensor // Analog sensor
// Enable support by passing ANALOG_SUPPORT=1 build flag // Enable support by passing ANALOG_SUPPORT=1 build flag
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
#ifndef ANALOG_SUPPORT #ifndef ANALOG_SUPPORT
#define ANALOG_SUPPORT 1
#define ANALOG_SUPPORT 0
#endif #endif
#if ANALOG_SUPPORT #if ANALOG_SUPPORT
@ -79,13 +108,13 @@
#define ADC_VCC_ENABLED 0 #define ADC_VCC_ENABLED 0
#endif #endif
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// BME280/BMP280 // BME280/BMP280
// Enable support by passing BMX280_SUPPORT=1 build flag // Enable support by passing BMX280_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef BMX280_SUPPORT #ifndef BMX280_SUPPORT
#define BMX280_SUPPORT 1
#define BMX280_SUPPORT 0
#endif #endif
#ifndef BMX280_ADDRESS #ifndef BMX280_ADDRESS
@ -102,10 +131,10 @@
#define I2C_SUPPORT 1 #define I2C_SUPPORT 1
#endif #endif
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Dallas OneWire temperature sensors // Dallas OneWire temperature sensors
// Enable support by passing DALLAS_SUPPORT=1 build flag // Enable support by passing DALLAS_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef DALLAS_SUPPORT #ifndef DALLAS_SUPPORT
#define DALLAS_SUPPORT 0 #define DALLAS_SUPPORT 0
@ -117,10 +146,10 @@
#define DALLAS_RESOLUTION 9 // Not used atm #define DALLAS_RESOLUTION 9 // Not used atm
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// DHTXX temperature/humidity sensor // DHTXX temperature/humidity sensor
// Enable support by passing DHT_SUPPORT=1 build flag // Enable support by passing DHT_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef DHT_SUPPORT #ifndef DHT_SUPPORT
#define DHT_SUPPORT 0 #define DHT_SUPPORT 0
@ -131,13 +160,13 @@
#endif #endif
#ifndef DHT_TYPE #ifndef DHT_TYPE
#define DHT_TYPE DHT22
#define DHT_TYPE DHT_CHIP_DHT22
#endif #endif
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Digital sensor // Digital sensor
// Enable support by passing DIGITAL_SUPPORT=1 build flag // Enable support by passing DIGITAL_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef DIGITAL_SUPPORT #ifndef DIGITAL_SUPPORT
#define DIGITAL_SUPPORT 0 #define DIGITAL_SUPPORT 0
@ -155,9 +184,9 @@
#define DIGITAL_DEFAULT_STATE 1 #define DIGITAL_DEFAULT_STATE 1
#endif #endif
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Energy Monitor general settings // Energy Monitor general settings
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#define EMON_MAX_SAMPLES 1000 // Max number of samples to get #define EMON_MAX_SAMPLES 1000 // Max number of samples to get
#define EMON_MAX_TIME 250 // Max time in ms to sample #define EMON_MAX_TIME 250 // Max time in ms to sample
@ -169,10 +198,10 @@
#define EMON_REPORT_POWER 1 // Report power #define EMON_REPORT_POWER 1 // Report power
#define EMON_REPORT_ENERGY 1 // Report energy #define EMON_REPORT_ENERGY 1 // Report energy
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Energy Monitor based on ADC121 // Energy Monitor based on ADC121
// Enable support by passing EMON_ADC121_SUPPORT=1 build flag // Enable support by passing EMON_ADC121_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef EMON_ADC121_SUPPORT #ifndef EMON_ADC121_SUPPORT
#define EMON_ADC121_SUPPORT 0 // Do not build support by default #define EMON_ADC121_SUPPORT 0 // Do not build support by default
@ -185,10 +214,10 @@
#define I2C_SUPPORT 1 #define I2C_SUPPORT 1
#endif #endif
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Energy Monitor based on ADS1X15 // Energy Monitor based on ADS1X15
// Enable support by passing EMON_ADS1X15_SUPPORT=1 build flag // Enable support by passing EMON_ADS1X15_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef EMON_ADS1X15_SUPPORT #ifndef EMON_ADS1X15_SUPPORT
#define EMON_ADS1X15_SUPPORT 0 // Do not build support by default #define EMON_ADS1X15_SUPPORT 0 // Do not build support by default
@ -204,10 +233,10 @@
#define I2C_SUPPORT 1 #define I2C_SUPPORT 1
#endif #endif
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Energy Monitor based on interval analog GPIO // Energy Monitor based on interval analog GPIO
// Enable support by passing EMON_ANALOG_SUPPORT=1 build flag // Enable support by passing EMON_ANALOG_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef EMON_ANALOG_SUPPORT #ifndef EMON_ANALOG_SUPPORT
#define EMON_ANALOG_SUPPORT 0 // Do not build support by default #define EMON_ANALOG_SUPPORT 0 // Do not build support by default
@ -218,10 +247,10 @@
#define ADC_VCC_ENABLED 0 #define ADC_VCC_ENABLED 0
#endif #endif
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Counter sensor // Counter sensor
// Enable support by passing EVENTS_SUPPORT=1 build flag // Enable support by passing EVENTS_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef EVENTS_SUPPORT #ifndef EVENTS_SUPPORT
#define EVENTS_SUPPORT 0 // Do not build with counter support by default #define EVENTS_SUPPORT 0 // Do not build with counter support by default
@ -241,10 +270,10 @@
#define EVENTS_DEBOUNCE 50 // Do not register events within less than 10 millis #define EVENTS_DEBOUNCE 50 // Do not register events within less than 10 millis
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// MHZ19 CO2 sensor // MHZ19 CO2 sensor
// Enable support by passing MHZ19_SUPPORT=1 build flag // Enable support by passing MHZ19_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef MHZ19_SUPPORT #ifndef MHZ19_SUPPORT
#define MHZ19_SUPPORT 0 #define MHZ19_SUPPORT 0
@ -253,10 +282,10 @@
#define MHZ19_RX_PIN 13 #define MHZ19_RX_PIN 13
#define MHZ19_TX_PIN 15 #define MHZ19_TX_PIN 15
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Particle Monitor based on Plantower PMSX003 // Particle Monitor based on Plantower PMSX003
// Enable support by passing PMSX003_SUPPORT=1 build flag // Enable support by passing PMSX003_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef PMSX003_SUPPORT #ifndef PMSX003_SUPPORT
#define PMSX003_SUPPORT 0 #define PMSX003_SUPPORT 0
@ -265,10 +294,10 @@
#define PMS_RX_PIN 13 #define PMS_RX_PIN 13
#define PMS_TX_PIN 15 #define PMS_TX_PIN 15
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// SI7021 temperature & humidity sensor // SI7021 temperature & humidity sensor
// Enable support by passing SI7021_SUPPORT=1 build flag // Enable support by passing SI7021_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef SI7021_SUPPORT #ifndef SI7021_SUPPORT
#define SI7021_SUPPORT 0 #define SI7021_SUPPORT 0
@ -283,6 +312,10 @@
#define I2C_SUPPORT 1 #define I2C_SUPPORT 1
#endif #endif
// =============================================================================
// Sensor helpers configuration
// =============================================================================
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// I2C // I2C
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


+ 46
- 38
code/espurna/sensor.ino View File

@ -37,45 +37,45 @@ double _sensor_temperature_correction = SENSOR_TEMPERATURE_CORRECTION;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
String _sensorTopic(magnitude_t type) { String _sensorTopic(magnitude_t type) {
if (type == MAGNITUDE_TEMPERATURE) return String(SENSOR_TEMPERATURE_TOPIC);
if (type == MAGNITUDE_HUMIDITY) return String(SENSOR_HUMIDITY_TOPIC);
if (type == MAGNITUDE_PRESSURE) return String(SENSOR_PRESSURE_TOPIC);
if (type == MAGNITUDE_CURRENT) return String(SENSOR_CURRENT_TOPIC);
if (type == MAGNITUDE_VOLTAGE) return String(SENSOR_VOLTAGE_TOPIC);
if (type == MAGNITUDE_POWER_ACTIVE) return String(SENSOR_ACTIVE_POWER_TOPIC);
if (type == MAGNITUDE_POWER_APPARENT) return String(SENSOR_APPARENT_POWER_TOPIC);
if (type == MAGNITUDE_POWER_REACTIVE) return String(SENSOR_REACTIVE_POWER_TOPIC);
if (type == MAGNITUDE_POWER_FACTOR) return String(SENSOR_POWER_FACTOR_TOPIC);
if (type == MAGNITUDE_ENERGY) return String(SENSOR_ENERGY_TOPIC);
if (type == MAGNITUDE_ENERGY_DELTA) return String(SENSOR_ENERGY_DELTA_TOPIC);
if (type == MAGNITUDE_ANALOG) return String(SENSOR_ANALOG_TOPIC);
if (type == MAGNITUDE_DIGITAL) return String(SENSOR_DIGITAL_TOPIC);
if (type == MAGNITUDE_EVENTS) return String(SENSOR_EVENTS_TOPIC);
if (type == MAGNITUDE_PM1dot0) return String(SENSOR_PM1dot0_TOPIC);
if (type == MAGNITUDE_PM2dot5) return String(SENSOR_PM2dot5_TOPIC);
if (type == MAGNITUDE_PM10) return String(SENSOR_PM10_TOPIC);
if (type == MAGNITUDE_CO2) return String(SENSOR_CO2_TOPIC);
return String(SENSOR_UNKNOWN_TOPIC);
if (type == MAGNITUDE_TEMPERATURE) return String(MAGNITUDE_TEMPERATURE_TOPIC);
if (type == MAGNITUDE_HUMIDITY) return String(MAGNITUDE_HUMIDITY_TOPIC);
if (type == MAGNITUDE_PRESSURE) return String(MAGNITUDE_PRESSURE_TOPIC);
if (type == MAGNITUDE_CURRENT) return String(MAGNITUDE_CURRENT_TOPIC);
if (type == MAGNITUDE_VOLTAGE) return String(MAGNITUDE_VOLTAGE_TOPIC);
if (type == MAGNITUDE_POWER_ACTIVE) return String(MAGNITUDE_ACTIVE_POWER_TOPIC);
if (type == MAGNITUDE_POWER_APPARENT) return String(MAGNITUDE_APPARENT_POWER_TOPIC);
if (type == MAGNITUDE_POWER_REACTIVE) return String(MAGNITUDE_REACTIVE_POWER_TOPIC);
if (type == MAGNITUDE_POWER_FACTOR) return String(MAGNITUDE_POWER_FACTOR_TOPIC);
if (type == MAGNITUDE_ENERGY) return String(MAGNITUDE_ENERGY_TOPIC);
if (type == MAGNITUDE_ENERGY_DELTA) return String(MAGNITUDE_ENERGY_DELTA_TOPIC);
if (type == MAGNITUDE_ANALOG) return String(MAGNITUDE_ANALOG_TOPIC);
if (type == MAGNITUDE_DIGITAL) return String(MAGNITUDE_DIGITAL_TOPIC);
if (type == MAGNITUDE_EVENTS) return String(MAGNITUDE_EVENTS_TOPIC);
if (type == MAGNITUDE_PM1dot0) return String(MAGNITUDE_PM1dot0_TOPIC);
if (type == MAGNITUDE_PM2dot5) return String(MAGNITUDE_PM2dot5_TOPIC);
if (type == MAGNITUDE_PM10) return String(MAGNITUDE_PM10_TOPIC);
if (type == MAGNITUDE_CO2) return String(MAGNITUDE_CO2_TOPIC);
return String(MAGNITUDE_UNKNOWN_TOPIC);
} }
unsigned char _sensorDecimals(magnitude_t type) { unsigned char _sensorDecimals(magnitude_t type) {
if (type == MAGNITUDE_TEMPERATURE) return SENSOR_TEMPERATURE_DECIMALS;
if (type == MAGNITUDE_HUMIDITY) return SENSOR_HUMIDITY_DECIMALS;
if (type == MAGNITUDE_PRESSURE) return SENSOR_PRESSURE_DECIMALS;
if (type == MAGNITUDE_CURRENT) return SENSOR_CURRENT_DECIMALS;
if (type == MAGNITUDE_VOLTAGE) return SENSOR_VOLTAGE_DECIMALS;
if (type == MAGNITUDE_POWER_ACTIVE) return SENSOR_POWER_DECIMALS;
if (type == MAGNITUDE_POWER_APPARENT) return SENSOR_POWER_DECIMALS;
if (type == MAGNITUDE_POWER_REACTIVE) return SENSOR_POWER_DECIMALS;
if (type == MAGNITUDE_POWER_FACTOR) return SENSOR_POWER_FACTOR_DECIMALS;
if (type == MAGNITUDE_ENERGY) return SENSOR_ENERGY_DECIMALS;
if (type == MAGNITUDE_ENERGY_DELTA) return SENSOR_ENERGY_DECIMALS;
if (type == MAGNITUDE_ANALOG) return SENSOR_ANALOG_DECIMALS;
if (type == MAGNITUDE_EVENTS) return SENSOR_EVENTS_DECIMALS;
if (type == MAGNITUDE_PM1dot0) return SENSOR_PM1dot0_DECIMALS;
if (type == MAGNITUDE_PM2dot5) return SENSOR_PM2dot5_DECIMALS;
if (type == MAGNITUDE_PM10) return SENSOR_PM10_DECIMALS;
if (type == MAGNITUDE_CO2) return SENSOR_CO2_DECIMALS;
if (type == MAGNITUDE_TEMPERATURE) return MAGNITUDE_TEMPERATURE_DECIMALS;
if (type == MAGNITUDE_HUMIDITY) return MAGNITUDE_HUMIDITY_DECIMALS;
if (type == MAGNITUDE_PRESSURE) return MAGNITUDE_PRESSURE_DECIMALS;
if (type == MAGNITUDE_CURRENT) return MAGNITUDE_CURRENT_DECIMALS;
if (type == MAGNITUDE_VOLTAGE) return MAGNITUDE_VOLTAGE_DECIMALS;
if (type == MAGNITUDE_POWER_ACTIVE) return MAGNITUDE_POWER_DECIMALS;
if (type == MAGNITUDE_POWER_APPARENT) return MAGNITUDE_POWER_DECIMALS;
if (type == MAGNITUDE_POWER_REACTIVE) return MAGNITUDE_POWER_DECIMALS;
if (type == MAGNITUDE_POWER_FACTOR) return MAGNITUDE_POWER_FACTOR_DECIMALS;
if (type == MAGNITUDE_ENERGY) return MAGNITUDE_ENERGY_DECIMALS;
if (type == MAGNITUDE_ENERGY_DELTA) return MAGNITUDE_ENERGY_DECIMALS;
if (type == MAGNITUDE_ANALOG) return MAGNITUDE_ANALOG_DECIMALS;
if (type == MAGNITUDE_EVENTS) return MAGNITUDE_EVENTS_DECIMALS;
if (type == MAGNITUDE_PM1dot0) return MAGNITUDE_PM1dot0_DECIMALS;
if (type == MAGNITUDE_PM2dot5) return MAGNITUDE_PM2dot5_DECIMALS;
if (type == MAGNITUDE_PM10) return MAGNITUDE_PM10_DECIMALS;
if (type == MAGNITUDE_CO2) return MAGNITUDE_CO2_DECIMALS;
return 0; return 0;
} }
@ -149,7 +149,7 @@ void _sensorWebSocketStart(JsonObject& root) {
/* /*
// Sensors manifest // Sensors manifest
JsonObject& manifest = root.createNestedObject("manifest");
JsonArray& manifest = root.createNestedArray("manifest");
#if BMX280_SUPPORT #if BMX280_SUPPORT
BMX280Sensor::manifest(manifest); BMX280Sensor::manifest(manifest);
#endif #endif
@ -158,13 +158,21 @@ void _sensorWebSocketStart(JsonObject& root) {
JsonArray& sensors = root.createNestedArray("sensors"); JsonArray& sensors = root.createNestedArray("sensors");
for (unsigned char i; i<_sensors.size(); i++) { for (unsigned char i; i<_sensors.size(); i++) {
JsonObject& sensor = sensors.createNestedObject(); JsonObject& sensor = sensors.createNestedObject();
sensor["id"] = i;
sensor["index"] = i;
sensor["id"] = _sensors[i]->getID();
_sensors[i]->getConfig(sensor); _sensors[i]->getConfig(sensor);
} }
*/ */
} }
void _sensorWebSocketReceiveData() {
//_emon.setCurrentRatio(getSetting("pwrRatioC", EMON_CURRENT_RATIO).toFloat());
//_power_voltage = getSetting("pwrVoltage", POWER_VOLTAGE).toFloat();
}
void _sensorAPISetup() { void _sensorAPISetup() {
for (unsigned char magnitude_id=0; magnitude_id<_magnitudes.size(); magnitude_id++) { for (unsigned char magnitude_id=0; magnitude_id<_magnitudes.size(); magnitude_id++) {


+ 1
- 0
code/espurna/sensors/AnalogSensor.h View File

@ -18,6 +18,7 @@ class AnalogSensor : public BaseSensor {
AnalogSensor(): BaseSensor() { AnalogSensor(): BaseSensor() {
_count = 1; _count = 1;
_sensor_id = SENSOR_ANALOG_ID;
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------


+ 8
- 6
code/espurna/sensors/BMX280Sensor.h View File

@ -10,8 +10,6 @@
#include "BaseSensor.h" #include "BaseSensor.h"
#include <SparkFunBME280.h> #include <SparkFunBME280.h>
#define BMX280_NAME "BME280 / BMP280"
#define BMX280_KEY "bme280"
#define BMX280_CHIP_BMP280 0x58 #define BMX280_CHIP_BMP280 0x58
#define BMX280_CHIP_BME280 0x60 #define BMX280_CHIP_BME280 0x60
@ -25,6 +23,10 @@ class BMX280Sensor : public BaseSensor {
// Public // Public
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
BMX280Sensor(): BaseSensor() {
_sensor_id = SENSOR_BMX280_ID;
}
void setAddress(unsigned char address) { void setAddress(unsigned char address) {
if (_address == address) return; if (_address == address) return;
_address = address; _address = address;
@ -127,12 +129,12 @@ class BMX280Sensor : public BaseSensor {
} }
// Load the configuration manifest // Load the configuration manifest
static void manifest(JsonObject& sensors) {
static void manifest(JsonArray& sensors) {
char buffer[10]; char buffer[10];
JsonObject& sensor = sensors.createNestedObject(BMX280_KEY);
sensor["name"] = BMX280_NAME;
JsonObject& sensor = sensors.createNestedObject();
sensor["sensor_id"] = SENSOR_BMX280_ID;
JsonArray& fields = sensor.createNestedArray("fields"); JsonArray& fields = sensor.createNestedArray("fields");
{ {
@ -157,7 +159,7 @@ class BMX280Sensor : public BaseSensor {
}; };
void getConfig(JsonObject& root) { void getConfig(JsonObject& root) {
root["key"] = BMX280_KEY;
root["sensor_id"] = _sensor_id;
root["address"] = getAddress(); root["address"] = getAddress();
}; };


+ 17
- 13
code/espurna/sensors/BaseSensor.h View File

@ -90,7 +90,10 @@ class BaseSensor {
virtual void setConfig(JsonObject& root) {}; virtual void setConfig(JsonObject& root) {};
// Load the configuration manifest // Load the configuration manifest
static void manifest(JsonObject& root) {};
static void manifest(JsonArray& root) {};
// Sensor ID
unsigned char getID() { return _sensor_id; };
// Specific for I2C sensors // Specific for I2C sensors
unsigned char lock_i2c(unsigned char address, size_t size, unsigned char * addresses) { unsigned char lock_i2c(unsigned char address, size_t size, unsigned char * addresses) {
@ -120,18 +123,6 @@ class BaseSensor {
} }
// Return sensor status (true for ready)
bool status() { return _error == 0; }
// Return sensor last internal error
int error() { return _error; }
// Number of available slots
unsigned char count() { return _count; }
// Handle interrupt calls
virtual void handleInterrupt(unsigned char gpio) {}
// Interrupt attach callback // Interrupt attach callback
void attached(unsigned char gpio) { void attached(unsigned char gpio) {
#if SENSOR_DEBUG #if SENSOR_DEBUG
@ -146,6 +137,18 @@ class BaseSensor {
#endif #endif
} }
// Return sensor status (true for ready)
bool status() { return _error == 0; }
// Return sensor last internal error
int error() { return _error; }
// Number of available slots
unsigned char count() { return _count; }
// Handle interrupt calls
virtual void handleInterrupt(unsigned char gpio) {}
protected: protected:
// Attach interrupt // Attach interrupt
@ -154,6 +157,7 @@ class BaseSensor {
// Detach interrupt // Detach interrupt
void detach(unsigned char gpio); void detach(unsigned char gpio);
unsigned char _sensor_id = 0x00;
int _error = 0; int _error = 0;
bool _dirty = true; bool _dirty = true;
unsigned char _count = 0; unsigned char _count = 0;


+ 7
- 6
code/espurna/sensors/DHTSensor.h View File

@ -12,10 +12,10 @@
#define DHT_MAX_ERRORS 5 #define DHT_MAX_ERRORS 5
#define DHT_MIN_INTERVAL 2000 #define DHT_MIN_INTERVAL 2000
#define DHT11 11
#define DHT22 22
#define DHT21 21
#define AM2301 21
#define DHT_CHIP_DHT11 11
#define DHT_CHIP_DHT22 22
#define DHT_CHIP_DHT21 21
#define DHT_CHIP_AM2301 21
class DHTSensor : public BaseSensor { class DHTSensor : public BaseSensor {
@ -27,6 +27,7 @@ class DHTSensor : public BaseSensor {
DHTSensor(): BaseSensor() { DHTSensor(): BaseSensor() {
_count = 2; _count = 2;
_sensor_id = SENSOR_DHT_ID;
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -166,7 +167,7 @@ class DHTSensor : public BaseSensor {
} }
// Get humidity from Data[0] and Data[1] // Get humidity from Data[0] and Data[1]
if (_type == DHT11) {
if (_type == DHT_CHIP_DHT11) {
_humidity = dhtData[0]; _humidity = dhtData[0];
} else { } else {
_humidity = dhtData[0] * 256 + dhtData[1]; _humidity = dhtData[0] * 256 + dhtData[1];
@ -174,7 +175,7 @@ class DHTSensor : public BaseSensor {
} }
// Get temp from Data[2] and Data[3] // Get temp from Data[2] and Data[3]
if (_type == DHT11) {
if (_type == DHT_CHIP_DHT11) {
_temperature = dhtData[2]; _temperature = dhtData[2];
} else { } else {
_temperature = (dhtData[2] & 0x7F) * 256 + dhtData[3]; _temperature = (dhtData[2] & 0x7F) * 256 + dhtData[3];


+ 6
- 0
code/espurna/sensors/DallasSensor.h View File

@ -33,6 +33,12 @@ class DallasSensor : public BaseSensor {
// Public // Public
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
DallasSensor(): BaseSensor() {
_sensor_id = SENSOR_DALLAS_ID;
}
// ---------------------------------------------------------------------
void setGPIO(unsigned char gpio) { void setGPIO(unsigned char gpio) {
if (_gpio == gpio) return; if (_gpio == gpio) return;
_gpio = gpio; _gpio = gpio;


+ 1
- 0
code/espurna/sensors/DigitalSensor.h View File

@ -18,6 +18,7 @@ class DigitalSensor : public BaseSensor {
DigitalSensor(): BaseSensor() { DigitalSensor(): BaseSensor() {
_count = 1; _count = 1;
_sensor_id = SENSOR_DIGITAL_ID;
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------


+ 1
- 0
code/espurna/sensors/EmonADC121Sensor.h View File

@ -39,6 +39,7 @@ class EmonADC121Sensor : public EmonAnalogSensor {
EmonADC121Sensor(): EmonAnalogSensor() { EmonADC121Sensor(): EmonAnalogSensor() {
_channels = ADC121_CHANNELS; _channels = ADC121_CHANNELS;
_sensor_id = SENSOR_EMON_ADC121_ID;
init(); init();
} }


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

@ -96,7 +96,6 @@
#define ADS1X15_REG_CONFIG_CQUE_4CONV (0x0002) // Assert ALERT/RDY after four conversions #define ADS1X15_REG_CONFIG_CQUE_4CONV (0x0002) // Assert ALERT/RDY after four conversions
#define ADS1X15_REG_CONFIG_CQUE_NONE (0x0003) // Disable the comparator and put ALERT/RDY in high state (default) #define ADS1X15_REG_CONFIG_CQUE_NONE (0x0003) // Disable the comparator and put ALERT/RDY in high state (default)
class EmonADS1X15Sensor : public EmonSensor { class EmonADS1X15Sensor : public EmonSensor {
public: public:
@ -107,6 +106,7 @@ class EmonADS1X15Sensor : public EmonSensor {
EmonADS1X15Sensor(): EmonSensor() { EmonADS1X15Sensor(): EmonSensor() {
_channels = ADS1X15_CHANNELS; _channels = ADS1X15_CHANNELS;
_sensor_id = SENSOR_EMON_ADS1X15_ID;
init(); init();
} }


+ 1
- 0
code/espurna/sensors/EmonAnalogSensor.h View File

@ -22,6 +22,7 @@ class EmonAnalogSensor : public EmonSensor {
EmonAnalogSensor(): EmonSensor() { EmonAnalogSensor(): EmonSensor() {
_channels = EMON_ANALOG_CHANNELS; _channels = EMON_ANALOG_CHANNELS;
_sensor_id = SENSOR_EMON_ANALOG_ID;
init(); init();
} }


+ 1
- 0
code/espurna/sensors/EventSensor.h View File

@ -18,6 +18,7 @@ class EventSensor : public BaseSensor {
EventSensor(): BaseSensor() { EventSensor(): BaseSensor() {
_count = 1; _count = 1;
_sensor_id = SENSOR_EVENTS_ID;
} }
~EventSensor() { ~EventSensor() {


+ 1
- 0
code/espurna/sensors/MHZ19Sensor.h View File

@ -31,6 +31,7 @@ class MHZ19Sensor : public BaseSensor {
MHZ19Sensor(): BaseSensor() { MHZ19Sensor(): BaseSensor() {
_count = 1; _count = 1;
_sensor_id = SENSOR_MHZ19_ID;
} }
void setRX(unsigned char pin_rx) { void setRX(unsigned char pin_rx) {


+ 1
- 0
code/espurna/sensors/PMSX003Sensor.h View File

@ -22,6 +22,7 @@ class PMSX003Sensor : public BaseSensor {
PMSX003Sensor(): BaseSensor() { PMSX003Sensor(): BaseSensor() {
_count = 3; _count = 3;
_sensor_id = SENSOR_PMSX003_ID;
} }
void setRX(unsigned char pin_rx) { void setRX(unsigned char pin_rx) {


+ 6
- 0
code/espurna/sensors/SI7021Sensor.h View File

@ -31,6 +31,12 @@ class SI7021Sensor : public BaseSensor {
// Public // Public
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
SI7021Sensor(): BaseSensor() {
_sensor_id = SENSOR_SI7021_ID;
}
// ---------------------------------------------------------------------
void setAddress(unsigned char address) { void setAddress(unsigned char address) {
if (_address != address) _dirty = true; if (_address != address) _dirty = true;
_address = address; _address = address;


+ 10
- 0
code/html/custom.js View File

@ -10,6 +10,7 @@ var numReconnect = 0;
var numReload = 0; var numReload = 0;
var useWhite = false; var useWhite = false;
var manifest;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Messages // Messages
@ -484,6 +485,11 @@ function initMagnitudes(data) {
} }
function getManifest(sensor_id) {
for (row of manifest) if (row.sensor_id == sensor_id) return row;
return null;
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Lights // Lights
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -750,6 +756,10 @@ function processData(data) {
return; return;
} }
if (key == "manifest") {
manifest = data[key];
}
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// WiFi // WiFi
// --------------------------------------------------------------------- // ---------------------------------------------------------------------


Loading…
Cancel
Save