From 9ce457fa86239f5c5c4d8f8647ad4c6076853753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 9 Jan 2017 01:04:15 +0100 Subject: [PATCH] Fixed error in relay identification from MQTT messages (issue #31) --- CHANGELOG.md | 4 ++++ README.md | 2 +- code/espurna/config/version.h | 2 +- code/espurna/led.ino | 7 +++++-- code/espurna/relay.ino | 7 +++++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18ba618c..b41f4a4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.4.2] 2017-01-09 +### Fixed +- Fixed error in relay identification from MQTT messages (issue #31) + ## [1.4.1] 2017-01-05 ### Added - Alexa support by default on all devices diff --git a/README.md b/README.md index 60b21213..4a9031c3 100644 --- a/README.md +++ b/README.md @@ -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.4.1**, read the [changelog](CHANGELOG.md). +**Current Release Version is 1.4.2**, read the [changelog](CHANGELOG.md). ## Features diff --git a/code/espurna/config/version.h b/code/espurna/config/version.h index a92cea79..448d7a24 100644 --- a/code/espurna/config/version.h +++ b/code/espurna/config/version.h @@ -1,4 +1,4 @@ #define APP_NAME "ESPurna" -#define APP_VERSION "1.4.1" +#define APP_VERSION "1.4.2" #define APP_AUTHOR "xose.perez@gmail.com" #define APP_WEBSITE "http://tinkerman.cat" diff --git a/code/espurna/led.ino b/code/espurna/led.ino index 0038d699..24d14ed8 100644 --- a/code/espurna/led.ino +++ b/code/espurna/led.ino @@ -79,8 +79,11 @@ void ledMQTTCallback(unsigned int type, const char * topic, const char * payload if (!t.endsWith(mqttSetter)) return; // Get led ID - unsigned int ledID = topic[strlen(MQTT_LED_TOPIC)+1] - '0'; - if (ledID >= ledCount()) ledID = 0; + unsigned int ledID = topic[strlen(topic) - mqttSetter.length() - 1] - '0'; + if (ledID >= ledCount()) { + DEBUG_MSG("[LED] Wrong ledID (%d)\n", ledID); + return; + } // get value unsigned int value = (char)payload[0] - '0'; diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index d7c7693d..ebe4d2ed 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -203,8 +203,11 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo if (!t.endsWith(mqttSetter)) return; // Get relay ID - unsigned int relayID = topic[strlen(MQTT_RELAY_TOPIC)+1] - '0'; - if (relayID >= relayCount()) relayID = 0; + unsigned int relayID = topic[strlen(topic) - mqttSetter.length() - 1] - '0'; + if (relayID >= relayCount()) { + DEBUG_MSG("[RELAY] Wrong relayID (%d)\n", relayID); + return; + } // Action to perform unsigned int value = (char)payload[0] - '0';