diff --git a/code/build-fs b/code/build-fs deleted file mode 100755 index d2ca4286..00000000 --- a/code/build-fs +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -node node_modules/gulp/bin/gulp.js diff --git a/code/build-all b/code/build.sh similarity index 100% rename from code/build-all rename to code/build.sh diff --git a/code/debug b/code/debug.sh similarity index 100% rename from code/debug rename to code/debug.sh diff --git a/code/deploy b/code/deploy deleted file mode 100755 index b98f1dec..00000000 --- a/code/deploy +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -# -# ESPurna Deploy Script -# -# Copyright (C) 2016 by Xose PĂ©rez -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# - -MQTT_HOST=192.168.1.10 - -function help() { - echo "Syntax: $0 " - devices -} - -function devices() { - echo "Defined devices:" - cat platformio.ini | grep 'device]' | sed 's/\[env:/ - /g' | sed 's/\-device]//g' -} - -function valid_ip() { - local stat=0 - rx='([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])' - if [[ $ip =~ ^$rx\.$rx\.$rx\.$rx$ ]]; then - stat=1 - fi - return $stat -} - -# Check arguments -if [ "$#" -ne 2 ]; then - help - exit 1 -fi -device=$1-device -target=$2 - -# Get IP -topic=`cat platformio.ini | grep $device -A 2 | grep "topic" | cut -d' ' -f3` -if [ "$topic" == "" ]; then - echo "Unknown device $device or topic not defined" - devices - exit 2 -fi - -ip=`mosquitto_sub -t $topic -h $MQTT_HOST -N -C 1` -if valid_ip $ip; then - echo "Could not get a valid IP from MQTT broker" - exit 3 -fi - -platformio run -vv -e $device --target $target --upload-port $ip diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index bd33db03..d439c378 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -44,44 +44,44 @@ int relayToIdx(unsigned int relayID) { return getSetting(buffer).toInt(); } -void domoticzSetup() { - - mqttRegister([](unsigned int type, const char * topic, const char * payload) { - - String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC); +void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) { - if (type == MQTT_CONNECT_EVENT) { - mqttSubscribeRaw(dczTopicOut.c_str()); - } + String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC); - if (type == MQTT_MESSAGE_EVENT) { + if (type == MQTT_CONNECT_EVENT) { + mqttSubscribeRaw(dczTopicOut.c_str()); + } - // Check topic - if (dczTopicOut.equals(topic)) { + if (type == MQTT_MESSAGE_EVENT) { - // Parse response - DynamicJsonBuffer jsonBuffer; - JsonObject& root = jsonBuffer.parseObject((char *) payload); - if (!root.success()) { - DEBUG_MSG_P(PSTR("[DOMOTICZ] Error parsing data\n")); - return; - } + // Check topic + if (dczTopicOut.equals(topic)) { - // IDX - unsigned long idx = root["idx"]; - int relayID = relayFromIdx(idx); - if (relayID >= 0) { - unsigned long value = root["nvalue"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx); - relayStatus(relayID, value == 1); - } + // Parse response + DynamicJsonBuffer jsonBuffer; + JsonObject& root = jsonBuffer.parseObject((char *) payload); + if (!root.success()) { + DEBUG_MSG_P(PSTR("[DOMOTICZ] Error parsing data\n")); + return; + } + // IDX + unsigned long idx = root["idx"]; + int relayID = relayFromIdx(idx); + if (relayID >= 0) { + unsigned long value = root["nvalue"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx); + relayStatus(relayID, value == 1); } } - }); -} + } + +}; +void domoticzSetup() { + mqttRegister(_domoticzMqtt); +} #endif