Browse Source

Merge branch 'dev' into rules-rpn

rules-rpn
Xose Pérez 5 years ago
parent
commit
d9dff336ad
16 changed files with 425 additions and 11 deletions
  1. +6
    -3
      code/espurna/alexa.ino
  2. +1
    -0
      code/espurna/config/arduino.h
  3. +5
    -0
      code/espurna/config/general.h
  4. +64
    -3
      code/espurna/config/hardware.h
  5. +3
    -0
      code/espurna/config/progmem.h
  6. +46
    -0
      code/espurna/config/sensors.h
  7. +1
    -0
      code/espurna/config/types.h
  8. +3
    -2
      code/espurna/homeassistant.ino
  9. +2
    -1
      code/espurna/light.ino
  10. +20
    -0
      code/espurna/sensor.ino
  11. +1
    -1
      code/espurna/sensors/AnalogSensor.h
  12. +183
    -0
      code/espurna/sensors/LDRSensor.h
  13. +1
    -1
      code/espurna/sensors/NTCSensor.h
  14. +11
    -0
      code/html/index.html
  15. +1
    -0
      code/memanalyzer.py
  16. +77
    -0
      code/platformio.ini

+ 6
- 3
code/espurna/alexa.ino View File

@ -30,6 +30,7 @@ bool _alexaWebSocketOnReceive(const char * key, JsonVariant& value) {
void _alexaWebSocketOnSend(JsonObject& root) {
root["alexaVisible"] = 1;
root["alexaEnabled"] = alexaEnabled();
root["alexaName"] = getSetting("alexaName");
}
void _alexaConfigure() {
@ -84,9 +85,11 @@ void alexaSetup() {
alexa.createServer(!WEB_SUPPORT);
alexa.setPort(80);
// Uses hostname as base name for all devices
// TODO: use custom switch name when available
String hostname = getSetting("hostname");
// Use custom alexa hostname if defined, device hostname otherwise
String hostname = getSetting("alexaName", ALEXA_HOSTNAME);
if (hostname.length() == 0) {
hostname = getSetting("hostname");
}
// Lights
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT


+ 1
- 0
code/espurna/config/arduino.h View File

@ -192,6 +192,7 @@
//#define GEIGER_SUPPORT 1
//#define GUVAS12SD_SUPPORT 1
//#define HLW8012_SUPPORT 1
//#define LDR_SUPPORT 1
//#define MAX6675_SUPPORT 1
//#define MHZ19_SUPPORT 1
//#define MICS2710_SUPPORT 1


+ 5
- 0
code/espurna/config/general.h View File

@ -1244,6 +1244,11 @@
#define ALEXA_ENABLED 1
#endif
#ifndef ALEXA_HOSTNAME
#define ALEXA_HOSTNAME ""
#endif
// -----------------------------------------------------------------------------
// MQTT RF BRIDGE
// -----------------------------------------------------------------------------


+ 64
- 3
code/espurna/config/hardware.h View File

@ -3514,6 +3514,65 @@
#define LED2_MODE LED_MODE_RELAY
#define LED2_PIN_INVERSE 1
// -----------------------------------------------------------------------------
// PSH
// -----------------------------------------------------------------------------
#elif defined(PSH_WIFI_PLUG)
// Info
#define MANUFACTURER "PSH"
#define DEVICE "WIFI_PLUG"
// Relays
#define RELAY1_PIN 2
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 0
#define LED1_PIN_INVERSE 0
#elif defined(PSH_RGBW_CONTROLLER)
// Info
#define MANUFACTURER "PSH"
#define DEVICE "RGBW_CONTROLLER"
#define RELAY_PROVIDER RELAY_PROVIDER_LIGHT
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
#define DUMMY_RELAY_COUNT 1
// LEDs
#define LED1_PIN 13
#define LED1_PIN_INVERSE 1
// Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 4 // GREEN
#define LIGHT_CH3_PIN 12 // BLUE
#define LIGHT_CH4_PIN 14 // WHITE1
#define LIGHT_CH1_INVERSE 0
#define LIGHT_CH2_INVERSE 0
#define LIGHT_CH3_INVERSE 0
#define LIGHT_CH4_INVERSE 0
#elif defined(PSH_WIFI_SENSOR)
// Info
#define MANUFACTURER "PSH"
#define DEVICE "WIFI_SENSOR"
// DHT12 Sensor
#define DHT_SUPPORT 1
#define DHT_PIN 14
#define DHT_TYPE DHT_CHIP_DHT12
// LDR Sensor
#define LDR_SUPPORT 1
#define LDR_TYPE LDR_GL5528
#define LDR_ON_GROUND false
#define LDR_RESISTOR 10000
// -----------------------------------------------------------------------------
// TEST boards (do not use!!)
// -----------------------------------------------------------------------------
@ -3703,10 +3762,12 @@
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
#define MY92XX_MAPPING 4, 3, 5, 0, 1
// A bit of Analog EMON (analog)
#ifndef EMON_ANALOG_SUPPORT
// A bit of analog,
// will not work on real life since they all share GPIO
// but it's OK to test build
#define EMON_ANALOG_SUPPORT 1
#endif
#define NTC_SENSOR 1
#define LDR_SENSOR 1
#define PULSEMETER_SUPPORT 1


+ 3
- 0
code/espurna/config/progmem.h View File

@ -193,6 +193,9 @@ PROGMEM const char espurna_sensors[] =
#if HLW8012_SUPPORT
"HLW8012 "
#endif
#if LDR_SUPPORT
"LDR "
#endif
#if MHZ19_SUPPORT
"MHZ19 "
#endif


+ 46
- 0
code/espurna/config/sensors.h View File

@ -491,6 +491,47 @@
// Use FALLING for BL0937 / HJL0
#endif
//------------------------------------------------------------------------------
// LDR sensor
// Enable support by passing LDR_SUPPORT=1 build flag
//------------------------------------------------------------------------------
#ifndef SENSOR_LUX_CORRECTION
#define SENSOR_LUX_CORRECTION 0.0 // Offset correction
#endif
#ifndef LDR_SUPPORT
#define LDR_SUPPORT 0
#endif
#ifndef LDR_SAMPLES
#define LDR_SAMPLES 10 // Number of samples
#endif
#ifndef LDR_DELAY
#define LDR_DELAY 0 // Delay between samples in micros
#endif
#ifndef LDR_TYPE
#define LDR_TYPE LDR_GL5528
#endif
#ifndef LDR_ON_GROUND
#define LDR_ON_GROUND true
#endif
#ifndef LDR_RESISTOR
#define LDR_RESISTOR 10000 // Resistance
#endif
#ifndef LDR_MULTIPLICATION
#define LDR_MULTIPLICATION 32017200
#endif
#ifndef LDR_POWER
#define LDR_POWER 1.5832
#endif
//------------------------------------------------------------------------------
// MHZ19 CO2 sensor
// Enable support by passing MHZ19_SUPPORT=1 build flag
@ -916,6 +957,7 @@
GEIGER_SUPPORT || \
GUVAS12SD_SUPPORT || \
HLW8012_SUPPORT || \
LDR_SUPPORT || \
MICS2710_SUPPORT || \
MICS5525_SUPPORT || \
MHZ19_SUPPORT || \
@ -1047,6 +1089,10 @@
#include "../sensors/HLW8012Sensor.h"
#endif
#if LDR_SUPPORT
#include "../sensors/LDRSensor.h"
#endif
#if MAX6675_SUPPORT
#include "../sensors/MAX6675Sensor.h"
#endif


+ 1
- 0
code/espurna/config/types.h View File

@ -302,6 +302,7 @@
#define SENSOR_EZOPH_ID 33
#define SENSOR_BMP180_ID 34
#define SENSOR_MAX6675_ID 35
#define SENSOR_LDR_ID 36
//--------------------------------------------------------------------------------
// Magnitudes


+ 3
- 2
code/espurna/homeassistant.ino View File

@ -98,9 +98,10 @@ void _haSendSwitch(unsigned char i, JsonObject& config) {
if (i == 0) {
config["brightness_state_topic"] = mqttTopic(MQTT_TOPIC_BRIGHTNESS, false);
config["brightness_command_topic"] = mqttTopic(MQTT_TOPIC_BRIGHTNESS, true);
if (lightHasColor()) {
config["brightness_state_topic"] = mqttTopic(MQTT_TOPIC_BRIGHTNESS, false);
config["brightness_command_topic"] = mqttTopic(MQTT_TOPIC_BRIGHTNESS, true);
config["rgb_state_topic"] = mqttTopic(MQTT_TOPIC_COLOR_RGB, false);
config["rgb_command_topic"] = mqttTopic(MQTT_TOPIC_COLOR_RGB, true);
config["color_temp_command_topic"] = mqttTopic(MQTT_TOPIC_MIRED, true);


+ 2
- 1
code/espurna/light.ino View File

@ -554,8 +554,9 @@ void _lightMQTTCallback(unsigned int type, const char * topic, const char * payl
if (type == MQTT_CONNECT_EVENT) {
mqttSubscribe(MQTT_TOPIC_BRIGHTNESS);
if (_light_has_color) {
mqttSubscribe(MQTT_TOPIC_BRIGHTNESS);
mqttSubscribe(MQTT_TOPIC_MIRED);
mqttSubscribe(MQTT_TOPIC_KELVIN);
mqttSubscribe(MQTT_TOPIC_COLOR_RGB);


+ 20
- 0
code/espurna/sensor.ino View File

@ -44,6 +44,7 @@ unsigned char _sensor_energy_units = SENSOR_ENERGY_UNITS;
unsigned char _sensor_temperature_units = SENSOR_TEMPERATURE_UNITS;
double _sensor_temperature_correction = SENSOR_TEMPERATURE_CORRECTION;
double _sensor_humidity_correction = SENSOR_HUMIDITY_CORRECTION;
double _sensor_lux_correction = SENSOR_LUX_CORRECTION;
#if PZEM004T_SUPPORT
PZEM004TSensor *pzem004t_sensor;
@ -88,6 +89,10 @@ double _magnitudeProcess(unsigned char type, unsigned char decimals, double valu
value = constrain(value + _sensor_humidity_correction, 0, 100);
}
if (type == MAGNITUDE_LUX) {
value = value + _sensor_lux_correction;
}
if (type == MAGNITUDE_ENERGY ||
type == MAGNITUDE_ENERGY_DELTA) {
if (_sensor_energy_units == ENERGY_KWH) value = value / 3600000;
@ -137,6 +142,7 @@ bool _sensorWebSocketOnReceive(const char * key, JsonVariant& value) {
if (strncmp(key, "tmp", 3) == 0) return true;
if (strncmp(key, "hum", 3) == 0) return true;
if (strncmp(key, "ene", 3) == 0) return true;
if (strncmp(key, "lux", 3) == 0) return true;
return false;
}
@ -677,6 +683,19 @@ void _sensorLoad() {
}
#endif
#if LDR_SUPPORT
{
LDRSensor * sensor = new LDRSensor();
sensor->setSamples(LDR_SAMPLES);
sensor->setDelay(LDR_DELAY);
sensor->setType(LDR_TYPE);
sensor->setPhotocellPositionOnGround(LDR_ON_GROUND);
sensor->setResistor(LDR_RESISTOR);
sensor->setPhotocellParameters(LDR_MULTIPLICATION, LDR_POWER);
_sensors.push_back(sensor);
}
#endif
#if MHZ19_SUPPORT
{
MHZ19Sensor * sensor = new MHZ19Sensor();
@ -1048,6 +1067,7 @@ void _sensorConfigure() {
_sensor_temperature_correction = getSetting("tmpCorrection", SENSOR_TEMPERATURE_CORRECTION).toFloat();
_sensor_humidity_correction = getSetting("humCorrection", SENSOR_HUMIDITY_CORRECTION).toFloat();
_sensor_energy_reset_ts = getSetting("snsResetTS", "");
_sensor_lux_correction = getSetting("luxCorrection", SENSOR_LUX_CORRECTION).toFloat();
// Specific sensor settings
for (unsigned char i=0; i<_sensors.size(); i++) {


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

@ -3,7 +3,7 @@
// Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>
// -----------------------------------------------------------------------------
#if SENSOR_SUPPORT && (ANALOG_SUPPORT || NTC_SUPPORT)
#if SENSOR_SUPPORT && (ANALOG_SUPPORT || NTC_SUPPORT || LDR_SENSOR)
#pragma once


+ 183
- 0
code/espurna/sensors/LDRSensor.h View File

@ -0,0 +1,183 @@
// -----------------------------------------------------------------------------
// LDR Sensor (maps to a LDRSensor)
// Copyright (C) 2019 by Altan Altay
// -----------------------------------------------------------------------------
#if SENSOR_SUPPORT && LDR_SUPPORT
#pragma once
// Set ADC to TOUT pin
#undef ADC_MODE_VALUE
#define ADC_MODE_VALUE ADC_TOUT
#include "Arduino.h"
#include "AnalogSensor.h"
#define LDR_GL5516 1
#define LDR_GL5528 2
#define LDR_GL5537_1 3
#define LDR_GL5537_2 4
#define LDR_GL5539 5
#define LDR_GL5549 6
#define LDR_OTHER 99
extern "C" {
#include "../libs/fs_math.h"
}
class LDRSensor : public AnalogSensor {
public:
// ---------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------
LDRSensor(): AnalogSensor() {
_count = 1;
_sensor_id = SENSOR_LDR_ID;
}
void setType(unsigned char type) {
_type = type;
switch (_type) {
case LDR_GL5516:
_mult_value = 29634400;
_pow_value = 1.6689;
break;
case LDR_GL5537_1:
_mult_value = 32435800;
_pow_value = 1.4899;
break;
case LDR_GL5537_2:
_mult_value = 2801820;
_pow_value = 1.1772;
break;
case LDR_GL5539:
_mult_value = 208510000;
_pow_value = 1.4850;
break;
case LDR_GL5549:
_mult_value = 44682100;
_pow_value = 1.2750;
break;
case LDR_OTHER:
_mult_value = LDR_MULTIPLICATION;
_pow_value = LDR_POWER;
break;
case LDR_GL5528:
default:
_mult_value = 32017200;
_pow_value = 1.5832;
break;
}
}
/*!
* \brief setPhotocellPositionOnGround Configure the photocell as connected to 3.3V or GND
*
* \param on_ground (bool) True if the photocell is connected to GND, else false
*
* True: EXTERNAL ADC
* ^ ^
* _____ | ___/___
* 3.3V |---|_____|--*--|__/____|--| GND
* Other /
* Resistor Photocell
*
* False:
* EXTERNAL ADC
* ^ ^
* _____ | ___/___
* GND |---|_____|--*--|__/____|--| 3.3V
* Other /
* Resistor Photocell
*/
void setPhotocellPositionOnGround(bool on_ground) {
_photocell_on_ground = on_ground;
}
void setResistor(unsigned long resistor) {
_resistor = resistor;
}
/*!
* \brief updatePhotocellParameters Redefine the photocell parameters
*
* \parameter mult_value (float) Multiplication parameter in "I[lux]=mult_value/(R[Ω]^pow_value)" expression
* \parameter pow_value (float) Power parameter in "I[lux]=mult_value/(R[Ω]^pow_value)" expression
*/
void setPhotocellParameters(float mult_value, float pow_value) {
if (_type == LDR_OTHER) {
_mult_value = mult_value;
_pow_value = pow_value;
}
}
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Sensor API
// ---------------------------------------------------------------------
// Descriptive name of the sensor
String description() {
return String("LDR @ TOUT");
}
// Descriptive name of the slot # index
String slot(unsigned char index) {
return description();
}
// Address of the sensor (it could be the GPIO or I2C address)
String address(unsigned char index) {
return String("0");
}
// Type for slot # index
unsigned char type(unsigned char index) {
if (index == 0) return MAGNITUDE_LUX;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
double current_lux = 0;
if (index == 0) {
unsigned long photocell_resistor = 0;
// sampled reading
double read = _read();
float ratio = ((float)1024/(float)read) - 1;
if (_photocell_on_ground) {
photocell_resistor = _resistor / ratio;
} else {
photocell_resistor = _resistor * ratio;
}
current_lux = _mult_value / (float)pow(photocell_resistor, _pow_value);
}
return current_lux;
}
protected:
unsigned char _type = LDR_GL5528;
bool _photocell_on_ground = false;
unsigned long _resistor = 10000;
float _mult_value = 0;
float _pow_value = 0;
};
#endif // SENSOR_SUPPORT && LDR_SUPPORT

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

@ -67,7 +67,7 @@ class NTCSensor : public AnalogSensor {
// Descriptive name of the slot # index
String slot(unsigned char index) {
return description();
};
}
// Address of the sensor (it could be the GPIO or I2C address)
String address(unsigned char index) {


+ 11
- 0
code/html/index.html View File

@ -392,6 +392,17 @@
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="alexaEnabled" /></div>
</div>
<div class="pure-g module module-alexa">
<label class="pure-u-1 pure-u-lg-1-4">Alexa device name</label>
<input name="alexaName" class="pure-u-1 pure-u-lg-1-4" maxlength="31" type="text" action="reboot" tabindex="7" />
<div class="pure-u-0 pure-u-lg-1-2"></div>
<div class="pure-u-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint">
This name will be used in Alexa integration.<br />
</div>
</div>
</fieldset>
</div>


+ 1
- 0
code/memanalyzer.py View File

@ -279,6 +279,7 @@ if __name__ == '__main__':
total['data'],
total['rodata'],
total['bss'],
total['free'],
total['irom0_text'],
total['size'],
))


+ 77
- 0
code/platformio.ini View File

@ -3319,3 +3319,80 @@ upload_flags = ${common.upload_flags}
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}
[env:psh-plug]
platform = ${common.platform}
framework = ${common.framework}
board = ${common.board_1m}
board_build.flash_mode = ${common.flash_mode}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m0m} -DPSH_PLUG
upload_speed = ${common.upload_speed}
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}
[env:psh-plug-ota]
platform = ${common.platform}
framework = ${common.framework}
board = ${common.board_1m}
board_build.flash_mode = ${common.flash_mode}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m0m} -DPSH_PLUG
upload_speed = ${common.upload_speed}
upload_port = ${common.upload_port}
upload_flags = ${common.upload_flags}
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}
[env:psh-led-controller]
platform = ${common.platform}
framework = ${common.framework}
board = ${common.board_4m}
board_build.flash_mode = ${common.flash_mode}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_4m1m} -DPSH_LED_CONTROLLER
upload_speed = ${common.upload_speed}
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}
[env:psh-led-controller-ota]
platform = ${common.platform}
framework = ${common.framework}
board = ${common.board_4m}
board_build.flash_mode = ${common.flash_mode}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_4m1m} -DPSH_LED_CONTROLLER
upload_speed = ${common.upload_speed}
upload_port = ${common.upload_port}
upload_flags = ${common.upload_flags}
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}
[env:psh-wifi-sensor]
platform = ${common.platform}
framework = ${common.framework}
board = ${common.board_4m}
board_build.flash_mode = ${common.flash_mode}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_4m1m} -DPSH_WIFI_SENSOR
upload_speed = ${common.upload_speed}
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}
[env:psh-wifi-sensor-ota]
platform = ${common.platform}
framework = ${common.framework}
board = ${common.board_4m}
board_build.flash_mode = ${common.flash_mode}
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_4m1m} -DPSH_WIFI_SENSOR
upload_speed = ${common.upload_speed}
upload_port = ${common.upload_port}
upload_flags = ${common.upload_flags}
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}

Loading…
Cancel
Save