From 29c7e409eefe4ef4899ac997f2673b26bf86ee21 Mon Sep 17 00:00:00 2001
From: Adrian Scillato <35405447+ascillato@users.noreply.github.com>
Date: Sun, 22 Jul 2018 22:37:22 -0300
Subject: [PATCH 1/9] ESP-KNX-IP Library - Correct invalid keywords.txt
KEYWORD_TOKENTYPE
---
lib/esp-knx-ip-0.5.1/keywords.txt | 36 +++++++++++++++----------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/lib/esp-knx-ip-0.5.1/keywords.txt b/lib/esp-knx-ip-0.5.1/keywords.txt
index bc4989bd4..ec1f4c78c 100644
--- a/lib/esp-knx-ip-0.5.1/keywords.txt
+++ b/lib/esp-knx-ip-0.5.1/keywords.txt
@@ -1,14 +1,14 @@
# datatypes
-address_t DATA_TYPE
-message_t DATA_TYPE
-callback_id_t DATA_TYPE
-callback_assignment_id_t DATA_TYPE
-option_entry_t DATA_TYPE
-config_id_t DATA_TYPE
-enable_condition_t DATA_TYPE
-callback_fptr_t DATA_TYPE
-feedback_action_fptr_t DATA_TYPE
-knx_command_type_t DATA_TYPE
+address_t KEYWORD1 DATA_TYPE
+message_t KEYWORD1 DATA_TYPE
+callback_id_t KEYWORD1 DATA_TYPE
+callback_assignment_id_t KEYWORD1 DATA_TYPE
+option_entry_t KEYWORD1 DATA_TYPE
+config_id_t KEYWORD1 DATA_TYPE
+enable_condition_t KEYWORD1 DATA_TYPE
+callback_fptr_t KEYWORD1 DATA_TYPE
+feedback_action_fptr_t KEYWORD1 DATA_TYPE
+knx_command_type_t KEYWORD1 DATA_TYPE
# methods
setup KEYWORD2
@@ -92,13 +92,13 @@ answer_4byte_int KEYWORD2
answer_4byte_uint KEYWORD2
answer_4byte_float KEYWORD2
-data_to_1byte_int KEYWORD 2
-data_to_2byte_int KEYWORD 2
-data_to_2byte_float KEYWORD 2
-data_to_4byte_float KEYWORD 2
-data_to_3byte_color KEYWORD 2
-data_to_3byte_time KEYWORD 2
-data_to_3byte_data KEYWORD 2
+data_to_1byte_int KEYWORD2
+data_to_2byte_int KEYWORD2
+data_to_2byte_float KEYWORD2
+data_to_4byte_float KEYWORD2
+data_to_3byte_color KEYWORD2
+data_to_3byte_time KEYWORD2
+data_to_3byte_data KEYWORD2
# constants
-knx LITERAL1
\ No newline at end of file
+knx LITERAL1
From bc6195e4928bfaa881b817ab18a7389d859edcaa Mon Sep 17 00:00:00 2001
From: Adrian Scillato <35405447+ascillato@users.noreply.github.com>
Date: Sun, 22 Jul 2018 22:40:28 -0300
Subject: [PATCH 2/9] KNX: Added the EVENT knxrx_val1..5
Added the EVENT KNXRX_VAL1...5 when receiving values from the KNX Network or another Tasmota with KNX
Now, sensor values (for example) can be sent from one device to another.
---
sonoff/xdrv_11_knx.ino | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
diff --git a/sonoff/xdrv_11_knx.ino b/sonoff/xdrv_11_knx.ino
index 2162fbcaa..06cfa6171 100644
--- a/sonoff/xdrv_11_knx.ino
+++ b/sonoff/xdrv_11_knx.ino
@@ -517,14 +517,27 @@ void KNX_INIT()
void KNX_CB_Action(message_t const &msg, void *arg)
{
device_parameters_t *chan = (device_parameters_t *)arg;
-
if (!(Settings.flag.knx_enabled)) { return; }
- snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX D_RECEIVED_FROM " %d.%d.%d " D_COMMAND " %s: %d " D_TO " %s"),
- msg.received_on.ga.area, msg.received_on.ga.line, msg.received_on.ga.member,
- (msg.ct == KNX_CT_WRITE) ? D_KNX_COMMAND_WRITE : (msg.ct == KNX_CT_READ) ? D_KNX_COMMAND_READ : D_KNX_COMMAND_OTHER,
- msg.data[0],
- device_param_cb[(chan->type)-1]);
+ char tempchar[25];
+
+ if (msg.data_len == 1) {
+ // COMMAND
+ snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX D_RECEIVED_FROM " %d.%d.%d " D_COMMAND " %s: %d " D_TO " %s"),
+ msg.received_on.ga.area, msg.received_on.ga.line, msg.received_on.ga.member,
+ (msg.ct == KNX_CT_WRITE) ? D_KNX_COMMAND_WRITE : (msg.ct == KNX_CT_READ) ? D_KNX_COMMAND_READ : D_KNX_COMMAND_OTHER,
+ msg.data[0],
+ device_param_cb[(chan->type)-1]);
+ } else {
+ // VALUE
+ float tempvar = knx.data_to_2byte_float(msg.data);
+ dtostrfd(tempvar,2,tempchar);
+ snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX D_RECEIVED_FROM " %d.%d.%d " D_COMMAND " %s: %s " D_TO " %s"),
+ msg.received_on.ga.area, msg.received_on.ga.line, msg.received_on.ga.member,
+ (msg.ct == KNX_CT_WRITE) ? D_KNX_COMMAND_WRITE : (msg.ct == KNX_CT_READ) ? D_KNX_COMMAND_READ : D_KNX_COMMAND_OTHER,
+ tempchar,
+ device_param_cb[(chan->type)-1]);
+ }
AddLog(LOG_LEVEL_INFO);
switch (msg.ct)
@@ -548,7 +561,13 @@ void KNX_CB_Action(message_t const &msg, void *arg)
{
if (!toggle_inhibit) {
char command[25];
- snprintf_P(command, sizeof(command), PSTR("event KNXRX_CMND%d=%d"), ((chan->type) - KNX_SLOT1 + 1 ), msg.data[0]);
+ if (msg.data_len == 1) {
+ // Command received
+ snprintf_P(command, sizeof(command), PSTR("event KNXRX_CMND%d=%d"), ((chan->type) - KNX_SLOT1 + 1 ), msg.data[0]);
+ } else {
+ // Value received
+ snprintf_P(command, sizeof(command), PSTR("event KNXRX_VAL%d=%s"), ((chan->type) - KNX_SLOT1 + 1 ), tempchar);
+ }
ExecuteCommand(command, SRC_KNX);
if (Settings.flag.knx_enable_enhancement) {
toggle_inhibit = TOGGLE_INHIBIT_TIME;
From a6f27db9103dcac49267ddc311d55785e032942a Mon Sep 17 00:00:00 2001
From: Adrian Scillato <35405447+ascillato@users.noreply.github.com>
Date: Sun, 22 Jul 2018 23:14:33 -0300
Subject: [PATCH 3/9] Make KNX WEB MENU optional
---
sonoff/user_config.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/sonoff/user_config.h b/sonoff/user_config.h
index 6d80fff83..5ba122be4 100644
--- a/sonoff/user_config.h
+++ b/sonoff/user_config.h
@@ -238,6 +238,7 @@
// -- KNX IP Protocol -----------------------------
//#define USE_KNX // Enable KNX IP Protocol Support (+23k code, +3k3 mem)
+ #define USE_KNX_WEB_MENU // Enable KNX WEB MENU
// -- HTTP ----------------------------------------
#define USE_WEBSERVER // Enable web server and Wifi Manager (+66k code, +8k mem)
From 9c5d3f501d4cd065b3987eb5395e0a0cafdcbf2e Mon Sep 17 00:00:00 2001
From: Adrian Scillato <35405447+ascillato@users.noreply.github.com>
Date: Sun, 22 Jul 2018 23:16:05 -0300
Subject: [PATCH 4/9] Make KNX WEB MENU Optional
---
sonoff/xdrv_02_webserver.ino | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/sonoff/xdrv_02_webserver.ino b/sonoff/xdrv_02_webserver.ino
index 12ed741ac..8418f3ce9 100644
--- a/sonoff/xdrv_02_webserver.ino
+++ b/sonoff/xdrv_02_webserver.ino
@@ -204,7 +204,9 @@ const char HTTP_BTN_MENU_MQTT[] PROGMEM =
"";
const char HTTP_BTN_MENU4[] PROGMEM =
#ifdef USE_KNX
+#ifdef USE_KNX_WEB_MENU
"
"
+#endif // USE_KNX_WEB_MENU
#endif // USE_KNX
"
"
"
"
@@ -391,7 +393,9 @@ void StartWebserver(int type, IPAddress ipweb)
#endif // USE_DOMOTICZ
}
#ifdef USE_KNX
+#ifdef USE_KNX_WEB_MENU
WebServer->on("/kn", HandleKNXConfiguration);
+#endif // USE_KNX_WEB_MENU
#endif // USE_KNX
WebServer->on("/lg", HandleLoggingConfiguration);
WebServer->on("/co", HandleOtherConfiguration);
From 552ac7d5451c437ff19433a0be99b8e4984e1584 Mon Sep 17 00:00:00 2001
From: Adrian Scillato <35405447+ascillato@users.noreply.github.com>
Date: Sun, 22 Jul 2018 23:16:46 -0300
Subject: [PATCH 5/9] Make KNX WEB MENU Optional
---
sonoff/xdrv_11_knx.ino | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sonoff/xdrv_11_knx.ino b/sonoff/xdrv_11_knx.ino
index 06cfa6171..5aadbc6c0 100644
--- a/sonoff/xdrv_11_knx.ino
+++ b/sonoff/xdrv_11_knx.ino
@@ -716,6 +716,7 @@ void KnxSensor(byte sensor_type, float value)
\*********************************************************************************************/
#ifdef USE_WEBSERVER
+#ifdef USE_KNX_WEB_MENU
const char S_CONFIGURE_KNX[] PROGMEM = D_CONFIGURE_KNX;
const char HTTP_FORM_KNX[] PROGMEM =
@@ -1020,6 +1021,7 @@ void KNX_Save_Settings()
}
}
+#endif // USE_KNX_WEB_MENU
#endif // USE_WEBSERVER
From 99eb3362aa784b252326116e6cf963b5650b548b Mon Sep 17 00:00:00 2001
From: Adrian Scillato <35405447+ascillato@users.noreply.github.com>
Date: Mon, 23 Jul 2018 00:54:25 -0300
Subject: [PATCH 6/9] Make KNX WEB MENU optional
---
sonoff/user_config.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sonoff/user_config.h b/sonoff/user_config.h
index 5ba122be4..173ed8684 100644
--- a/sonoff/user_config.h
+++ b/sonoff/user_config.h
@@ -237,8 +237,8 @@
//#define USE_MQTT_TLS // Use TLS for MQTT connection (+53k code, +15k mem)
// -- KNX IP Protocol -----------------------------
-//#define USE_KNX // Enable KNX IP Protocol Support (+23k code, +3k3 mem)
- #define USE_KNX_WEB_MENU // Enable KNX WEB MENU
+//#define USE_KNX // Enable KNX IP Protocol Support (+9.4k code, +3k7 mem)
+ #define USE_KNX_WEB_MENU // Enable KNX WEB MENU (+8.3k code, +144 mem)
// -- HTTP ----------------------------------------
#define USE_WEBSERVER // Enable web server and Wifi Manager (+66k code, +8k mem)
From 77181854a7bfd33897809cbc4a7efebdafa64071 Mon Sep 17 00:00:00 2001
From: Adrian Scillato <35405447+ascillato@users.noreply.github.com>
Date: Mon, 23 Jul 2018 01:01:52 -0300
Subject: [PATCH 7/9] Added KNX commands
* KNX_ENABLED 0/1
* KNX_ENHANCED 0/1
---
sonoff/xdrv_11_knx.ino | 55 +++++++++++++++++++++++++++++++++++-------
1 file changed, 46 insertions(+), 9 deletions(-)
diff --git a/sonoff/xdrv_11_knx.ino b/sonoff/xdrv_11_knx.ino
index 5aadbc6c0..35fa559ad 100644
--- a/sonoff/xdrv_11_knx.ino
+++ b/sonoff/xdrv_11_knx.ino
@@ -196,8 +196,10 @@ const char *device_param_cb[] = {
// Commands
#define D_CMND_KNXTXCMND "KnxTx_Cmnd"
#define D_CMND_KNXTXVAL "KnxTx_Val"
-enum KnxCommands { CMND_KNXTXCMND, CMND_KNXTXVAL };
-const char kKnxCommands[] PROGMEM = D_CMND_KNXTXCMND "|" D_CMND_KNXTXVAL ;
+#define D_CMND_KNX_ENABLED "Knx_Enabled"
+#define D_CMND_KNX_ENHANCED "Knx_Enhanced"
+enum KnxCommands { CMND_KNXTXCMND, CMND_KNXTXVAL, CMND_KNX_ENABLED, CMND_KNX_ENHANCED } ;
+const char kKnxCommands[] PROGMEM = D_CMND_KNXTXCMND "|" D_CMND_KNXTXVAL "|" D_CMND_KNX_ENABLED "|" D_CMND_KNX_ENHANCED ;
byte KNX_GA_Search( byte param, byte start = 0 )
@@ -1031,14 +1033,12 @@ boolean KnxCommand()
uint8_t index = XdrvMailbox.index;
int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic, kKnxCommands);
- if (!(Settings.flag.knx_enabled)) { return false; }
-
if (-1 == command_code) { return false; } // Unknown command
else if ((CMND_KNXTXCMND == command_code) && (index > 0) && (index <= MAX_KNXTX_CMNDS) && (XdrvMailbox.data_len > 0)) {
// index <- KNX SLOT to use
// XdrvMailbox.payload <- data to send
-
+ if (!(Settings.flag.knx_enabled)) { return false; }
// Search all the registered GA that has that output (variable: KNX SLOTx) as parameter
byte i = KNX_GA_Search(index + KNX_SLOT1 -1);
while ( i != KNX_Empty ) {
@@ -1056,12 +1056,14 @@ boolean KnxCommand()
i = KNX_GA_Search(index + KNX_SLOT1 -1, i + 1);
}
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s%d\":\"%s\"}"),
+ command, index, XdrvMailbox.data );
}
else if ((CMND_KNXTXVAL == command_code) && (index > 0) && (index <= MAX_KNXTX_CMNDS) && (XdrvMailbox.data_len > 0)) {
// index <- KNX SLOT to use
// XdrvMailbox.payload <- data to send
-
+ if (!(Settings.flag.knx_enabled)) { return false; }
// Search all the registered GA that has that output (variable: KNX SLOTx) as parameter
byte i = KNX_GA_Search(index + KNX_SLOT1 -1);
while ( i != KNX_Empty ) {
@@ -1083,13 +1085,48 @@ boolean KnxCommand()
i = KNX_GA_Search(index + KNX_SLOT1 -1, i + 1);
}
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s%d\":\"%s\"}"),
+ command, index, XdrvMailbox.data );
+ }
+
+ else if (CMND_KNX_ENABLED == command_code) {
+ if (!XdrvMailbox.data_len) {
+ if (Settings.flag.knx_enabled) {
+ snprintf_P(XdrvMailbox.data, sizeof(XdrvMailbox.data), PSTR("1"));
+ } else {
+ snprintf_P(XdrvMailbox.data, sizeof(XdrvMailbox.data), PSTR("0"));
+ }
+ } else {
+ if (XdrvMailbox.payload == 1) {
+ Settings.flag.knx_enabled = 1;
+ } else if (XdrvMailbox.payload == 0) {
+ Settings.flag.knx_enabled = 0;
+ } else { return false; } // Incomplete command
+ }
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%s\"}"),
+ command, XdrvMailbox.data );
+ }
+
+ else if (CMND_KNX_ENHANCED == command_code) {
+ if (!XdrvMailbox.data_len) {
+ if (Settings.flag.knx_enable_enhancement) {
+ snprintf_P(XdrvMailbox.data, sizeof(XdrvMailbox.data), PSTR("1"));
+ } else {
+ snprintf_P(XdrvMailbox.data, sizeof(XdrvMailbox.data), PSTR("0"));
+ }
+ } else {
+ if (XdrvMailbox.payload == 1) {
+ Settings.flag.knx_enable_enhancement = 1;
+ } else if (XdrvMailbox.payload == 0) {
+ Settings.flag.knx_enable_enhancement = 0;
+ } else { return false; } // Incomplete command
+ }
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%s\"}"),
+ command, XdrvMailbox.data );
}
else { return false; } // Incomplete command
- snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s%d\":\"%s\"}"),
- command, index, XdrvMailbox.data );
-
return true;
}
From a294a9179dd8bb03d89cccdbda455ef0f736eb4f Mon Sep 17 00:00:00 2001
From: Adrian Scillato <35405447+ascillato@users.noreply.github.com>
Date: Mon, 23 Jul 2018 02:15:44 -0300
Subject: [PATCH 8/9] Added Command KNX_PA
Added Command KNX_PA for changing the device KNX Physical Address
---
sonoff/xdrv_11_knx.ino | 34 +++++++++++++++++++++++++++++++---
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/sonoff/xdrv_11_knx.ino b/sonoff/xdrv_11_knx.ino
index 35fa559ad..5016393c8 100644
--- a/sonoff/xdrv_11_knx.ino
+++ b/sonoff/xdrv_11_knx.ino
@@ -198,9 +198,10 @@ const char *device_param_cb[] = {
#define D_CMND_KNXTXVAL "KnxTx_Val"
#define D_CMND_KNX_ENABLED "Knx_Enabled"
#define D_CMND_KNX_ENHANCED "Knx_Enhanced"
-enum KnxCommands { CMND_KNXTXCMND, CMND_KNXTXVAL, CMND_KNX_ENABLED, CMND_KNX_ENHANCED } ;
-const char kKnxCommands[] PROGMEM = D_CMND_KNXTXCMND "|" D_CMND_KNXTXVAL "|" D_CMND_KNX_ENABLED "|" D_CMND_KNX_ENHANCED ;
-
+#define D_CMND_KNX_PA "Knx_PA"
+enum KnxCommands { CMND_KNXTXCMND, CMND_KNXTXVAL, CMND_KNX_ENABLED, CMND_KNX_ENHANCED, CMND_KNX_PA } ;
+const char kKnxCommands[] PROGMEM = D_CMND_KNXTXCMND "|" D_CMND_KNXTXVAL "|" D_CMND_KNX_ENABLED "|"
+ D_CMND_KNX_ENHANCED "|" D_CMND_KNX_PA ;
byte KNX_GA_Search( byte param, byte start = 0 )
{
@@ -1125,6 +1126,33 @@ boolean KnxCommand()
command, XdrvMailbox.data );
}
+ else if (CMND_KNX_PA == command_code) {
+ if (XdrvMailbox.data_len) {
+ if (strstr(XdrvMailbox.data, ".")) { // Process parameter entry
+ char sub_string[XdrvMailbox.data_len +1];
+
+ int pa_area = atoi(subStr(sub_string, XdrvMailbox.data, ".", 1));
+ int pa_line = atoi(subStr(sub_string, XdrvMailbox.data, ".", 2));
+ int pa_member = atoi(subStr(sub_string, XdrvMailbox.data, ".", 3));
+
+ if ( ((pa_area == 0) && (pa_line == 0) && (pa_member == 0))
+ || (pa_area > 15) || (pa_line > 15) || (pa_member > 255) ) {
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"" D_ERROR "\"}"),
+ command );
+ return true;
+ } // Invalid command
+
+ KNX_addr.pa.area = pa_area;
+ KNX_addr.pa.line = pa_line;
+ KNX_addr.pa.member = pa_member;
+ Settings.knx_physsical_addr = KNX_addr.value;
+ }
+ }
+ KNX_addr.value = Settings.knx_physsical_addr;
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%d.%d.%d\"}"),
+ command, KNX_addr.pa.area, KNX_addr.pa.line, KNX_addr.pa.member );
+ }
+
else { return false; } // Incomplete command
return true;
From 3373fff9eb40d6a367ceb6eba216b3bf6eb9ec7c Mon Sep 17 00:00:00 2001
From: Adrian Scillato <35405447+ascillato@users.noreply.github.com>
Date: Mon, 23 Jul 2018 04:03:57 -0300
Subject: [PATCH 9/9] Added Commands KNX_GA and KNX_CB
* Added command KNX_GA so as to setup Group Address to Send Data/Commands
Usage:
KNX_GA
(return the amount of GA configured)
KNX_GA 1
(return the configuration of the GA#1
KNX_GAx option, area, line, member
(Set the configuration of the GA#x)
example: KNX_GA3 1, 2,2,4
For the GA#3, the status of Relay 1 is sent to 2.2.4
* Added command KNX_CB so as to setup Group Address to Receive Data/Commands
KNX_CBx option, area, line, member
example: KNX_CB2 1, 2,2,4
For the CB#2, listen to 2.2.4 to set the status of the Relay 1
Posible values of the parameter OPTION:
1 - Relay 1
2 - Relay 2
3 - Relay 3
4 - Relay 4
5 - Relay 5
6 - Relay 6
7 - Relay 7
8 - Relay 8
9 - Button 1
10 - Button 2
11 - Button 3
12 - Button 4
13 - Button 5
14 - Button 6
15 - Button 7
16 - Button 8
17 - TEMPERATURE
18 - HUMIDITY
19 - ENERGY_VOLTAGE
20 - ENERGY_CURRENT
21 - ENERGY_POWER
22 - ENERGY_POWERFACTOR
23 - ENERGY_DAILY
24 - ENERGY_START
25 - ENERGY_TOTAL
26 - KNX_SLOT1
27 - KNX_SLOT2
28 - KNX_SLOT3
29 - KNX_SLOT4
30 - KNX_SLOT5
255 - EMPTY
---
sonoff/xdrv_11_knx.ino | 105 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 103 insertions(+), 2 deletions(-)
diff --git a/sonoff/xdrv_11_knx.ino b/sonoff/xdrv_11_knx.ino
index 5016393c8..710b63f66 100644
--- a/sonoff/xdrv_11_knx.ino
+++ b/sonoff/xdrv_11_knx.ino
@@ -199,9 +199,12 @@ const char *device_param_cb[] = {
#define D_CMND_KNX_ENABLED "Knx_Enabled"
#define D_CMND_KNX_ENHANCED "Knx_Enhanced"
#define D_CMND_KNX_PA "Knx_PA"
-enum KnxCommands { CMND_KNXTXCMND, CMND_KNXTXVAL, CMND_KNX_ENABLED, CMND_KNX_ENHANCED, CMND_KNX_PA } ;
+#define D_CMND_KNX_GA "Knx_GA"
+#define D_CMND_KNX_CB "Knx_CB"
+enum KnxCommands { CMND_KNXTXCMND, CMND_KNXTXVAL, CMND_KNX_ENABLED, CMND_KNX_ENHANCED, CMND_KNX_PA,
+ CMND_KNX_GA, CMND_KNX_CB } ;
const char kKnxCommands[] PROGMEM = D_CMND_KNXTXCMND "|" D_CMND_KNXTXVAL "|" D_CMND_KNX_ENABLED "|"
- D_CMND_KNX_ENHANCED "|" D_CMND_KNX_PA ;
+ D_CMND_KNX_ENHANCED "|" D_CMND_KNX_PA "|" D_CMND_KNX_GA "|" D_CMND_KNX_CB ;
byte KNX_GA_Search( byte param, byte start = 0 )
{
@@ -1153,6 +1156,104 @@ boolean KnxCommand()
command, KNX_addr.pa.area, KNX_addr.pa.line, KNX_addr.pa.member );
}
+ else if ((CMND_KNX_GA == command_code) && (index > 0) && (index <= MAX_KNX_GA)) {
+ if (XdrvMailbox.data_len) {
+ if (strstr(XdrvMailbox.data, ",")) { // Process parameter entry
+ char sub_string[XdrvMailbox.data_len +1];
+
+ int ga_option = atoi(subStr(sub_string, XdrvMailbox.data, ",", 1));
+ int ga_area = atoi(subStr(sub_string, XdrvMailbox.data, ",", 2));
+ int ga_line = atoi(subStr(sub_string, XdrvMailbox.data, ",", 3));
+ int ga_member = atoi(subStr(sub_string, XdrvMailbox.data, ",", 4));
+
+ if ( ((ga_area == 0) && (ga_line == 0) && (ga_member == 0))
+ || (ga_area > 31) || (ga_line > 7) || (ga_member > 255)
+ || (ga_option < 0) || ((ga_option > KNX_MAX_device_param ) && (ga_option != KNX_Empty))
+ || (!device_param[ga_option-1].show) ) {
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"" D_ERROR "\"}"), command );
+ return true;
+ } // Invalid command
+
+ KNX_addr.ga.area = ga_area;
+ KNX_addr.ga.line = ga_line;
+ KNX_addr.ga.member = ga_member;
+
+ if ( index > Settings.knx_GA_registered ) {
+ Settings.knx_GA_registered ++;
+ index = Settings.knx_GA_registered;
+ }
+
+ Settings.knx_GA_addr[index -1] = KNX_addr.value;
+ Settings.knx_GA_param[index -1] = ga_option;
+ } else {
+ if ( (XdrvMailbox.payload <= Settings.knx_GA_registered) && (XdrvMailbox.payload > 0) ) {
+ index = XdrvMailbox.payload;
+ } else {
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"" D_ERROR "\"}"), command );
+ return true;
+ }
+ }
+ if ( index <= Settings.knx_GA_registered ) {
+ KNX_addr.value = Settings.knx_GA_addr[index -1];
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s%d\":\"%s, %d/%d/%d\"}"),
+ command, index, device_param_ga[Settings.knx_GA_param[index-1]-1],
+ KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member );
+ }
+ } else {
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%d\"}"),
+ command, Settings.knx_GA_registered );
+ }
+ }
+
+ else if ((CMND_KNX_CB == command_code) && (index > 0) && (index <= MAX_KNX_CB)) {
+ if (XdrvMailbox.data_len) {
+ if (strstr(XdrvMailbox.data, ",")) { // Process parameter entry
+ char sub_string[XdrvMailbox.data_len +1];
+
+ int cb_option = atoi(subStr(sub_string, XdrvMailbox.data, ",", 1));
+ int cb_area = atoi(subStr(sub_string, XdrvMailbox.data, ",", 2));
+ int cb_line = atoi(subStr(sub_string, XdrvMailbox.data, ",", 3));
+ int cb_member = atoi(subStr(sub_string, XdrvMailbox.data, ",", 4));
+
+ if ( ((cb_area == 0) && (cb_line == 0) && (cb_member == 0))
+ || (cb_area > 31) || (cb_line > 7) || (cb_member > 255)
+ || (cb_option < 0) || ((cb_option > KNX_MAX_device_param ) && (cb_option != KNX_Empty))
+ || (!device_param[cb_option-1].show) ) {
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"" D_ERROR "\"}"), command );
+ return true;
+ } // Invalid command
+
+ KNX_addr.ga.area = cb_area;
+ KNX_addr.ga.line = cb_line;
+ KNX_addr.ga.member = cb_member;
+
+ if ( index > Settings.knx_CB_registered ) {
+ Settings.knx_CB_registered ++;
+ index = Settings.knx_CB_registered;
+ }
+
+ Settings.knx_CB_addr[index -1] = KNX_addr.value;
+ Settings.knx_CB_param[index -1] = cb_option;
+ } else {
+ if ( (XdrvMailbox.payload <= Settings.knx_CB_registered) && (XdrvMailbox.payload > 0) ) {
+ index = XdrvMailbox.payload;
+ } else {
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"" D_ERROR "\"}"), command );
+ return true;
+ }
+ }
+ if ( index <= Settings.knx_CB_registered ) {
+ KNX_addr.value = Settings.knx_CB_addr[index -1];
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s%d\":\"%s, %d/%d/%d\"}"),
+ command, index, device_param_cb[Settings.knx_CB_param[index-1]-1],
+ KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member );
+ }
+ } else {
+ snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%d\"}"),
+ command, Settings.knx_CB_registered );
+ }
+ }
+
else { return false; } // Incomplete command
return true;