Browse Source

Merge branch 'dev' into fastled

Conflicts:
	code/espurna/light.ino
fastled
Xose Pérez 6 years ago
parent
commit
ba60f34eee
16 changed files with 2633 additions and 2563 deletions
  1. +17
    -0
      CHANGELOG.md
  2. +2
    -1
      README.md
  3. +2
    -0
      code/espurna/config/general.h
  4. +30
    -33
      code/espurna/config/hardware.h
  5. +2
    -2
      code/espurna/config/sensors.h
  6. +1
    -1
      code/espurna/config/version.h
  7. BIN
      code/espurna/data/index.html.gz
  8. +14
    -2
      code/espurna/domoticz.ino
  9. +20
    -0
      code/espurna/led.ino
  10. +1
    -1
      code/espurna/libs/pwm.h
  11. +6
    -0
      code/espurna/light.ino
  12. +2
    -1
      code/espurna/migrate.ino
  13. +43
    -34
      code/espurna/relay.ino
  14. +2483
    -2481
      code/espurna/static/index.html.gz.h
  15. +4
    -1
      code/html/index.html
  16. +6
    -6
      code/platformio.ini

+ 17
- 0
CHANGELOG.md View File

@ -3,6 +3,23 @@
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [1.11.2] 2017-12-30
### Fixed
- Fix my92xx and pwm references for Arduino IDE (#346)
- Fix SHT3X I2C sensor magnitude count (#337)
- Fix timing for DHT11 sensors (#294)
- Fix overflow in relayParsePayload with long MQTT messages (#344)
- Fix loading of Dallas and DHT sensors for Sonoff TH images (#352)
- Subscribe to Domoticz MQTT topics only if Domotic< is enabled
### Added
- Added option to change MQTT retain flag, QoS and keepalive time from webUI (#321)
- Added LED modes "always off" and "always on" (#348)
- Defined new ESPurna switch (no HLW8012 support & touch button ready)
### Changed
- Stop requiring definition of boards in migrate module
## [1.11.1] 2017-12-29
### Fixed
- Fixed relay status on reboot


+ 2
- 1
README.md View File

@ -4,7 +4,7 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8266 based smart switch
It was originally developed with the **[IteadStudio Sonoff](https://www.itead.cc/sonoff-wifi-wireless-switch.html)** in mind but now it supports a growing number of ESP8266-based boards.
It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries.
> **Current Release Version is 1.11.1**, read the [changelog](https://bitbucket.org/xoseperez/espurna/src/master/CHANGELOG.md).
> **Current Release Version is 1.11.2**, read the [changelog](https://bitbucket.org/xoseperez/espurna/src/master/CHANGELOG.md).
> **NOTICE**: Default flash layout changed in 1.8.3, as an unpredicted consequence devices will not be able to persist/retrieve configuration if flashed with 1.8.3 via **OTA** from **PlatformIO**. Please check issue #187.
@ -104,6 +104,7 @@ It uses the Arduino Core for ESP8266 framework and a number of 3rd party librari
* Double click to enter AP mode (only main button)
* Long click (>1 second) to reboot device (only main button)
* Extra long click (>10 seconds) to go back to factory settings (only main button)
* Specific definitions for touch button devices (ESPurna Switch, Sonoff Touch & T1)
## Documentation


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

@ -264,6 +264,8 @@ PROGMEM const char* const custom_reset_string[] = {
#define LED_MODE_FOLLOW_INVERSE 3 // LED will follow the opposite state of linked relay (check RELAY#_LED)
#define LED_MODE_FINDME 4 // LED will be ON if all relays are OFF
#define LED_MODE_MIXED 5 // A mixed between WIFI and FINDME
#define LED_MODE_ON 6 // LED always ON
#define LED_MODE_OFF 7 // LED always OFF
// -----------------------------------------------------------------------------
// WIFI


+ 30
- 33
code/espurna/config/hardware.h View File

@ -104,23 +104,8 @@
#define BUTTON1_PIN 4
#define BUTTON1_RELAY 1
#ifdef USE_TOUCH_BUTTON
// Touch button
#define BUTTON1_MODE BUTTON_PUSHBUTTON
#define BUTTON1_PRESS BUTTON_MODE_TOGGLE
#define BUTTON1_CLICK BUTTON_MODE_NONE
#define BUTTON1_DBLCLICK BUTTON_MODE_NONE
#define BUTTON1_LNGCLICK BUTTON_MODE_NONE
#define BUTTON1_LNGLNGCLICK BUTTON_MODE_NONE
#else
// Normal pushbutton
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#endif
// Normal pushbutton
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
// Relays
#define RELAY1_PIN 12
@ -148,22 +133,8 @@
#define BUTTON1_PIN 4
#define BUTTON1_RELAY 1
#ifdef USE_TOUCH_BUTTON
// Touch button
#define BUTTON1_MODE BUTTON_PUSHBUTTON
#define BUTTON1_PRESS BUTTON_MODE_TOGGLE
#define BUTTON1_CLICK BUTTON_MODE_NONE
#define BUTTON1_DBLCLICK BUTTON_MODE_NONE
#define BUTTON1_LNGCLICK BUTTON_MODE_NONE
#define BUTTON1_LNGLNGCLICK BUTTON_MODE_NONE
#else
// Normal pushbutton
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#endif
// Normal pushbutton
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
// Relays
#define RELAY1_PIN 12
@ -181,6 +152,32 @@
#define HLW8012_CF1_PIN 13
#define HLW8012_CF_PIN 14
#elif defined(TINKERMAN_ESPURNA_SWITCH)
// Info
#define MANUFACTURER "TINKERMAN"
#define DEVICE "ESPURNA_SWITCH"
// Buttons
#define BUTTON1_PIN 4
#define BUTTON1_RELAY 1
// Touch button
#define BUTTON1_MODE BUTTON_PUSHBUTTON
#define BUTTON1_PRESS BUTTON_MODE_TOGGLE
#define BUTTON1_CLICK BUTTON_MODE_NONE
#define BUTTON1_DBLCLICK BUTTON_MODE_NONE
#define BUTTON1_LNGCLICK BUTTON_MODE_NONE
#define BUTTON1_LNGLNGCLICK BUTTON_MODE_NONE
// LEDs
#define LED1_PIN 2
#define LED1_PIN_INVERSE 0
// Relays
#define RELAY1_PIN 12
#define RELAY1_TYPE RELAY_TYPE_INVERSE
// -----------------------------------------------------------------------------
// Itead Studio boards
// -----------------------------------------------------------------------------


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

@ -158,7 +158,7 @@
#endif
#ifndef DALLAS_PIN
#define DALLAS_PIN 13
#define DALLAS_PIN 14
#endif
#define DALLAS_RESOLUTION 9 // Not used atm
@ -174,7 +174,7 @@
#endif
#ifndef DHT_PIN
#define DHT_PIN 13
#define DHT_PIN 14
#endif
#ifndef DHT_TYPE


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

@ -1,5 +1,5 @@
#define APP_NAME "ESPURNA"
#define APP_VERSION "1.11.2b"
#define APP_VERSION "1.11.2"
#define APP_AUTHOR "xose.perez@gmail.com"
#define APP_WEBSITE "http://tinkerman.cat"
#define CFG_VERSION 3

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


+ 14
- 2
code/espurna/domoticz.ino View File

@ -35,8 +35,21 @@ bool _domoticzSkip(unsigned long idx) {
return false;
}
void _domoticzMqttSubscribe(bool value) {
String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC);
if (value) {
mqttSubscribeRaw(dczTopicOut.c_str());
} else {
mqttUnsubscribeRaw(dczTopicOut.c_str());
}
}
void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) {
if (!_dcz_enabled) return;
String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC);
if (type == MQTT_CONNECT_EVENT) {
@ -45,8 +58,6 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload)
if (type == MQTT_MESSAGE_EVENT) {
if (!_dcz_enabled) return;
// Check topic
if (dczTopicOut.equals(topic)) {
@ -107,6 +118,7 @@ void _domoticzWebSocketOnSend(JsonObject& root) {
void _domoticzConfigure() {
_dcz_enabled = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1;
_dcz_skip_time = 1000 * getSetting("dczSkip", DOMOTICZ_SKIP_TIME).toInt();
_domoticzMqttSubscribe(_dcz_enabled);
}
//------------------------------------------------------------------------------


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

@ -18,6 +18,7 @@ typedef struct {
} led_t;
std::vector<led_t> _leds;
bool _led_update = false; // For relay-based modes
// -----------------------------------------------------------------------------
@ -115,10 +116,15 @@ void _ledConfigure() {
for (unsigned int i=0; i < _leds.size(); i++) {
_ledMode(i, getSetting("ledMode", i, _ledMode(i)).toInt());
}
_led_update = true;
}
// -----------------------------------------------------------------------------
void ledUpdate(bool value) {
_led_update = value;
}
void ledSetup() {
#ifdef LED1_PIN
@ -206,6 +212,9 @@ void ledLoop() {
}
// Relay-based modes, update only if relays have been updated
if (!_led_update) continue;
if (_ledMode(i) == LED_MODE_FOLLOW) {
_ledStatus(i, relayStatus(_leds[i].relay-1));
}
@ -225,5 +234,16 @@ void ledLoop() {
_ledStatus(i, status);
}
if (_ledMode(i) == LED_MODE_ON) {
_ledStatus(i, true);
}
if (_ledMode(i) == LED_MODE_OFF) {
_ledStatus(i, false);
}
}
_led_update = false;
}

+ 1
- 1
code/espurna/libs/pwm.h View File

@ -9,7 +9,7 @@
/*NOTE!! : DO NOT CHANGE THIS FILE*/
/*SUPPORT UP TO 8 PWM CHANNEL*/
//#define PWM_CHANNEL_NUM_MAX 8
#define PWM_CHANNEL_NUM_MAX 8
struct pwm_param {
uint32 period;


+ 6
- 0
code/espurna/light.ino View File

@ -12,6 +12,12 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#include <ArduinoJson.h>
#include <vector>
#if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
extern "C" {
#include "libs/pwm.h"
}
#endif
// -----------------------------------------------------------------------------
Ticker _light_save_ticker;


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

@ -696,7 +696,8 @@ void migrate() {
#else
#error "UNSUPPORTED HARDWARE!"
// Allow users to define new settings without migration config
//#error "UNSUPPORTED HARDWARE!"
#endif


+ 43
- 34
code/espurna/relay.ino View File

@ -276,16 +276,21 @@ unsigned char relayParsePayload(const char * payload) {
// Payload could be "OFF", "ON", "TOGGLE"
// or its number equivalents: 0, 1 or 2
if (payload[0] == '0') return 0;
if (payload[0] == '1') return 1;
if (payload[0] == '2') return 2;
// trim payload
char * p = ltrim((char *)payload);
// to lower
for (unsigned char i=0; i<strlen(p); i++) {
unsigned int l = strlen(p);
if (l>6) l=6;
for (unsigned char i=0; i<l; i++) {
p[i] = tolower(p[i]);
}
unsigned int value;
unsigned int value = 0xFF;
if (strcmp(p, "off") == 0) {
value = 0;
} else if (strcmp(p, "on") == 0) {
@ -294,12 +299,9 @@ unsigned char relayParsePayload(const char * payload) {
value = 2;
} else if (strcmp(p, "query") == 0) {
value = 3;
} else {
value = p[0] - '0';
}
if (0 <= value && value <=3) return value;
return 0xFF;
return value;
}
@ -583,43 +585,47 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
if (type == MQTT_MESSAGE_EVENT) {
// Get value
unsigned char value = relayParsePayload(payload);
if (value == 0xFF) {
DEBUG_MSG_P(PSTR("[RELAY] Wrong payload (%s)\n"), payload);
// Check relay topic
String t = mqttSubtopic((char *) topic);
if (t.startsWith(MQTT_TOPIC_RELAY)) {
// Get value
unsigned char value = relayParsePayload(payload);
if (value == 0xFF) return;
// Get relay ID
unsigned int id = t.substring(strlen(MQTT_TOPIC_RELAY)+1).toInt();
if (id >= relayCount()) {
DEBUG_MSG_P(PSTR("[RELAY] Wrong relayID (%d)\n"), id);
} else {
relayStatusWrap(id, value, false);
}
return;
}
// Check group topics
bool found = false;
for (unsigned int i=0; i < _relays.size(); i++) {
String t = getSetting("mqttGroup", i, "");
if (t.equals(topic)) {
unsigned char local_value = value;
if (getSetting("mqttGroupInv", i, 0).toInt() == 1) {
if (local_value < 2) local_value = 1 - local_value;
}
found = true;
DEBUG_MSG_P(PSTR("[RELAY] Matched group topic for relayID %d\n"), i);
relayStatusWrap(i, local_value, true);
}
}
// If found as group topic quit
if (found) return;
if ((t.length() > 0) && t.equals(topic)) {
// Else, try to match topic
String t = mqttSubtopic((char *) topic);
if (!t.startsWith(MQTT_TOPIC_RELAY)) return;
unsigned char value = relayParsePayload(payload);
if (value == 0xFF) return;
// Get relay ID
unsigned int id = t.substring(strlen(MQTT_TOPIC_RELAY)+1).toInt();
if (id >= relayCount()) {
DEBUG_MSG_P(PSTR("[RELAY] Wrong relayID (%d)\n"), id);
return;
}
if (value < 2) {
if (getSetting("mqttGroupInv", i, 0).toInt() == 1) {
value = 1 - value;
}
}
DEBUG_MSG_P(PSTR("[RELAY] Matched group topic for relayID %d\n"), i);
relayStatusWrap(i, value, true);
relayStatusWrap(id, value, false);
}
}
}
@ -741,6 +747,9 @@ void relayLoop(void) {
relayInfluxDB(id);
#endif
// Flag relay-based LEDs to update status
ledUpdate(true);
_relays[id].report = false;
_relays[id].group_report = false;


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


+ 4
- 1
code/html/index.html View File

@ -268,6 +268,8 @@
<option value="0">MQTT managed</option>
<option value="4">Find me</option>
<option value="5">Mixed</option>
<option value="6">Always ON</option>
<option value="7">Always OFF</option>
</select>
<div class="pure-u-0 pure-u-lg-1-2"></div>
<div class="pure-u-0 pure-u-lg-1-4"></div>
@ -276,7 +278,8 @@
When in "WiFi status" it will blink at 1Hz when trying to connecting. If successfully connected if will briefly lit every 5 seconds if in STA mode or every second if in AP mode.<br />
When in "MQTT managed" mode you will be able to set the LED state sending a message to "&lt;base_topic&gt;/led/0/set" with a payload of 0, 1 or 2 (to toggle it).<br />
When in "Find me" mode the LED will be ON when all relays are OFF. This is meant to locate switches at night.<br />
When in "Mixed" mode it will follow the WiFi status but will stay mostly on when relays are OFF, and mostly OFF when any of them is ON.
When in "Mixed" mode it will follow the WiFi status but will stay mostly on when relays are OFF, and mostly OFF when any of them is ON.<br />
"Always ON" and "Always OFF" modes are self-explanatory.
</div>
</div>


+ 6
- 6
code/platformio.ini View File

@ -172,7 +172,7 @@ upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-basic-dht22]
[env:itead-sonoff-basic-dht]
platform = ${common.platform}
framework = arduino
board = esp01_1m
@ -182,7 +182,7 @@ lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_BASIC -DDHT_SUPPORT=1
monitor_baud = 115200
[env:itead-sonoff-basic-dht22-ota]
[env:itead-sonoff-basic-dht-ota]
platform = ${common.platform}
framework = arduino
board = esp01_1m
@ -195,14 +195,14 @@ upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
[env:itead-sonoff-basic-ds18b20]
[env:itead-sonoff-basic-dallas]
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} -DITEAD_SONOFF_BASIC -DDS18B20_SUPPORT=1
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_BASIC -DDALLAS_SUPPORT=1
monitor_baud = 115200
[env:itead-sonoff-rf]
@ -690,7 +690,7 @@ framework = arduino
board = esp_wroom_02
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags} -DOPENENERGYMONITOR_MQTT_RELAY -DDS18B20_SUPPORT=1
build_flags = ${common.build_flags} -DOPENENERGYMONITOR_MQTT_RELAY -DDALLAS_SUPPORT=1
monitor_baud = 115200
[env:openenergymonitor-mqtt-relay-ota]
@ -699,7 +699,7 @@ framework = arduino
board = esp_wroom_02
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags} -DOPENENERGYMONITOR_MQTT_RELAY -DDS18B20_SUPPORT=1
build_flags = ${common.build_flags} -DOPENENERGYMONITOR_MQTT_RELAY -DDALLAS_SUPPORT=1
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266


Loading…
Cancel
Save