Added KNX Communication Enhancement

Added option to enable KNX Communication Enhancement. If activated, will make the device send 3 times the same telegram drastically reducing the telegram lost.

This improves issue #78
This commit is contained in:
ascillato 2018-05-16 04:20:35 -03:00
parent 2a0cc518f6
commit 205481629c
18 changed files with 66 additions and 6 deletions

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Друго"
#define D_SENT_TO "изпратен до"
#define D_KNX_WARNING "Груповият адрес ( 0 / 0 / 0 ) е резервиран и не може да бъде използван."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Използвана енергия днес"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Jiné"
#define D_SENT_TO "pošli"
#define D_KNX_WARNING "Skupinová adresa ( 0 / 0 / 0 ) je rezervována a nemůže být použita."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Spotřeba Dnes"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Other"
#define D_SENT_TO "sent to"
#define D_KNX_WARNING "The group address ( 0 / 0 / 0 ) is reserved and can not be used."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Energie heute"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Αλλο"
#define D_SENT_TO "αποστολή σε"
#define D_KNX_WARNING "Η Ομάδα Διευθύνσεων ( 0 / 0 / 0 ) είναι δεσμευμένη και δεν μπορεί να χρησιμοποιηθεί."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Energy Σήμερα"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Other"
#define D_SENT_TO "sent to"
#define D_KNX_WARNING "The group address ( 0 / 0 / 0 ) is reserved and can not be used."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Energy Today"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Otro"
#define D_SENT_TO "enviada a"
#define D_KNX_WARNING "La dirección de grupo ( 0 / 0 / 0 ) está reservada y no puede ser utilizada."
#define D_KNX_ENHANCEMENT "Mejora de Comunicación"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Energía Hoy"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Autre"
#define D_SENT_TO "envoyé à"
#define D_KNX_WARNING "L'Adresse de Groupe ( 0 / 0 / 0 ) est réservée et ne peut être utilisée."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xsns_03_energy.ino
#define D_ENERGY_TODAY "Énergie aujourd'hui"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Other"
#define D_SENT_TO "sent to"
#define D_KNX_WARNING "The group address ( 0 / 0 / 0 ) is reserved and can not be used."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Mai Energia"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Altro"
#define D_SENT_TO "invia a"
#define D_KNX_WARNING "L'indirizzo del gruppo ( 0 / 0 / 0 ) è riservato e non può essere usato."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Energia Oggi"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Overige"
#define D_SENT_TO "verzend naar"
#define D_KNX_WARNING "Groep adres (0/0/0) is gereserveerd en mag niet worden gebruikt."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Verbruik vandaag"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Other"
#define D_SENT_TO "sent to"
#define D_KNX_WARNING "The group address ( 0 / 0 / 0 ) is reserved and can not be used."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Energia Dzisiaj"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Outros"
#define D_SENT_TO "Enviar para"
#define D_KNX_WARNING "O endereço ( 0 / 0 / 0 ) é reservado e não pode ser usado."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Consumo energético de hoje"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Other"
#define D_SENT_TO "sent to"
#define D_KNX_WARNING "The group address ( 0 / 0 / 0 ) is reserved and can not be used."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Consumo energético de hoje"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Other"
#define D_SENT_TO "sent to"
#define D_KNX_WARNING "The group address ( 0 / 0 / 0 ) is reserved and can not be used."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "Энергия Сегодня"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Other"
#define D_SENT_TO "sent to"
#define D_KNX_WARNING "The group address ( 0 / 0 / 0 ) is reserved and can not be used."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "今日用电量"

View File

@ -400,6 +400,7 @@
#define D_KNX_COMMAND_OTHER "Other"
#define D_SENT_TO "sent to"
#define D_KNX_WARNING "The group address ( 0 / 0 / 0 ) is reserved and can not be used."
#define D_KNX_ENHANCEMENT "Communication Enhancement"
// xdrv_03_energy.ino
#define D_ENERGY_TODAY "今日用電量"

View File

@ -52,7 +52,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t rules_once : 1; // bit 24 (v5.12.0k)
uint32_t knx_enabled : 1; // bit 25 (v5.12.0l) KNX
uint32_t device_index_enable : 1; // bit 26 (v5.13.1a)
uint32_t spare27 : 1;
uint32_t knx_enable_enhancement : 1; // bit 27 (v5.14.1b) KNX
uint32_t spare28 : 1;
uint32_t spare29 : 1;
uint32_t spare30 : 1;
@ -319,4 +319,4 @@ struct XDRVMAILBOX {
ADC_MODE(ADC_VCC); // Set ADC input for Power Supply Voltage usage
#endif
#endif // _SETTINGS_H_
#endif // _SETTINGS_H_

View File

@ -50,6 +50,8 @@ byte Settings.knx_CB_param[MAX_KNX_CB] Type of Output (set relay, t
#include <esp-knx-ip.h>
//#include <ESPAsyncUDP.h>
//void KNX_CB_Action(message_t const &msg, void *arg); // Define function (action callback) to be called by the KNX_IP Library
// when an action is requested by another KNX Device
@ -60,9 +62,11 @@ address_t KNX_addr; // KNX Address converter variable
#define KNX_TEMPERATURE 17
#define KNX_HUMIDITY 18
#define KNX_MAX_device_param 18
#define TOGGLE_INHIBIT_TIME 10 // 10*50mseg = 500mseg
float last_temp;
float last_hum;
byte toggle_inhibit;
typedef struct __device_parameters
{
@ -461,21 +465,38 @@ void KNX_CB_Action(message_t const &msg, void *arg)
}
else if (chan->type < 17) // Toggle Relays
{
ExecuteCommandPower((chan->type) -8, 2);
if (!toggle_inhibit) {
ExecuteCommandPower((chan->type) -8, 2);
if (Settings.flag.knx_enable_enhancement) {
toggle_inhibit = TOGGLE_INHIBIT_TIME;
}
}
}
break;
case KNX_CT_READ:
if (chan->type < 9) // reply Relays status
{
knx.answer_1bit(msg.received_on, chan->last_state);
if (Settings.flag.knx_enable_enhancement) {
knx.answer_1bit(msg.received_on, chan->last_state);
knx.answer_1bit(msg.received_on, chan->last_state);
}
}
else if (chan->type = KNX_TEMPERATURE) // Reply Temperature
{
knx.answer_2byte_float(msg.received_on, last_temp);
if (Settings.flag.knx_enable_enhancement) {
knx.answer_2byte_float(msg.received_on, last_temp);
knx.answer_2byte_float(msg.received_on, last_temp);
}
}
else if (chan->type = KNX_HUMIDITY) // Reply Humidity
{
knx.answer_2byte_float(msg.received_on, last_hum);
if (Settings.flag.knx_enable_enhancement) {
knx.answer_2byte_float(msg.received_on, last_hum);
knx.answer_2byte_float(msg.received_on, last_hum);
}
}
break;
}
@ -493,6 +514,10 @@ void KnxUpdatePowerState(byte device, power_t state)
while ( i != KNX_Empty ) {
KNX_addr.value = Settings.knx_GA_addr[i];
knx.write_1bit(KNX_addr, device_param[device -1].last_state);
if (Settings.flag.knx_enable_enhancement) {
knx.write_1bit(KNX_addr, device_param[device -1].last_state);
knx.write_1bit(KNX_addr, device_param[device -1].last_state);
}
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX "%s = %d " D_SENT_TO " %d.%d.%d"),
device_param_ga[device -1], device_param[device -1].last_state,
@ -522,6 +547,10 @@ void KnxSendButtonPower(byte key, byte device, byte state)
while ( i != KNX_Empty ) {
KNX_addr.value = Settings.knx_GA_addr[i];
knx.write_1bit(KNX_addr, !(state == 0));
if (Settings.flag.knx_enable_enhancement) {
knx.write_1bit(KNX_addr, !(state == 0));
knx.write_1bit(KNX_addr, !(state == 0));
}
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX "%s = %d " D_SENT_TO " %d.%d.%d"),
device_param_ga[device + 7], !(state == 0),
@ -550,6 +579,10 @@ void KnxSensor(byte sensor_type, float value)
while ( i != KNX_Empty ) {
KNX_addr.value = Settings.knx_GA_addr[i];
knx.write_2byte_float(KNX_addr, value);
if (Settings.flag.knx_enable_enhancement) {
knx.write_2byte_float(KNX_addr, value);
knx.write_2byte_float(KNX_addr, value);
}
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX "%s " D_SENT_TO " %d.%d.%d "),
device_param_ga[sensor_type -1],
@ -578,8 +611,11 @@ const char HTTP_FORM_KNX[] PROGMEM =
"<br/><br/>" D_KNX_PHYSICAL_ADDRESS_NOTE "<br/><br/>"
"<input style='width:10%;' id='b1' name='b1' type='checkbox'";
const char HTTP_FORM_KNX1[] PROGMEM =
"><b>" D_KNX_ENABLE " </b><input style='width:10%;' id='b2' name='b2' type='checkbox'";
const char HTTP_FORM_KNX2[] PROGMEM =
"><b>" D_KNX_ENABLE "</b><br/></center><br/>"
"><b>" D_KNX_ENHANCEMENT "</b><br/></center><br/>"
"<fieldset><center>"
"<b>" D_KNX_GROUP_ADDRESS_TO_WRITE "</b><hr>"
@ -696,6 +732,8 @@ void HandleKNXConfiguration()
page.replace(F("{knl"), String(KNX_physs_addr.pa.line));
page.replace(F("{knm"), String(KNX_physs_addr.pa.member));
if ( Settings.flag.knx_enabled ) { page += F(" checked"); }
page += FPSTR(HTTP_FORM_KNX1);
if ( Settings.flag.knx_enable_enhancement ) { page += F(" checked"); }
page += FPSTR(HTTP_FORM_KNX2);
for (byte i = 0; i < KNX_MAX_device_param ; i++)
@ -822,8 +860,9 @@ void KNX_Save_Settings()
address_t KNX_addr;
Settings.flag.knx_enabled = WebServer->hasArg("b1");
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX D_ENABLED ": %d "),
Settings.flag.knx_enabled);
Settings.flag.knx_enable_enhancement = WebServer->hasArg("b2");
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX D_ENABLED ": %d, " D_KNX_ENHANCEMENT ": %d"),
Settings.flag.knx_enabled, Settings.flag.knx_enable_enhancement );
AddLog(LOG_LEVEL_DEBUG);
stmp = WebServer->arg("area");
@ -883,6 +922,11 @@ boolean Xdrv11(byte function)
case FUNC_LOOP:
knx.loop(); // Process knx events
break;
case FUNC_EVERY_50_MSECOND:
if (toggle_inhibit) {
toggle_inhibit--;
}
break;
// case FUNC_COMMAND:
// result = KNXCommand();
// break;