Skip to content

Commit

Permalink
Fixed error in relay identification from MQTT messages (issue #31)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Jan 9, 2017
1 parent b263ad8 commit 9ce457f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion code/espurna/config/version.h
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 5 additions & 2 deletions code/espurna/led.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 5 additions & 2 deletions code/espurna/relay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 9ce457f

Please sign in to comment.