Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge latest dev #1

Merged
merged 95 commits into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
2ecce4d
README: add nightly builder releases and missing sensors (#1955)
mcspr Oct 24, 2019
2f6d3ec
Fix releases URLs and add more info about compilation (#1960)
mcspr Oct 24, 2019
5e7f3c2
mqtt: reduce debug log pressure, return result of mqttSend
mcspr Nov 1, 2019
5bef606
ha: delay discovery until next loop
mcspr Nov 1, 2019
7adedc8
ws: use std::pair instead of custom struct
mcspr Nov 1, 2019
9956cd8
ha: send discovery on reconnect
mcspr Nov 1, 2019
e8acf33
ha: more cancelation reasons
mcspr Nov 1, 2019
c414ba1
ha: log autodiscovery -> discovery
mcspr Nov 1, 2019
94291fa
1.13.6-dev Changelog so far (#1930)
mcspr Nov 6, 2019
4343457
Support restore last schedule (#1948)
foxman69 Nov 6, 2019
d177634
Telaire T6613 Support (#1956)
james-coder Nov 6, 2019
0134598
gpio: detect esp8285 chip to allow the use of GPIO9 and GPIO10 (#1964)
mcspr Nov 6, 2019
bad47d0
Typo in thingspeak macro (#1965)
Niek Nov 6, 2019
17b3620
1.14.0-dev
mcspr Nov 8, 2019
c6f75f9
Comments & README - 1.13.6 -> 1.14.0 (#1980)
mcspr Nov 8, 2019
05a1029
Fix out_of_range exception on bitset.test (#1977)
Niek Nov 8, 2019
292ef5b
mqtt: Arduino-MQTT setWill parameters order (#1978)
Niek Nov 8, 2019
cec6c6a
Adding support for miobulb001 (#1973)
ealfaroc Nov 8, 2019
5ae0eb8
sensor/dht: increase the delay per DHT22 datasheet
mcspr Nov 8, 2019
e1ed62a
sensor/dht: set pin mode before digitalWrite
mcspr Nov 8, 2019
08cfcbd
sensor/dht: wait DHT_MIN_INTERVAL after initialization
mcspr Nov 8, 2019
c3678ab
Relay: use relative time comparisons, runtime settings for flood wind…
mcspr Nov 9, 2019
99dcff3
Merge pull request #1969 from mcspr/ha/disc-queue
mcspr Nov 9, 2019
377ee70
Changelog: 1.14.0 + recent commits (#1982)
mcspr Nov 9, 2019
849f8cf
Rules RPN (#1984)
mcspr Nov 10, 2019
04c7333
relay: add WEB_SUPPORT check (#1985)
mcspr Nov 10, 2019
f588893
Use generic typechecks, OTA add followRedirects (#1974)
Niek Nov 17, 2019
7fa05d1
utils/heartbeat: fix hbReport=1 condition, add Bssid (#1995)
mcspr Nov 17, 2019
ab186e0
Add missing / not implemented default getSettings values (#1996)
mcspr Nov 17, 2019
c96f2e4
Fix strtoul error condition (#1995)
mcspr Nov 18, 2019
9a5698b
Add TUYA_SUPPORT (#1997)
mcspr Nov 20, 2019
383d5a8
DHTSensor: fix Si7021 compatibility (#2000)
mcspr Nov 20, 2019
ca56e0e
Add THERMOSTAT_SUPPORT=1 to the sensor tests
mcspr Nov 20, 2019
1f41d79
Fix heartbeat check for thermostat, add Bssid for InfluxDB (#2002)
mcspr Nov 22, 2019
f4b0e9f
relay: fix dummy relays overwriting real ones
mcspr Nov 21, 2019
9f4329d
relay: replace eeprom 8bit with 32bit bitmask stored in settings
mcspr Nov 21, 2019
e7fc5f3
relay: rework mask handling to use generic u32<->string conversion
mcspr Nov 22, 2019
5e74adb
relay: proxy header defaults through methods
mcspr Nov 22, 2019
83f49e3
relay: write boot mask later, add relay_t defaults
mcspr Nov 22, 2019
19e474a
utils: fix base-10 condition
mcspr Nov 22, 2019
57c9359
utils: interval value is in seconds
mcspr Nov 22, 2019
76e2542
Merge pull request #2003 from mcspr/upd-dummy-relays
mcspr Nov 22, 2019
a6c5c7e
utils: u32 value prefix should depend on "base" argument (#2005)
mcspr Nov 22, 2019
812c3ea
web: init relay selectors inside relayConfig
mcspr Nov 25, 2019
fc5aa2f
sch: send type_switch as default
mcspr Nov 25, 2019
5c49db8
relay: compare sum of physical + dummy relays instead of just dummy (…
mcspr Nov 26, 2019
960b32c
Merge pull request #2013 from mcspr/web/sch-init-order
mcspr Nov 26, 2019
0b5d200
Scripts: memanalyser fixes (#2014)
mcspr Nov 26, 2019
899f646
Add support for Hykker Smart Plug with power meter (#2010)
reaper7 Nov 26, 2019
8c204f3
Update README.md
mcspr Nov 27, 2019
ea9d29f
Update Arduino core in PIO (#2018)
Niek Nov 27, 2019
0f71869
Clean up headers (#2019)
mcspr Nov 28, 2019
55a0abf
Secure client / server cleanup (#2016)
mcspr Nov 28, 2019
60063f9
Upgrade to core 2.6.2, fixes WiFi issues (#2023)
Niek Nov 28, 2019
f743ca4
Reword comments regarding 2.4.0 (#2024)
mcspr Nov 28, 2019
52fff43
Update nodemcu-lolin envs (#2025)
mcspr Nov 28, 2019
5ac420d
Scripts: memanalyzer can use size instead of objdump (#2021)
mcspr Nov 28, 2019
808d2b5
ota: arduinoota reboots after end callback
mcspr Nov 28, 2019
655805a
ota: hide progress cb under DEBUG_SUPPORT check
mcspr Nov 28, 2019
03e6443
system: move prototypes to a separate header
mcspr Nov 28, 2019
5e0ec86
system: same name as light for rtcmem struct member
mcspr Nov 28, 2019
c43efc7
nofuss: custom reset reason
mcspr Nov 28, 2019
8dab123
Merge pull request #2028 from mcspr/ota/arduino-ota-adjustments
mcspr Nov 28, 2019
4cb8cd3
Add support for BW-SHP5 (#2029)
aligator Nov 29, 2019
ae335c6
Update README.md (#2030)
reaper7 Nov 29, 2019
978cf2a
Version 1.14.0
mcspr Nov 29, 2019
bc70dec
Beautify build script size output
xoseperez Dec 5, 2019
a2599de
Removed unneeded reference to Ticker library in RFBridge module
xoseperez Dec 5, 2019
c271ba6
Using python3 by default in OTA manager
xoseperez Dec 6, 2019
7bf7aa6
Force get_device_size to return an int in OTA manager
xoseperez Dec 8, 2019
2c4cfd6
Version 1.14.1-dev (#2047)
mcspr Dec 9, 2019
b059ce9
domoticz: proper datastructure for mask (#2049)
mcspr Dec 9, 2019
15accf8
web: check sch_last existence (#2050)
mcspr Dec 9, 2019
2ef21d8
WebUI: fix some issues
mcspr Dec 9, 2019
987e343
travis: do not run test stages on tag (#2052)
mcspr Dec 9, 2019
5cf687f
WebUI: Fixed small aesthetic problem (#2038)
foxman69 Dec 9, 2019
e64ec2a
Device: add GENERIC_E14, e14 rgb+w 4,5w (#2039)
orrpan Dec 16, 2019
9c5dc67
Add support for LinkSprite R4 (#2042)
mpcusack Dec 16, 2019
b1d3488
Add support for eHomeDIY devices. (#2046)
user890104 Dec 16, 2019
8e8c990
Device: MAGICHOME_ZJ_WFMN_C_11 (#2051)
mcspr Dec 16, 2019
0ae6e3b
Influxdb: fix sensor send frequency, use async client, send data in b…
mcspr Dec 16, 2019
c6758e4
Revert "ir: use proper methods" (#2066)
mcspr Dec 16, 2019
c0c325e
Add support for the LSC LED LIGHT STRIP from ACTION using a tuya chip…
sehraf Dec 16, 2019
96a13f3
Influxdb: don't queue any data while connecting
mcspr Dec 16, 2019
e5b72a0
Device: add LOHAS_E26_A19, rename LOHAS_9W to LOHAS_E27_9W (#2068)
mcspr Dec 16, 2019
8e7854b
WebUI fix change detection of input elements (#1986)
mcspr Dec 18, 2019
de2179c
Update Arduino core to 2.3.2 (#2069)
Niek Dec 18, 2019
56ab28c
Update PIO platforms comment
mcspr Dec 18, 2019
76ba6d5
Recover -ota block for #2042
mcspr Dec 18, 2019
0f02256
Small fixes (#2071)
mcspr Dec 18, 2019
8066bbf
hw: set button pullup on shpx-v23 boards (#2074)
mcspr Dec 20, 2019
43cf926
ha: try to avoid conflict with useCSS (#2075)
mcspr Dec 20, 2019
4f5e9fa
OTA: verify data stream and properly handle errors (#2067)
mcspr Dec 20, 2019
9edccd1
Scripts: ota.py version 0.4 (#2020)
mcspr Dec 20, 2019
37763f1
Test: check core feature build (#2080)
mcspr Dec 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ env:
script:
- ./travis_script.sh
stages:
- name: Test
- name: Test WebUI
if: tag IS NOT present
- name: Test PlatformIO Build
if: tag IS NOT present
- name: Release
if: tag IS present AND tag =~ ^\d+\.\d+\.\d+$
jobs:
Expand Down
200 changes: 198 additions & 2 deletions CHANGELOG.md

Large diffs are not rendered by default.

48 changes: 33 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smart switches, lights and sensors.
It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries.

[![version](https://img.shields.io/badge/version-1.13.6--dev-brightgreen.svg)](CHANGELOG.md)
[![version](https://img.shields.io/badge/version-1.14.1--dev-brightgreen.svg)](CHANGELOG.md)
[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.com/xoseperez/espurna/tree/dev/)
[![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)
[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna)
[![codacy](https://api.codacy.com/project/badge/Grade/c9496e25cf07434cba786b462cb15f49)](https://www.codacy.com/app/xoseperez/espurna/dashboard)
<br />
[![latest master build](https://img.shields.io/github/release/xoseperez/espurna/all.svg?label=latest%20master%20build)](https://github.com/xoseperez/espurna/releases/latest)
[![latest dev build](https://img.shields.io/github/release/mcspr/espurna-nightly-builder/all.svg?label=latest%20dev%20build)](https://github.com/mcspr/espurna-nightly-builder/releases)
[![downloads](https://img.shields.io/github/downloads/xoseperez/espurna/total.svg)](https://github.com/xoseperez/espurna/releases)
<br />
[![donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=xose%2eperez%40gmail%2ecom&lc=US&no_note=0&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHostedGuest)
Expand All @@ -18,11 +21,11 @@ It uses the Arduino Core for ESP8266 framework and a number of 3rd party librari

## Collaborators

Since November 2018, Max Prokhorov (@mcspr) is also actively working as a collaborator of the project.
Since November 2018, Max Prokhorov (**@mcspr**) is also actively working as a collaborator of the project.

## Contributors

**Without your help this project would not be possible**. I (@xoseperez) simply can't spend all the time I wish on ESPurna but luckly I recieve a lot of contributions, bug fixes, enhancement suggestions,... from people all around the world. I would like to thank each and every one of you. The [contributors](https://github.com/xoseperez/espurna/graphs/contributors) page shows the ones that have done a PR in the past, but I also get contributions in the issues, by email or via the [gitter ESPurna channel](https://gitter.im/tinkerman-cat/espurna), those I also want to thank.
**Without your help this project would not be possible**. I (**@xoseperez**) simply can't spend all the time I wish on ESPurna but luckly I recieve a lot of contributions, bug fixes, enhancement suggestions,... from people all around the world. I would like to thank each and every one of you. The [contributors](https://github.com/xoseperez/espurna/graphs/contributors) page shows the ones that have done a PR in the past, but I also get contributions in the issues, by email or via the [gitter ESPurna channel](https://gitter.im/tinkerman-cat/espurna), those I also want to thank.

**Thank you all very much**.

Expand All @@ -32,6 +35,13 @@ Since November 2018, Max Prokhorov (@mcspr) is also actively working as a collab

> Please use the [gitter ESPurna channel](https://gitter.im/tinkerman-cat/espurna) for support and questions, you have better chances to get fast answers from me or other ESPurna users. Open an issue here only if you feel there is a bug or you want to request an enhancement. Thank you.

> Process of building ESPurna from source is documented in the Wiki:
[Using PlatformIO IDE for VSCode](https://github.com/xoseperez/espurna/wiki/Build-and-update-from-Visual-Studio-Code-using-PlatformIO)
[Using PlatformIO CLI](https://github.com/xoseperez/espurna/wiki/PlatformIO)
[Using Arduino IDE](https://github.com/xoseperez/espurna/wiki/ArduinoIDE)

> If you want to try out latest changes from **dev** branch without building the firmware yourself or if you are having problems with the stable release, please visit [**espurna-nightly-builder** releases page](https://github.com/mcspr/espurna-nightly-builder/releases).

## Features

* *KRACK* vulnerability free (when built with Arduino Core >= 2.4.0)
Expand Down Expand Up @@ -91,6 +101,7 @@ Since November 2018, Max Prokhorov (@mcspr) is also actively working as a collab
* **AM2320** temperature and humidity sensor over I2C
* **Dallas OneWire sensors** like the DS18B20
* **MHZ19** CO2 sensor
* **T6613** CO2 sensor
* **MICS2710** CO2 & NO2 sensor
* **MICS5525** CO & CO2 sensor
* **SenseAir S8** CO2 sensor
Expand All @@ -103,13 +114,18 @@ Since November 2018, Max Prokhorov (@mcspr) is also actively working as a collab
* **Geiger counter** by RH Electronics
* **HC-SR04**, **SRF05**, **SRF06**, **DYP-ME007**, **JSN-SR04T** & **Parallax PING)))™** distance sensors
* **VL53L1X** distance sensor
* **MAX6675** K-thermocouple-to-digital converter
* **NTC** thermistor
* **LDR** light-dependent resistor sensor
* Power monitoring
* **HLW8012** using the [HLW8012 Library](https://bitbucket.org/xoseperez/hlw8012) (Sonoff POW)
* **CSE7766** and **CSE7759B** power monitor chips
* **HJL-01** and **BL0937** power monitor chips
* Non-invasive **current sensor** using **internal ADC** or **ADC712** or **ADC121** or **ADS1115**
* Non-invasive **current sensor** using **internal ADC** or **ADC712** or **ADC121** or **ADS1015** / **ADS1115**
* **V9261F** power monitor chip
* **PZEM0004T** power monitor board
* **ECH1560** power monitor chip
* **ADE7953** power monitor chip
* Raw **analog** and **digital** sensors
* Simple **pulse counter** with **event triggering** option
* Support for (almost) any UART based sensor via the **UART-to-MQTT module**
Expand Down Expand Up @@ -166,7 +182,7 @@ Since November 2018, Max Prokhorov (@mcspr) is also actively working as a collab
* 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)
* Configuration stored in different sectors to prevent data loosing and corruption
* Configuration stored in different flash sectors to prevent data loss and corruption

## Notices

Expand Down Expand Up @@ -232,14 +248,14 @@ Here is the list of supported hardware. For more information please refer to the

||||
|---|---|---|
|![BlitzWolf BW-SHP6](images/devices/blitzwolf-bw-shp6.jpg)|![BlitzWolf BW-SHP2](images/devices/blitzwolf-bw-shp2.jpg)|![Power meters based on V9261F](images/devices/generic-v9261f.jpg)|
|**Blitzwolf BW-SHP6**|**Blitzwolf BW-SHP2<br />(also by Coosa, Gosund, HomeCube, Teckin)**|**Power meters based on V9261F**|
|![Itead Sonoff POW](images/devices/itead-sonoff-pow.jpg)|![Itead Sonoff POW](images/devices/itead-sonoff-pow-r2.jpg)|![Itead Sonoff S31](images/devices/itead-sonoff-s31.jpg)|
|**Itead Sonoff POW**|**Itead Sonoff POW R2**|**Itead Sonoff S31**|
|![Smartlife Mini Smart Socket](images/devices/smartlife-mini-smart-socket.jpg)|![Teckin SP20](images/devices/teckin-sp20.jpg)|![Digoo NX SP202](images/devices/digoo-nx-sp202.jpg)|
|**Smartlife (NETVIP) Mini Smart Socket**|**Teckin SP20**|**Digoo NX SP202**|
|![Vanzavanzu Smart WiFi Plug Mini](images/devices/vanzavanzu-smart-wifi-plug-mini.jpg)|||
|**Vanzavanzu Smart WiFi Plug Mini**|||
|![BlitzWolf BW-SHP6](images/devices/blitzwolf-bw-shp6.jpg)|![BlitzWolf BW-SHP2](images/devices/blitzwolf-bw-shp2.jpg)|![BlitzWolf BW-SHP5](images/devices/blitzwolf-bw-shp5.jpg)|
|**Blitzwolf BW-SHP6**|**Blitzwolf BW-SHP2<br />(also by Coosa, Gosund, HomeCube, Teckin)**|**Blitzwolf BW-SHP5**|
|![Power meters based on V9261F](images/devices/generic-v9261f.jpg)|![Itead Sonoff POW](images/devices/itead-sonoff-pow.jpg)|![Itead Sonoff POW](images/devices/itead-sonoff-pow-r2.jpg)|
|**Power meters based on V9261F**|**Itead Sonoff POW**|**Itead Sonoff POW R2**|
|![Itead Sonoff S31](images/devices/itead-sonoff-s31.jpg)|![Smartlife Mini Smart Socket](images/devices/smartlife-mini-smart-socket.jpg)|![Teckin SP20](images/devices/teckin-sp20.jpg)|
|**Itead Sonoff S31**|**Smartlife (NETVIP) Mini Smart Socket**|**Teckin SP20**|
|![Digoo NX SP202](images/devices/digoo-nx-sp202.jpg)|![Vanzavanzu Smart WiFi Plug Mini](images/devices/vanzavanzu-smart-wifi-plug-mini.jpg)|![Hykker Smart Home Power Plug](images/devices/hykker-smart-home-power-plug.jpg)|
|**Digoo NX SP202**|**Vanzavanzu Smart WiFi Plug Mini**|**Hykker Smart Home Power Plug**|

### Embedded switches

Expand All @@ -251,8 +267,8 @@ Here is the list of supported hardware. For more information please refer to the
|**Electrodragon WiFi IOT**|**OpenEnergyMonitor WiFi MQTT Relay / Thermostat**||
|![Itead Sonoff 4CH](images/devices/itead-sonoff-4ch.jpg)|![Itead Sonoff 4CH Pro](images/devices/itead-sonoff-4ch-pro.jpg)||
|**Itead Sonoff 4CH**|**Itead Sonoff 4CH Pro**||
|![Allterco Shelly1](images/devices/allterco-shelly1.jpg)|![Allterco Shelly2](images/devices/allterco-shelly2.jpg)|![Jan Goedeke Wifi Relay (NO/NC)](images/devices/jangoe-wifi-relay.jpg)|
|**Alterco Shelly1**|**Alterco Shelly2**|**Jan Goedeke Wifi Relay (NO/NC)**|
|![Allterco Shelly 1 / 1PM](images/devices/allterco-shelly1.jpg)|![Allterco Shelly 2 / 2.5](images/devices/allterco-shelly2.jpg)|![Jan Goedeke Wifi Relay (NO/NC)](images/devices/jangoe-wifi-relay.jpg)|
|**Alterco Shelly 1 / 1PM**|**Alterco Shelly 2 / 2.5**|**Jan Goedeke Wifi Relay (NO/NC)**|
|![EXS Wifi Relay v3.1](images/devices/exs-wifi-relay-v31.jpg)|![EXS Wifi Relay v5.0](images/devices/exs-wifi-relay-v50.jpg)|![Jorge García Wifi + Relays Board Kit](images/devices/jorgegarcia-wifi-relays.jpg)|
|**EXS Wifi Relay v3.1**|**EXS Wifi Relay v5.0**|**Jorge García Wifi + Relays Board Kit**|
|![Allnet ESP8266-UP-Relay](images/devices/allnet-esp8266-up-relay.jpg)|![Bruno Horta's OnOfre](images/devices/bh-onofre.jpg)|![Luani HVIO](images/devices/luani-hvio.jpg)|
Expand Down Expand Up @@ -312,6 +328,8 @@ Here is the list of supported hardware. For more information please refer to the
|**Arilux AL-LC01 (RGB)**|**Arilux AL-LC02 (RGBW)**|**Arilux AL-LC06 (RGBWWCW)**|
|![Arilux AL-LC11 (RGBWWW) & RF](images/devices/arilux-al-lc11.jpg)|![MagicHome LED Controller (1.0 and 2.x)](images/devices/magichome-led-controller.jpg)|![Huacanxing H801/802](images/devices/huacanxing-h801.jpg)|
|**Arilux AL-LC11 (RGBWWW) & RF**|**MagicHome LED Controller (1.0/2.x, also ZJ WFMN A/B11)**|**Huacanxing H801/802**|
|![Muvit I/O MIOBULB001](images/devices/muvit-io-miobulb001.jpg)|
|**Muvit I/O MIOBULB001**|

### Radio links / gateways

Expand Down
3 changes: 2 additions & 1 deletion code/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ build_environments() {
mkdir -p $destination/espurna-$version

for environment in $environments; do
echo -n "* espurna-$version-$environment.bin --- "
echo "* espurna-$version-$environment.bin"
platformio run --silent --environment $environment || exit 1
echo -n "SIZE: "
stat_bytes .pio/build/$environment/firmware.bin
[[ "${TRAVIS_BUILD_STAGE_NAME}" = "Test" ]] || \
mv .pio/build/$environment/firmware.bin $destination/espurna-$version/espurna-$version-$environment.bin
Expand Down
22 changes: 13 additions & 9 deletions code/espurna/alexa.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>

#if ALEXA_SUPPORT

#include "relay.h"
#include "broker.h"

#include <fauxmoESP.h>
fauxmoESP alexa;

Expand Down Expand Up @@ -48,18 +51,19 @@ void _alexaConfigure() {
#endif

#if BROKER_SUPPORT
void _alexaBrokerCallback(const unsigned char type, const char * topic, unsigned char id, const char * payload) {
void _alexaBrokerCallback(const String& topic, unsigned char id, unsigned int value) {

// Only process status messages
if (BROKER_MSG_TYPE_STATUS != type) return;

unsigned char value = atoi(payload);
// Only process status messages for switches and channels
if (!topic.equals(MQTT_TOPIC_CHANNEL)
&& !topic.equals(MQTT_TOPIC_RELAY)) {
return;
}

if (strcmp(MQTT_TOPIC_CHANNEL, topic) == 0) {
alexa.setState(id+1, value > 0, value);
if (topic.equals(MQTT_TOPIC_CHANNEL)) {
alexa.setState(id + 1, value > 0, value);
}

if (strcmp(MQTT_TOPIC_RELAY, topic) == 0) {
if (topic.equals(MQTT_TOPIC_RELAY)) {
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT
if (id > 0) return;
#endif
Expand Down Expand Up @@ -146,7 +150,7 @@ void alexaSetup() {

// Register main callbacks
#if BROKER_SUPPORT
brokerRegister(_alexaBrokerCallback);
StatusBroker::Register(_alexaBrokerCallback);
#endif
espurnaRegisterReload(_alexaConfigure);
espurnaRegisterLoop(alexaLoop);
Expand Down
17 changes: 7 additions & 10 deletions code/espurna/api.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include <ArduinoJson.h>
#include <vector>

#include "system.h"

typedef struct {
char * key;
api_get_callback_f getFn = NULL;
Expand All @@ -28,7 +30,7 @@ bool _apiWebSocketOnKeyCheck(const char * key, JsonVariant& value) {

void _apiWebSocketOnConnected(JsonObject& root) {
root["apiEnabled"] = getSetting("apiEnabled", API_ENABLED).toInt() == 1;
root["apiKey"] = getSetting("apiKey");
root["apiKey"] = getSetting("apiKey", API_KEY);
root["apiRealTime"] = getSetting("apiRealTime", API_REAL_TIME_VALUES).toInt() == 1;
root["apiRestFul"] = getSetting("apiRestFul", API_RESTFUL).toInt() == 1;
}
Expand All @@ -43,21 +45,16 @@ void _apiConfigure() {

bool _authAPI(AsyncWebServerRequest *request) {

if (getSetting("apiEnabled", API_ENABLED).toInt() == 0) {
const String key = getSetting("apiKey", API_KEY);
if (!key.length() || getSetting("apiEnabled", API_ENABLED).toInt() == 0) {
DEBUG_MSG_P(PSTR("[WEBSERVER] HTTP API is not enabled\n"));
request->send(403);
return false;
}

if (!request->hasParam("apikey", (request->method() == HTTP_PUT))) {
DEBUG_MSG_P(PSTR("[WEBSERVER] Missing apikey parameter\n"));
request->send(403);
return false;
}

AsyncWebParameter* p = request->getParam("apikey", (request->method() == HTTP_PUT));
if (!p->value().equals(getSetting("apiKey"))) {
DEBUG_MSG_P(PSTR("[WEBSERVER] Wrong apikey parameter\n"));
if (!p || !p->value().equals(key)) {
DEBUG_MSG_P(PSTR("[WEBSERVER] Wrong / missing apikey parameter\n"));
request->send(403);
return false;
}
Expand Down
60 changes: 60 additions & 0 deletions code/espurna/broker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*

BROKER MODULE

Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>

*/

#if BROKER_SUPPORT

#pragma once

#include <functional>
#include <vector>
#include <utility>

enum class TBrokerType {
SYSTEM,
STATUS,
SENSOR_READ,
SENSOR_REPORT,
DATETIME,
CONFIG
};

template <typename... TArgs>
using TBrokerCallback = std::function<void(TArgs...)>;

template <typename... TArgs>
using TBrokerCallbacks = std::vector<TBrokerCallback<TArgs...>>;

template <TBrokerType type, typename... TArgs>
struct TBroker {
static TBrokerCallbacks<TArgs...> callbacks;

static void Register(TBrokerCallback<TArgs...> callback) {
callbacks.push_back(callback);
}
static void Publish(TArgs... args) {
for (auto& callback : callbacks) {
callback(args...);
}
}
};

template <TBrokerType type, typename... TArgs>
TBrokerCallbacks<TArgs...> TBroker<type, TArgs...>::callbacks;


// --- Some known types. Bind them here to avoid .ino screwing with order ---

using StatusBroker = TBroker<TBrokerType::STATUS, const String&, unsigned char, unsigned int>;

using SensorReadBroker = TBroker<TBrokerType::SENSOR_READ, const String&, unsigned char, double, const char*>;
using SensorReportBroker = TBroker<TBrokerType::SENSOR_REPORT, const String&, unsigned char, double, const char*>;

using TimeBroker = TBroker<TBrokerType::DATETIME, const String&, time_t, const String&>;
using ConfigBroker = TBroker<TBrokerType::CONFIG, const String&, const String&>;

#endif // BROKER_SUPPORT
32 changes: 0 additions & 32 deletions code/espurna/broker.ino

This file was deleted.

2 changes: 2 additions & 0 deletions code/espurna/button.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include <DebounceEvent.h>
#include <vector>

#include "system.h"
#include "relay.h"
#include "light.h"

typedef struct {
Expand Down
Loading