Browse Source

Merge pull request #2 from xoseperez/dev

Merging back from Xoseperez
ota
ColinShorts 6 years ago
committed by GitHub
parent
commit
e34559728a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 3309 additions and 3111 deletions
  1. +5
    -0
      README.md
  2. +1
    -0
      code/espurna/config/arduino.h
  3. +12
    -6
      code/espurna/config/general.h
  4. +36
    -0
      code/espurna/config/hardware.h
  5. BIN
      code/espurna/data/index.html.gz
  6. +1
    -2
      code/espurna/homeassistant.ino
  7. +86
    -34
      code/espurna/light.ino
  8. +16
    -0
      code/espurna/migrate.ino
  9. +3
    -2
      code/espurna/relay.ino
  10. +8
    -11
      code/espurna/sensors/PZEM004TSensor.h
  11. +3059
    -3049
      code/espurna/static/index.html.gz.h
  12. +2
    -0
      code/espurna/wifi.ino
  13. +31
    -0
      code/html/custom.js
  14. +24
    -6
      code/html/index.html
  15. +25
    -1
      code/platformio.ini
  16. BIN
      images/devices/tonbux-mosquito-killer.jpg

+ 5
- 0
README.md View File

@ -243,10 +243,15 @@ Here is the list of supported hardware. For more information please refer to the
|**Heltec Touch Relay**|**Generic Relay v4.0**|**Generic RGBLed v1.0**| |**Heltec Touch Relay**|**Generic Relay v4.0**|**Generic RGBLed v1.0**|
|![Generic DHT11 v1.0](images/devices/generic-dht11-10.jpg)|![Generic DS18B20 v1.0](images/devices/generic-ds18b20-10.jpg)|| |![Generic DHT11 v1.0](images/devices/generic-dht11-10.jpg)|![Generic DS18B20 v1.0](images/devices/generic-ds18b20-10.jpg)||
|**Generic DHT11 v1.0**|**Generic DS18B20 v1.0**|| |**Generic DHT11 v1.0**|**Generic DS18B20 v1.0**||
|![Tonbux Mosquito Killer](images/devices/tonbux-mosquito-killer.jpg)|||
|**Tonbux Mosquito Killer**|||
**Other supported boards:** **Other supported boards:**
IteadStudio Sonoff S31, IteadStudio Sonoff POW R2, Zhilde ZLD-EU55-W, Luani HVIO IteadStudio Sonoff S31, IteadStudio Sonoff POW R2, Zhilde ZLD-EU55-W, Luani HVIO
**Other supported boards (beta):**
KMC 4 Outlet, Gosund WS1, Smart Dual Plug, MakerFocus Intelligent Module LM33 for Lamps
## License ## License
Copyright (C) 2016-2018 by Xose Pérez (@xoseperez) Copyright (C) 2016-2018 by Xose Pérez (@xoseperez)


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

@ -81,6 +81,7 @@
//#define ZHILDE_EU44_W //#define ZHILDE_EU44_W
//#define LUANI_HVIO //#define LUANI_HVIO
//#define ALLNET_4DUINO_IOT_WLAN_RELAIS //#define ALLNET_4DUINO_IOT_WLAN_RELAIS
//#define TONBUX_MOSQUITO_KILLER
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Features (values below are non-default values) // Features (values below are non-default values)


+ 12
- 6
code/espurna/config/general.h View File

@ -772,11 +772,8 @@
#define LIGHT_MAX_BRIGHTNESS 255 // Maximun brightness value #define LIGHT_MAX_BRIGHTNESS 255 // Maximun brightness value
#endif #endif
//#define LIGHT_MIN_MIREDS 153 // NOT USED (yet)! // Default to the Philips Hue value that HA has always assumed
//#define LIGHT_MAX_MIREDS 500 // NOT USED (yet)! // https://developers.meethue.com/documentation/core-concepts
#ifndef LIGHT_DEFAULT_MIREDS
#define LIGHT_DEFAULT_MIREDS 153 // Default value used by MQTT. This value is __NEVRER__ applied!
#endif
#define LIGHT_MIN_MIREDS 153 // Default to the Philips Hue value that HA also use.
#define LIGHT_MAX_MIREDS 500 // https://developers.meethue.com/documentation/core-concepts
#ifndef LIGHT_STEP #ifndef LIGHT_STEP
#define LIGHT_STEP 32 // Step size #define LIGHT_STEP 32 // Step size
@ -787,9 +784,18 @@
#endif #endif
#ifndef LIGHT_USE_WHITE #ifndef LIGHT_USE_WHITE
#define LIGHT_USE_WHITE 0 // Use white channel whenever RGB have the same value
#define LIGHT_USE_WHITE 0 // Use the 4th channel as (Warm-)White LEDs
#endif
#ifndef LIGHT_USE_CCT
#define LIGHT_USE_CCT 0 // Use the 5th channel as Coldwhite LEDs, LIGHT_USE_WHITE must be 1.
#endif #endif
// Used when LIGHT_USE_WHITE AND LIGHT_USE_CCT is 1 - (1000000/Kelvin = MiReds)
// Warning! Don't change this yet, NOT FULLY IMPLEMENTED!
#define LIGHT_COLDWHITE_MIRED 153 // Coldwhite Strip, Value must be __BELOW__ W2!! (Default: 6535 Kelvin/153 MiRed)
#define LIGHT_WARMWHITE_MIRED 500 // Warmwhite Strip, Value must be __ABOVE__ W1!! (Default: 2000 Kelvin/500 MiRed)
#ifndef LIGHT_USE_GAMMA #ifndef LIGHT_USE_GAMMA
#define LIGHT_USE_GAMMA 0 // Use gamma correction for color channels #define LIGHT_USE_GAMMA 0 // Use gamma correction for color channels
#endif #endif


+ 36
- 0
code/espurna/config/hardware.h View File

@ -1923,6 +1923,7 @@
#define DHT_SUPPORT 1 #define DHT_SUPPORT 1
#endif #endif
#define DHT_PIN 2 #define DHT_PIN 2
#define DHT_TYPE DHT_CHIP_DHT11
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// ESP-01S DS18B20 v1.0 // ESP-01S DS18B20 v1.0
@ -2072,6 +2073,41 @@
#define LED1_PIN 15 #define LED1_PIN 15
#define LED1_PIN_INVERSE 0 #define LED1_PIN_INVERSE 0
// -----------------------------------------------------------------------------
// Tonbux 50-100M Smart Mosquito Killer USB
// https://www.aliexpress.com/item/Original-Tonbux-50-100M-Smart-Mosquito-Killer-USB-Plug-No-Noise-Repellent-App-Smart-Module/32859330820.html
// -----------------------------------------------------------------------------
#elif defined(TONBUX_MOSQUITO_KILLER)
// Info
#define MANUFACTURER "TONBUX"
#define DEVICE "MOSQUITO_KILLER"
// Buttons
#define BUTTON1_PIN 2
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON1_RELAY 1
// Relays
#define RELAY1_PIN 5 // not a relay, fan
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 15 // blue led
#define LED1_PIN_INVERSE 1
#define LED1_MODE LED_MODE_WIFI
#define LED2_PIN 14 // red led
#define LED2_PIN_INVERSE 1
#define LED2_MODE LED_MODE_RELAY
#define LED3_PIN 12 // UV leds (1-2-3-4-5-6-7-8)
#define LED3_PIN_INVERSE 0
#define LED3_RELAY 1
#define LED4_PIN 16 // UV leds (9-10-11)
#define LED4_PIN_INVERSE 0
#define LED4_RELAY 1
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// TEST boards (do not use!!) // TEST boards (do not use!!)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


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


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

@ -24,9 +24,8 @@ void _haSendMagnitude(unsigned char i, JsonObject& config) {
unsigned char type = magnitudeType(i); unsigned char type = magnitudeType(i);
config["name"] = getSetting("hostname") + String(" ") + magnitudeTopic(type); config["name"] = getSetting("hostname") + String(" ") + magnitudeTopic(type);
config.set("platform", "mqtt"); config.set("platform", "mqtt");
config.set("device_class", "sensor");
config["state_topic"] = mqttTopic(magnitudeTopicIndex(i).c_str(), false); config["state_topic"] = mqttTopic(magnitudeTopicIndex(i).c_str(), false);
config["unit_of_measurement"] = String("\"") + magnitudeUnits(type) + String("\"");
config["unit_of_measurement"] = magnitudeUnits(type);
} }


+ 86
- 34
code/espurna/light.ino View File

@ -40,10 +40,11 @@ bool _light_use_transitions = false;
unsigned int _light_transition_time = LIGHT_TRANSITION_TIME; unsigned int _light_transition_time = LIGHT_TRANSITION_TIME;
bool _light_has_color = false; bool _light_has_color = false;
bool _light_use_white = false; bool _light_use_white = false;
bool _light_use_cct = false;
bool _light_use_gamma = false; bool _light_use_gamma = false;
unsigned long _light_steps_left = 1; unsigned long _light_steps_left = 1;
unsigned char _light_brightness = LIGHT_MAX_BRIGHTNESS; unsigned char _light_brightness = LIGHT_MAX_BRIGHTNESS;
unsigned int _light_mireds = LIGHT_DEFAULT_MIREDS;
unsigned int _light_mireds = round((LIGHT_COLDWHITE_MIRED+LIGHT_WARMWHITE_MIRED)/2);
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
#include <my92xx.h> #include <my92xx.h>
@ -77,45 +78,70 @@ const unsigned char _light_gamma_table[] = {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void _setRGBInputValue(unsigned char red, unsigned char green, unsigned char blue) { void _setRGBInputValue(unsigned char red, unsigned char green, unsigned char blue) {
_light_channel[0].inputValue = red;
_light_channel[1].inputValue = green;
_light_channel[2].inputValue = blue;
_light_channel[0].inputValue = constrain(red, 0, LIGHT_MAX_VALUE);
_light_channel[1].inputValue = constrain(green, 0, LIGHT_MAX_VALUE);;
_light_channel[2].inputValue = constrain(blue, 0, LIGHT_MAX_VALUE);;
} }
void _generateBrightness() { void _generateBrightness() {
double brightness = (double) _light_brightness / LIGHT_MAX_BRIGHTNESS; double brightness = (double) _light_brightness / LIGHT_MAX_BRIGHTNESS;
// Convert RGB to RGBW
// Convert RGB to RGBW(W)
if (_light_has_color && _light_use_white) { if (_light_has_color && _light_use_white) {
// Substract the common part from RGB channels and add it to white channel. So [250,150,50] -> [200,100,0,50
// Substract the common part from RGB channels and add it to white channel. So [250,150,50] -> [200,100,0,50]
unsigned char white = std::min(_light_channel[0].inputValue, std::min(_light_channel[1].inputValue, _light_channel[2].inputValue)); unsigned char white = std::min(_light_channel[0].inputValue, std::min(_light_channel[1].inputValue, _light_channel[2].inputValue));
for (unsigned int i=0; i < 3; i++) { for (unsigned int i=0; i < 3; i++) {
_light_channel[i].value = _light_channel[i].inputValue - white; _light_channel[i].value = _light_channel[i].inputValue - white;
} }
_light_channel[3].value = white;
_light_channel[3].inputValue = 0;
// Split the White Value across 2 White LED Strips.
if (_light_use_cct) {
// This change the range from 153-500 to 0-347 so we get a value between 0 and 1 in the end.
double miredFactor = ((double) _light_mireds - (double) LIGHT_COLDWHITE_MIRED)/((double) LIGHT_WARMWHITE_MIRED - (double) LIGHT_COLDWHITE_MIRED);
// set cold white
_light_channel[3].inputValue = 0;
_light_channel[3].value = round(((double) 1.0 - miredFactor) * white);
// set warm white
_light_channel[4].inputValue = 0;
_light_channel[4].value = round(miredFactor * white);
} else {
_light_channel[3].inputValue = 0;
_light_channel[3].value = white;
}
// Scale up to equal input values. So [250,150,50] -> [200,100,0,50] -> [250, 125, 0, 63] // Scale up to equal input values. So [250,150,50] -> [200,100,0,50] -> [250, 125, 0, 63]
unsigned char max_in = std::max(_light_channel[0].inputValue, std::max(_light_channel[1].inputValue, _light_channel[2].inputValue)); unsigned char max_in = std::max(_light_channel[0].inputValue, std::max(_light_channel[1].inputValue, _light_channel[2].inputValue));
unsigned char max_out = std::max(std::max(_light_channel[0].value, _light_channel[1].value), std::max(_light_channel[2].value, _light_channel[3].value)); unsigned char max_out = std::max(std::max(_light_channel[0].value, _light_channel[1].value), std::max(_light_channel[2].value, _light_channel[3].value));
unsigned char channelSize = _light_use_cct ? 5 : 4;
if (_light_use_cct) {
max_out = std::max(max_out, _light_channel[4].value);
}
double factor = (max_out > 0) ? (double) (max_in / max_out) : 0; double factor = (max_out > 0) ? (double) (max_in / max_out) : 0;
for (unsigned int i=0; i < 4; i++) {
for (unsigned char i=0; i < channelSize; i++) {
_light_channel[i].value = round((double) _light_channel[i].value * factor * brightness); _light_channel[i].value = round((double) _light_channel[i].value * factor * brightness);
} }
// Scale white channel to match brightness // Scale white channel to match brightness
_light_channel[3].value = constrain(_light_channel[3].value * LIGHT_WHITE_FACTOR, 0, 255);
for (unsigned char i=3; i < channelSize; i++) {
_light_channel[i].value = constrain(_light_channel[i].value * LIGHT_WHITE_FACTOR, 0, LIGHT_MAX_BRIGHTNESS);
}
// For the rest of channels, don't apply brightness, it is already in the inputValue:
for (unsigned char i=4; i < _light_channel.size(); i++) {
// For the rest of channels, don't apply brightness, it is already in the inputValue
// i should be 4 when RGBW and 5 when RGBWW
for (unsigned char i=channelSize; i < _light_channel.size(); i++) {
_light_channel[i].value = _light_channel[i].inputValue; _light_channel[i].value = _light_channel[i].inputValue;
} }
} else { } else {
// Don't apply brightness, it is already in the inputValue:
// Don't apply brightness, it is already in the target:
for (unsigned char i=0; i < _light_channel.size(); i++) { for (unsigned char i=0; i < _light_channel.size(); i++) {
if (_light_has_color & (i<3)) { if (_light_has_color & (i<3)) {
_light_channel[i].value = _light_channel[i].inputValue * brightness; _light_channel[i].value = _light_channel[i].inputValue * brightness;
@ -155,16 +181,10 @@ void _fromRGB(const char * rgb) {
} }
break; break;
case 'M': // Mired Value case 'M': // Mired Value
if (_light_has_color) {
unsigned long mireds = atol(p + 1);
_fromMireds(mireds);
}
_fromMireds(atol(p + 1));
break; break;
case 'K': // Kelvin Value case 'K': // Kelvin Value
if (_light_has_color) {
unsigned long kelvin = atol(p + 1);
_fromKelvin(kelvin);
}
_fromKelvin(atol(p + 1));
break; break;
default: // assume decimal values separated by commas default: // assume decimal values separated by commas
char * tok; char * tok;
@ -257,13 +277,18 @@ void _fromHSV(const char * hsv) {
// https://github.com/stelgenhof/AiLight // https://github.com/stelgenhof/AiLight
void _fromKelvin(unsigned long kelvin, bool setMireds) { void _fromKelvin(unsigned long kelvin, bool setMireds) {
// Check we have RGB channels
if (!_light_has_color) return; if (!_light_has_color) return;
if (setMireds) { if (setMireds) {
_light_mireds = round(1000000UL / kelvin);
_light_mireds = constrain(round(1000000UL / kelvin), LIGHT_MIN_MIREDS, LIGHT_MAX_MIREDS);
} }
if (_light_use_cct) {
_setRGBInputValue(LIGHT_MAX_VALUE, LIGHT_MAX_VALUE, LIGHT_MAX_VALUE);
return;
}
// Calculate colors // Calculate colors
unsigned int red = (kelvin <= 66) unsigned int red = (kelvin <= 66)
? LIGHT_MAX_VALUE ? LIGHT_MAX_VALUE
@ -277,11 +302,7 @@ void _fromKelvin(unsigned long kelvin, bool setMireds) {
? 0 ? 0
: 138.5177312231 * log(kelvin - 10) - 305.0447927307); : 138.5177312231 * log(kelvin - 10) - 305.0447927307);
_setRGBInputValue(
constrain(red, 0, LIGHT_MAX_VALUE),
constrain(green, 0, LIGHT_MAX_VALUE),
constrain(blue, 0, LIGHT_MAX_VALUE)
);
_setRGBInputValue(red, green, blue);
} }
void _fromKelvin(unsigned long kelvin) { void _fromKelvin(unsigned long kelvin) {
@ -290,8 +311,15 @@ void _fromKelvin(unsigned long kelvin) {
// Color temperature is measured in mireds (kelvin = 1e6/mired) // Color temperature is measured in mireds (kelvin = 1e6/mired)
void _fromMireds(unsigned long mireds) { void _fromMireds(unsigned long mireds) {
if (mireds == 0) mireds = 1;
_light_mireds = mireds;
if (!_light_has_color) return;
_light_mireds = mireds = constrain(mireds, LIGHT_MIN_MIREDS, LIGHT_MAX_MIREDS);
if (_light_use_cct) {
_setRGBInputValue(LIGHT_MAX_VALUE, LIGHT_MAX_VALUE, LIGHT_MAX_VALUE);
return;
}
unsigned long kelvin = constrain(1000000UL / mireds, 1000, 40000) / 100; unsigned long kelvin = constrain(1000000UL / mireds, 1000, 40000) / 100;
_fromKelvin(kelvin, false); _fromKelvin(kelvin, false);
} }
@ -313,15 +341,15 @@ void _toRGB(char * rgb, size_t len) {
} }
void _toHSV(char * hsv, size_t len) { void _toHSV(char * hsv, size_t len) {
double min, max, h, s, v;
double h, s, v;
double brightness = (double) _light_brightness / LIGHT_MAX_BRIGHTNESS; double brightness = (double) _light_brightness / LIGHT_MAX_BRIGHTNESS;
double r = (double) (_light_channel[0].inputValue * brightness) / 255.0; double r = (double) (_light_channel[0].inputValue * brightness) / 255.0;
double g = (double) (_light_channel[1].inputValue * brightness) / 255.0; double g = (double) (_light_channel[1].inputValue * brightness) / 255.0;
double b = (double) (_light_channel[2].inputValue * brightness) / 255.0; double b = (double) (_light_channel[2].inputValue * brightness) / 255.0;
min = std::min(r, std::min(g, b));
max = std::max(r, std::max(g, b));
double min = std::min(r, std::min(g, b));
double max = std::max(r, std::max(g, b));
v = 100.0 * max; v = 100.0 * max;
if (v == 0) { if (v == 0) {
@ -389,6 +417,7 @@ unsigned int _toPWM(unsigned char id) {
} }
void _shadow() { void _shadow() {
// Update transition ticker // Update transition ticker
_light_steps_left--; _light_steps_left--;
if (_light_steps_left == 0) _light_transition_ticker.detach(); if (_light_steps_left == 0) _light_transition_ticker.detach();
@ -396,15 +425,20 @@ void _shadow() {
// Transitions // Transitions
unsigned char target; unsigned char target;
for (unsigned int i=0; i < _light_channel.size(); i++) { for (unsigned int i=0; i < _light_channel.size(); i++) {
target = _light_state ? _light_channel[i].value : 0;
target = _light_state && _light_channel[i].state ? _light_channel[i].value : 0;
if (_light_steps_left == 0) { if (_light_steps_left == 0) {
_light_channel[i].current = target; _light_channel[i].current = target;
} else { } else {
double difference = (double) (target - _light_channel[i].current) / (_light_steps_left + 1); double difference = (double) (target - _light_channel[i].current) / (_light_steps_left + 1);
_light_channel[i].current = _light_channel[i].current + difference; _light_channel[i].current = _light_channel[i].current + difference;
} }
_light_channel[i].shadow = _light_channel[i].current; _light_channel[i].shadow = _light_channel[i].current;
} }
} }
void _lightProviderUpdate() { void _lightProviderUpdate() {
@ -441,6 +475,7 @@ void _lightColorSave() {
setSetting("ch", i, _light_channel[i].inputValue); setSetting("ch", i, _light_channel[i].inputValue);
} }
setSetting("brightness", _light_brightness); setSetting("brightness", _light_brightness);
setSetting("mireds", _light_mireds);
saveSettings(); saveSettings();
} }
@ -449,6 +484,7 @@ void _lightColorRestore() {
_light_channel[i].inputValue = getSetting("ch", i, i==0 ? 255 : 0).toInt(); _light_channel[i].inputValue = getSetting("ch", i, i==0 ? 255 : 0).toInt();
} }
_light_brightness = getSetting("brightness", LIGHT_MAX_BRIGHTNESS).toInt(); _light_brightness = getSetting("brightness", LIGHT_MAX_BRIGHTNESS).toInt();
_light_mireds = getSetting("mireds", _light_mireds).toInt();
lightUpdate(false, false); lightUpdate(false, false);
} }
@ -751,6 +787,10 @@ void _lightWebSocketOnSend(JsonObject& root) {
bool useRGB = getSetting("useRGB", LIGHT_USE_RGB).toInt() == 1; bool useRGB = getSetting("useRGB", LIGHT_USE_RGB).toInt() == 1;
root["useRGB"] = useRGB; root["useRGB"] = useRGB;
if (_light_has_color) { if (_light_has_color) {
if (_light_use_cct) {
root["useCCT"] = _light_use_cct;
root["mireds"] = _light_mireds;
}
if (useRGB) { if (useRGB) {
root["rgb"] = lightColor(true); root["rgb"] = lightColor(true);
root["brightness"] = lightBrightness(); root["brightness"] = lightBrightness();
@ -780,6 +820,12 @@ void _lightWebSocketOnAction(uint32_t client_id, const char * action, JsonObject
lightUpdate(true, true); lightUpdate(true, true);
} }
} }
if (_light_use_cct) {
if (strcmp(action, "mireds") == 0) {
_fromMireds(data["mireds"]);
lightUpdate(true, true);
}
}
} }
if (strcmp(action, "channel") == 0) { if (strcmp(action, "channel") == 0) {
@ -961,6 +1007,12 @@ void _lightConfigure() {
setSetting("useWhite", _light_use_white); setSetting("useWhite", _light_use_white);
} }
_light_use_cct = getSetting("useCCT", LIGHT_USE_CCT).toInt() == 1;
if (_light_use_cct && ((_light_channel.size() < 5) || !_light_use_white)) {
_light_use_cct = false;
setSetting("useCCT", _light_use_cct);
}
_light_use_gamma = getSetting("useGamma", LIGHT_USE_GAMMA).toInt() == 1; _light_use_gamma = getSetting("useGamma", LIGHT_USE_GAMMA).toInt() == 1;
_light_use_transitions = getSetting("useTransitions", LIGHT_USE_TRANSITIONS).toInt() == 1; _light_use_transitions = getSetting("useTransitions", LIGHT_USE_TRANSITIONS).toInt() == 1;
_light_transition_time = getSetting("lightTime", LIGHT_TRANSITION_TIME).toInt(); _light_transition_time = getSetting("lightTime", LIGHT_TRANSITION_TIME).toInt();


+ 16
- 0
code/espurna/migrate.ino View File

@ -937,6 +937,22 @@ void migrate() {
setSetting("relayResetGPIO", 0, 12); setSetting("relayResetGPIO", 0, 12);
setSetting("relayType", 0, RELAY_TYPE_LATCHED); setSetting("relayType", 0, RELAY_TYPE_LATCHED);
#elif defined(TONBUX_MOSQUITO_KILLER)
setSetting("board", 74);
setSetting("ledGPIO", 0, 15);
setSetting("ledLogic", 0, 1);
setSetting("ledGPIO", 1, 14);
setSetting("ledLogic", 1, 1);
setSetting("ledGPIO", 2, 12);
setSetting("ledLogic", 2, 0);
setSetting("ledGPIO", 3, 16);
setSetting("ledLogic", 3, 0);
setSetting("btnGPIO", 0, 2);
setSetting("btnRelay", 0, 0);
setSetting("relayGPIO", 0, 5);
setSetting("relayType", 0, RELAY_TYPE_NORMAL);
#else #else
// Allow users to define new settings without migration config // Allow users to define new settings without migration config


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

@ -829,9 +829,10 @@ void relaySetup() {
// Dummy relays for AI Light, Magic Home LED Controller, H801, // Dummy relays for AI Light, Magic Home LED Controller, H801,
// Sonoff Dual and Sonoff RF Bridge // Sonoff Dual and Sonoff RF Bridge
#if DUMMY_RELAY_COUNT > 0 #if DUMMY_RELAY_COUNT > 0
unsigned int _delay_on[8] = {RELAY1_DELAY_ON, RELAY2_DELAY_ON, RELAY3_DELAY_ON, RELAY4_DELAY_ON, RELAY5_DELAY_ON, RELAY6_DELAY_ON, RELAY7_DELAY_ON, RELAY8_DELAY_ON};
unsigned int _delay_off[8] = {RELAY1_DELAY_OFF, RELAY2_DELAY_OFF, RELAY3_DELAY_OFF, RELAY4_DELAY_OFF, RELAY5_DELAY_OFF, RELAY6_DELAY_OFF, RELAY7_DELAY_OFF, RELAY8_DELAY_OFF};
for (unsigned char i=0; i < DUMMY_RELAY_COUNT; i++) { for (unsigned char i=0; i < DUMMY_RELAY_COUNT; i++) {
_relays.push_back((relay_t) {0, RELAY_TYPE_NORMAL});
_relays.push_back((relay_t) {0, RELAY_TYPE_NORMAL,0,_delay_on[i], _delay_off[i]});
} }
#else #else


+ 8
- 11
code/espurna/sensors/PZEM004TSensor.h View File

@ -20,9 +20,10 @@ class PZEM004TSensor : public BaseSensor {
// Public // Public
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
PZEM004TSensor(): BaseSensor(), _data() {
PZEM004TSensor(): BaseSensor() {
_count = 4; _count = 4;
_sensor_id = SENSOR_PZEM004T_ID; _sensor_id = SENSOR_PZEM004T_ID;
_ip = IPAddress(192,168,1,1);
} }
~PZEM004TSensor() { ~PZEM004TSensor() {
@ -43,7 +44,7 @@ class PZEM004TSensor : public BaseSensor {
_dirty = true; _dirty = true;
} }
void setSerial(Stream & serial) {
void setSerial(HardwareSerial * serial) {
_serial = serial; _serial = serial;
_dirty = true; _dirty = true;
} }
@ -58,10 +59,6 @@ class PZEM004TSensor : public BaseSensor {
return _pin_tx; return _pin_tx;
} }
Stream & getSerial() {
return _serial;
}
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Sensor API // Sensor API
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -72,10 +69,10 @@ class PZEM004TSensor : public BaseSensor {
if (!_dirty) return; if (!_dirty) return;
if (_pzem) delete _pzem; if (_pzem) delete _pzem;
if (_serial == NULL) {
_pzem = PZEM004T(_pin_rx, _pin_tx);
if (_serial) {
_pzem = new PZEM004T(_serial);
} else { } else {
_pzem = PZEM004T(_serial);
_pzem = new PZEM004T(_pin_rx, _pin_tx);
} }
_pzem->setAddress(_ip); _pzem->setAddress(_ip);
@ -127,8 +124,8 @@ class PZEM004TSensor : public BaseSensor {
unsigned int _pin_rx = PZEM004T_RX_PIN; unsigned int _pin_rx = PZEM004T_RX_PIN;
unsigned int _pin_tx = PZEM004T_TX_PIN; unsigned int _pin_tx = PZEM004T_TX_PIN;
Stream & _serial = NULL;
IPAddress _ip(192,168,1,1);
IPAddress _ip;
HardwareSerial * _serial = NULL;
PZEM004T * _pzem = NULL; PZEM004T * _pzem = NULL;
}; };


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


+ 2
- 0
code/espurna/wifi.ino View File

@ -198,6 +198,8 @@ void _wifiInject() {
#if WIFI_AP_CAPTIVE #if WIFI_AP_CAPTIVE
#include "DNSServer.h"
DNSServer _wifi_dnsServer; DNSServer _wifi_dnsServer;
void _wifiCaptivePortal(justwifi_messages_t code, char * parameter) { void _wifiCaptivePortal(justwifi_messages_t code, char * parameter) {


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

@ -13,6 +13,7 @@ var numReconnect = 0;
var numReload = 0; var numReload = 0;
var useWhite = false; var useWhite = false;
var useCCT = false;
var now = 0; var now = 0;
var ago = 0; var ago = 0;
@ -804,6 +805,22 @@ function initColorRGB() {
} }
function initCCT() {
// check if already initialized
var done = $("#cct > div").length;
if (done > 0) { return; }
$("#miredsTemplate").children().clone().appendTo("#cct");
$("#mireds").on("change", function() {
var value = $(this).val();
var parent = $(this).parents(".pure-g");
$("span", parent).html(value);
sendAction("mireds", {mireds: value});
});
}
function initColorHSV() { function initColorHSV() {
// check if already initialized // check if already initialized
@ -841,6 +858,9 @@ function initChannels(num) {
max = num % 3; max = num % 3;
if ((max > 0) & useWhite) { if ((max > 0) & useWhite) {
max--; max--;
if (useCCT) {
max--;
}
} }
} }
var start = num - max; var start = num - max;
@ -1021,10 +1041,21 @@ function processData(data) {
return; return;
} }
if ("mireds" === key) {
$("#mireds").val(value);
$("span.mireds").html(value);
return;
}
if ("useWhite" === key) { if ("useWhite" === key) {
useWhite = value; useWhite = value;
} }
if ("useCCT" === key) {
initCCT();
useCCT = value;
}
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Sensors & Magnitudes // Sensors & Magnitudes
// --------------------------------------------------------------------- // ---------------------------------------------------------------------


+ 24
- 6
code/html/index.html View File

@ -179,6 +179,8 @@
<div id="colors"></div> <div id="colors"></div>
<div id="cct"></div>
<div id="channels"></div> <div id="channels"></div>
<div id="magnitudes"></div> <div id="magnitudes"></div>
@ -410,12 +412,20 @@
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="useWhite" action="reload" tabindex="9" /></div> <div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="useWhite" action="reload" tabindex="9" /></div>
<div class="pure-u-0 pure-u-lg-1-2"></div> <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-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint">Use forth dimmable channel as white when first 3 have the same RGB value.<br />Will only work if the device has at least 4 dimmable channels.<br />Enabling this will render useless the "Channel 4" slider in the status page.<br />Reload the page to update the web interface.</div>
<div class="pure-u-1 pure-u-lg-3-4 hint">Use forth dimmable channel as (cold) white light calculated out of the RGB values.<br />Will only work if the device has at least 4 dimmable channels.<br />Enabling this will render useless the "Channel 4" slider in the status page.<br />Reload the page to update the web interface.</div>
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Use white color temperature</label>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="useCCT" action="reload" tabindex="10" /></div>
<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">Use fifth dimmable channel as warm white light and the forth dimmable channel as cold white.<br />Will only work if the device has at least 5 dimmable channels and "white channel" above is also ON.<br />Enabling this will render useless the "Channel 5" slider in the status page.<br />Reload the page to update the web interface.</div>
</div> </div>
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Use gamma correction</label> <label class="pure-u-1 pure-u-lg-1-4">Use gamma correction</label>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="useGamma" tabindex="10" /></div>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="useGamma" tabindex="11" /></div>
<div class="pure-u-0 pure-u-lg-1-2"></div> <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-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint">Use gamma correction for RGB channels.<br />Will only work if "use colorpicker" above is also ON.</div> <div class="pure-u-1 pure-u-lg-3-4 hint">Use gamma correction for RGB channels.<br />Will only work if "use colorpicker" above is also ON.</div>
@ -423,7 +433,7 @@
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Use CSS style</label> <label class="pure-u-1 pure-u-lg-1-4">Use CSS style</label>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="useCSS" tabindex="11" /></div>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="useCSS" tabindex="12" /></div>
<div class="pure-u-0 pure-u-lg-1-2"></div> <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-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint">Use CSS style to report colors to MQTT and REST API. <br />Red will be reported as "#FF0000" if ON, otherwise "255,0,0"</div> <div class="pure-u-1 pure-u-lg-3-4 hint">Use CSS style to report colors to MQTT and REST API. <br />Red will be reported as "#FF0000" if ON, otherwise "255,0,0"</div>
@ -431,7 +441,7 @@
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Color transitions</label> <label class="pure-u-1 pure-u-lg-1-4">Color transitions</label>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="useTransitions" tabindex="12" /></div>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="useTransitions" tabindex="13" /></div>
<div class="pure-u-0 pure-u-lg-1-2"></div> <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-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint">If enabled color changes will be smoothed.</div> <div class="pure-u-1 pure-u-lg-3-4 hint">If enabled color changes will be smoothed.</div>
@ -439,7 +449,7 @@
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Transition time</label> <label class="pure-u-1 pure-u-lg-1-4">Transition time</label>
<div class="pure-u-1 pure-u-lg-1-4"><input class="pure-u-1" type="number" name="lightTime" min="10" max="5000" tabindex="13" /></div>
<div class="pure-u-1 pure-u-lg-1-4"><input class="pure-u-1" type="number" name="lightTime" min="10" max="5000" tabindex="14" /></div>
<div class="pure-u-0 pure-u-lg-1-2"></div> <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-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint">Time in millisecons to transition from one color to another.</div> <div class="pure-u-1 pure-u-lg-3-4 hint">Time in millisecons to transition from one color to another.</div>
@ -447,7 +457,7 @@
<div class="pure-g"> <div class="pure-g">
<div class="pure-u-1 pure-u-lg-1-4"><label>MQTT group</label></div> <div class="pure-u-1 pure-u-lg-1-4"><label>MQTT group</label></div>
<div class="pure-u-1 pure-u-lg-3-4"><input name="mqttGroupColor" class="pure-u-1" tabindex="14" action="reconnect" /></div>
<div class="pure-u-1 pure-u-lg-3-4"><input name="mqttGroupColor" class="pure-u-1" tabindex="15" action="reconnect" /></div>
<div class="pure-u-0 pure-u-lg-1-4"></div> <div class="pure-u-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint">Sync color between different lights.</div> <div class="pure-u-1 pure-u-lg-3-4 hint">Sync color between different lights.</div>
</div> </div>
@ -1405,6 +1415,14 @@
</div> </div>
</div> </div>
<div id="miredsTemplate" class="template">
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Mireds (Cold &harr; Warm)</label>
<input type="range" min="153" max="500" class="slider pure-u-lg-1-4" id="mireds">
<span class="slider mireds pure-u-lg-1-4"></span>
</div>
</div>
<div id="magnitudeTemplate" class="template"> <div id="magnitudeTemplate" class="template">
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4"></label> <label class="pure-u-1 pure-u-lg-1-4"></label>


+ 25
- 1
code/platformio.ini View File

@ -64,7 +64,7 @@ lib_deps =
https://bitbucket.org/xoseperez/fauxmoesp.git#2.4.2 https://bitbucket.org/xoseperez/fauxmoesp.git#2.4.2
https://github.com/xoseperez/hlw8012.git#1.1.0 https://github.com/xoseperez/hlw8012.git#1.1.0
https://github.com/markszabo/IRremoteESP8266#v2.2.0 https://github.com/markszabo/IRremoteESP8266#v2.2.0
https://bitbucket.org/xoseperez/justwifi.git#1.1.8
https://bitbucket.org/xoseperez/justwifi.git#1.1.9
https://github.com/madpilot/mDNSResolver#4cfcda1 https://github.com/madpilot/mDNSResolver#4cfcda1
https://github.com/xoseperez/my92xx#3.0.1 https://github.com/xoseperez/my92xx#3.0.1
https://bitbucket.org/xoseperez/nofuss.git#0.2.5 https://bitbucket.org/xoseperez/nofuss.git#0.2.5
@ -2128,3 +2128,27 @@ upload_speed = 115200
upload_port = "${env.ESPURNA_IP}" upload_port = "${env.ESPURNA_IP}"
upload_flags = --auth=${env.ESPURNA_AUTH} --port 8266 upload_flags = --auth=${env.ESPURNA_AUTH} --port 8266
extra_scripts = ${common.extra_scripts} extra_scripts = ${common.extra_scripts}
[env:tonbux-mosquito-killer]
platform = ${common.platform}
framework = arduino
board = esp01_1m
board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DTONBUX_MOSQUITO_KILLER
monitor_baud = 115200
extra_scripts = ${common.extra_scripts}
[env:tonbux-mosquito-killer-ota]
platform = ${common.platform}
framework = arduino
board = esp01_1m
board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DTONBUX_MOSQUITO_KILLER
upload_speed = 115200
upload_port = "${env.ESPURNA_IP}"
upload_flags = --auth=${env.ESPURNA_AUTH} --port 8266
extra_scripts = ${common.extra_scripts}

BIN
images/devices/tonbux-mosquito-killer.jpg View File

Before After
Width: 400  |  Height: 400  |  Size: 16 KiB

Loading…
Cancel
Save