Minor changes to prep for rules

Change German day display to two character (#2403)
This commit is contained in:
Theo Arends 2018-04-11 10:11:20 +02:00
parent 7a9ee6b669
commit ee7227254f
25 changed files with 58 additions and 45 deletions

View File

@ -42,7 +42,7 @@
#define D_HOUR_MINUTE_SEPARATOR ":"
#define D_MINUTE_SECOND_SEPARATOR ":"
#define D_DAY3LIST "SonMonDieMitDonFriSam"
#define D_DAY3LIST "So Mo Di Mi Do Fr Sa "
#define D_MONTH3LIST "JanFebMärAprMaiJunJulAugSepOktNovDez"
// Non JSON decimal separator

View File

@ -258,7 +258,7 @@ struct SYSCFG {
byte free_6b8[72]; // 6B8
char rules[256]; // 700
char rules[MAX_RULE_SIZE]; // 700
// 800 - FFF free locations
} Settings;

View File

@ -48,6 +48,7 @@ typedef unsigned long power_t; // Power (Relay) type
#define MAX_FRIENDLYNAMES 4 // Max number of Friendly names
#define MAX_DOMOTICZ_IDX 4 // Max number of Domoticz device, key and switch indices
#define MAX_DOMOTICZ_SNS_IDX 12 // Max number of Domoticz sensors indices
#define MAX_RULE_SIZE 256 // Max number of characters in rules
#define MODULE SONOFF_BASIC // [Module] Select default model
@ -163,7 +164,9 @@ enum LichtSubtypes {LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LST_R
enum LichtSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX};
enum XsnsFunctions {FUNC_INIT, FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_SECOND, FUNC_PREP_BEFORE_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART,
FUNC_COMMAND, FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SHOW_SENSOR};
FUNC_COMMAND, FUNC_NTP_INIT, FUNC_NTP_SET,
FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_MQTT_DISCONNECTED, FUNC_MQTT_CONNECTED,
FUNC_SET_POWER, FUNC_SHOW_SENSOR};
const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 };

View File

@ -1376,6 +1376,12 @@ void RtcSecond()
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "(" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"),
GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str());
AddLog(LOG_LEVEL_DEBUG);
if (local_time < 1451602800) {
XdrvCall(FUNC_NTP_SET);
} else {
XdrvCall(FUNC_NTP_SET);
}
} else {
ntp_sync_minute++; // Try again in next minute
}

View File

@ -183,12 +183,10 @@ const char HTTP_BTN_RSTRT[] PROGMEM =
"<br/><form action='rb' method='get' onsubmit='return confirm(\"" D_CONFIRM_RESTART "\");'><button>" D_RESTART "</button></form>";
const char HTTP_BTN_MENU_MODULE[] PROGMEM =
"<br/><form action='md' method='get'><button>" D_CONFIGURE_MODULE "</button></form>";
#ifdef USE_TIMERS
#ifdef USE_TIMERS_WEB
#if defined(USE_TIMERS) && defined(USE_TIMERS_WEB)
const char HTTP_BTN_MENU_TIMER[] PROGMEM =
"<br/><form action='tm' method='get'><button>" D_CONFIGURE_TIMER "</button></form>";
#endif // USE_TIMERS_WEB
#endif // USE_TIMERS
#endif // USE_TIMERS and USE_TIMERS_WEB
const char HTTP_BTN_MENU_WIFI[] PROGMEM =
"<br/><form action='w0' method='get'><button>" D_CONFIGURE_WIFI "</button></form>";
const char HTTP_BTN_MENU_MQTT[] PROGMEM =
@ -340,11 +338,9 @@ void StartWebserver(int type, IPAddress ipweb)
WebServer->on("/", HandleRoot);
WebServer->on("/cn", HandleConfiguration);
WebServer->on("/md", HandleModuleConfiguration);
#ifdef USE_TIMERS
#ifdef USE_TIMERS_WEB
#if defined(USE_TIMERS) && defined(USE_TIMERS_WEB)
WebServer->on("/tm", HandleTimerConfiguration);
#endif // USE_TIMERS_WEB
#endif // USE_TIMERS
#endif // USE_TIMERS and USE_TIMERS_WEB
WebServer->on("/w1", HandleWifiConfigurationWithScan);
WebServer->on("/w0", HandleWifiConfiguration);
if (Settings.flag.mqtt_enabled) {
@ -632,11 +628,9 @@ void HandleConfiguration()
page.replace(F("{v}"), FPSTR(S_CONFIGURATION));
page += FPSTR(HTTP_HEAD_STYLE);
page += FPSTR(HTTP_BTN_MENU_MODULE);
#ifdef USE_TIMERS
#ifdef USE_TIMERS_WEB
#if defined(USE_TIMERS) && defined(USE_TIMERS_WEB)
if (devices_present) page += FPSTR(HTTP_BTN_MENU_TIMER);
#endif // USE_TIMERS_WEB
#endif // USE_TIMERS
#endif // USE_TIMERS and USE_TIMERS_WEB
page += FPSTR(HTTP_BTN_MENU_WIFI);
if (Settings.flag.mqtt_enabled) page += FPSTR(HTTP_BTN_MENU_MQTT);
page += FPSTR(HTTP_BTN_MENU4);
@ -1103,13 +1097,11 @@ void HandleSaveSettings()
Settings.seriallog_level, Settings.weblog_level, Settings.syslog_level, Settings.syslog_host, Settings.syslog_port, Settings.tele_period);
AddLog(LOG_LEVEL_INFO);
break;
#ifdef USE_TIMERS
#ifdef USE_TIMERS_WEB
#if defined(USE_TIMERS) && defined(USE_TIMERS_WEB)
case 7:
TimerSaveSettings();
break;
#endif // USE_TIMERS_WEB
#endif // USE_TIMERS
#endif // USE_TIMERS and USE_TIMERS_WEB
#ifdef USE_DOMOTICZ
case 4:
DomoticzSaveSettings();

View File

@ -316,6 +316,8 @@ void MqttDisconnected(int state)
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MQTT D_CONNECT_FAILED_TO " %s:%d, rc %d. " D_RETRY_IN " %d " D_UNIT_SECOND),
Settings.mqtt_host, Settings.mqtt_port, state, mqtt_retry_counter);
AddLog(LOG_LEVEL_INFO);
XdrvCall(FUNC_MQTT_DISCONNECTED);
}
void MqttConnected()
@ -371,6 +373,8 @@ void MqttConnected()
XdrvCall(FUNC_MQTT_INIT);
}
mqtt_initial_connection_state = 0;
XdrvCall(FUNC_MQTT_CONNECTED);
}
#ifdef USE_MQTT_TLS

View File

@ -105,7 +105,7 @@ void CounterShow(boolean json)
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_COUNTER "%d\":%s"), mqtt_data, i +1, counter);
#ifdef USE_DOMOTICZ
if (1 == dsxflg) {
if ((0 == tele_period) && (1 == dsxflg)) {
DomoticzSensor(DZ_COUNT, RtcSettings.pulse_counter[i]);
dsxflg++;
}

View File

@ -123,10 +123,12 @@ void SonoffScShow(boolean json)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"SonoffSC\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s,\"" D_JSON_LIGHT "\":%d,\"" D_JSON_NOISE "\":%d,\"" D_JSON_AIRQUALITY "\":%d}"),
mqtt_data, temperature, humidity, sc_value[2], sc_value[3], sc_value[4]);
#ifdef USE_DOMOTICZ
DomoticzTempHumSensor(temperature, humidity);
DomoticzSensor(DZ_ILLUMINANCE, sc_value[2]);
DomoticzSensor(DZ_COUNT, sc_value[3]);
DomoticzSensor(DZ_AIRQUALITY, 500 + ((100 - sc_value[4]) * 20));
if (0 == tele_period) {
DomoticzTempHumSensor(temperature, humidity);
DomoticzSensor(DZ_ILLUMINANCE, sc_value[2]);
DomoticzSensor(DZ_COUNT, sc_value[3]);
DomoticzSensor(DZ_AIRQUALITY, 500 + ((100 - sc_value[4]) * 20));
}
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -197,7 +197,7 @@ void Ds18b20Show(boolean json)
if(json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"DS18B20\":{\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, temperature);
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_TEMP, temperature);
if (0 == tele_period) DomoticzSensor(DZ_TEMP, temperature);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -380,7 +380,7 @@ void Ds18x20Show(boolean json)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_ID "\":\"%s\",\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, stemp, address, temperature);
}
#ifdef USE_DOMOTICZ
if (domoticz_flag) {
if ((0 == tele_period) && domoticz_flag) {
DomoticzSensor(DZ_TEMP, temperature);
domoticz_flag = false;
}

View File

@ -188,7 +188,7 @@ void Ds18x20Show(boolean json)
mqtt_data, stemp, i +1, ds18x20_types, Ds18x20Addresses(i).c_str(), temperature);
strcpy(stemp, ",");
#ifdef USE_DOMOTICZ
if (1 == dsxflg) {
if ((0 == tele_period) && (1 == dsxflg)) {
DomoticzSensor(DZ_TEMP, temperature);
}
#endif // USE_DOMOTICZ

View File

@ -226,7 +226,7 @@ void DhtShow(boolean json)
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, Dht[i].stype, temperature, humidity);
#ifdef USE_DOMOTICZ
if (!dsxflg) {
if ((0 == tele_period) && !dsxflg) {
DomoticzTempHumSensor(temperature, humidity);
dsxflg++;
}

View File

@ -199,7 +199,7 @@ void ShtShow(boolean json)
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, "SHT1X", temperature, humidity);
#ifdef USE_DOMOTICZ
DomoticzTempHumSensor(temperature, humidity);
if (0 == tele_period) DomoticzTempHumSensor(temperature, humidity);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -262,7 +262,7 @@ void HtuShow(boolean json)
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, htu_types, temperature, humidity);
#ifdef USE_DOMOTICZ
DomoticzTempHumSensor(temperature, humidity);
if (0 == tele_period) DomoticzTempHumSensor(temperature, humidity);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -465,7 +465,7 @@ void BmpShow(boolean json)
mqtt_data, bmp_name, temperature, (bmp_model >= 2) ? json_humidity : "", pressure, (Settings.altitude != 0) ? json_sealevel : "");
#endif // USE_BME680
#ifdef USE_DOMOTICZ
DomoticzTempHumPressureSensor(temperature, humidity, pressure);
if (0 == tele_period) DomoticzTempHumPressureSensor(temperature, humidity, pressure);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -77,7 +77,7 @@ void Bh1750Show(boolean json)
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"BH1750\":{\"" D_JSON_ILLUMINANCE "\":%d}"), mqtt_data, illuminance);
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_ILLUMINANCE, illuminance);
if (0 == tele_period) DomoticzSensor(DZ_ILLUMINANCE, illuminance);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -82,7 +82,7 @@ void Veml6070Show(boolean json)
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"VEML6070\":{\"" D_JSON_UV_LEVEL "\":%d}"), mqtt_data, uvlevel);
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_ILLUMINANCE, uvlevel);
if (0 == tele_period) DomoticzSensor(DZ_ILLUMINANCE, uvlevel);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -216,8 +216,10 @@ void Ina219Show(boolean json)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"INA219\":{\"" D_JSON_VOLTAGE "\":%s,\"" D_JSON_CURRENT "\":%s,\"" D_JSON_POWERUSAGE "\":%s}"),
mqtt_data, voltage, current, power);
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_VOLTAGE, voltage);
DomoticzSensor(DZ_CURRENT, current);
if (0 == tele_period) {
DomoticzSensor(DZ_VOLTAGE, voltage);
DomoticzSensor(DZ_CURRENT, current);
}
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -107,7 +107,7 @@ void Sht3xShow(boolean json)
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, types, temperature, humidity);
#ifdef USE_DOMOTICZ
if (0 == i) { // We want the same first sensor to report to Domoticz in case a read is missed
if ((0 == tele_period) && (0 == i)) { // We want the same first sensor to report to Domoticz in case a read is missed
DomoticzTempHumSensor(temperature, humidity);
}
#endif // USE_DOMOTICZ

View File

@ -265,7 +265,7 @@ void MhzShow(boolean json)
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_CO2 "\":%d,\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, mhz_types, mhz_last_ppm, temperature);
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_AIRQUALITY, mhz_last_ppm);
if (0 == tele_period) DomoticzSensor(DZ_AIRQUALITY, mhz_last_ppm);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -71,7 +71,7 @@ void Tsl2561Show(boolean json)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"TSL2561\":{\"" D_JSON_ILLUMINANCE "\":%u.%03u}"),
mqtt_data, milliLux/1000, milliLux%1000);
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_ILLUMINANCE, (milliLux+500)/1000);
if (0 == tele_period) DomoticzSensor(DZ_ILLUMINANCE, (milliLux+500)/1000);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -213,7 +213,7 @@ void SenseairShow(boolean json)
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_AIRQUALITY, senseair_co2);
if (0 == tele_period) DomoticzSensor(DZ_AIRQUALITY, senseair_co2);
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -131,9 +131,11 @@ void PmsShow(boolean json)
pms_data.pm10_env, pms_data.pm25_env, pms_data.pm100_env,
pms_data.particles_03um, pms_data.particles_05um, pms_data.particles_10um, pms_data.particles_25um, pms_data.particles_50um, pms_data.particles_100um);
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_COUNT, pms_data.pm10_env); // PM1
DomoticzSensor(DZ_VOLTAGE, pms_data.pm25_env); // PM2.5
DomoticzSensor(DZ_CURRENT, pms_data.pm100_env); // PM10
if (0 == tele_period) {
DomoticzSensor(DZ_COUNT, pms_data.pm10_env); // PM1
DomoticzSensor(DZ_VOLTAGE, pms_data.pm25_env); // PM2.5
DomoticzSensor(DZ_CURRENT, pms_data.pm100_env); // PM10
}
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -108,8 +108,10 @@ void NovaSdsShow(boolean json)
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"SDS0X1\":{\"PM2.5\":%s,\"PM10\":%s}"), mqtt_data, pm2_5, pm10);
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_VOLTAGE, pm2_5); // PM2.5
DomoticzSensor(DZ_CURRENT, pm10); // PM10
if (0 == tele_period) {
DomoticzSensor(DZ_VOLTAGE, pm2_5); // PM2.5
DomoticzSensor(DZ_CURRENT, pm10); // PM10
}
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {

View File

@ -74,7 +74,7 @@ void Sgp30Show(boolean json)
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"SGP30\":{\"" D_JSON_ECO2 "\":%d,\"" D_JSON_TVOC "\":%d}"), mqtt_data, sgp.eCO2, sgp.TVOC);
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_AIRQUALITY, sgp.eCO2);
if (0 == tele_period) DomoticzSensor(DZ_AIRQUALITY, sgp.eCO2);
#endif // USE_DOMOTICZ
} else {
#ifdef USE_WEBSERVER