5.7.1d
 * Fix watchdog timeout caused by lack of stack space by now
using global buffers (#853)
 * Removed webserver syslog disable as now
no longer needed
 * Increased default MQTT message size from 368 to 405
bytes while keeping DMQTT_MAX_PACKET_SIZE = 512 (because we can)
 * Fix
MQTT Offline or Remove MQTT retained topic code
 * Allow command
SwitchTopic in group mode (#861)
 * Allow command SwitchMode if no
switches are defined (#861)
This commit is contained in:
arendst 2017-09-13 14:19:34 +02:00
parent 616b16d08d
commit c16fd3d99e
23 changed files with 574 additions and 642 deletions

View File

@ -1,7 +1,7 @@
## Sonoff-Tasmota
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.
Current version is **5.7.1c** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
Current version is **5.7.1d** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
### ATTENTION All versions

View File

@ -58,7 +58,7 @@ platform = espressif8266
framework = arduino
board = esp01_1m
board_flash_mode = dout
build_flags = -Wl,-Tesp8266.flash.1m0.ld -DMQTT_MAX_PACKET_SIZE=758 -DUSE_DS18x20 -DMESSZ=600
build_flags = -Wl,-Tesp8266.flash.1m0.ld -DMQTT_MAX_PACKET_SIZE=707 -DUSE_DS18x20 -DMESSZ=600
lib_deps = PubSubClient, NeoPixelBus, IRremoteESP8266, ArduinoJSON, OneWire
; Serial Monitor options

View File

@ -1,4 +1,12 @@
/* 5.7.1c
/* 5.7.1d
* Fix watchdog timeout caused by lack of stack space by now using global buffers (#853)
* Removed webserver syslog disable as now no longer needed
* Increased default MQTT message size from 368 to 405 bytes while keeping DMQTT_MAX_PACKET_SIZE = 512 (because we can)
* Fix MQTT Offline or Remove MQTT retained topic code
* Allow command SwitchTopic in group mode (#861)
* Allow command SwitchMode if no switches are defined (#861)
*
* 5.7.1c
* Allow LogPort and MqttPort up to 65535 and add LogPort tot Status 3 (#859)
*
* 5.7.1b

View File

@ -82,7 +82,6 @@ void RTC_Dump()
{
#define CFG_COLS 16
char log[LOGSZ];
uint16_t idx;
uint16_t maxrow;
uint16_t row;
@ -93,22 +92,22 @@ void RTC_Dump()
for (row = 0; row < maxrow; row++) {
idx = row * CFG_COLS;
snprintf_P(log, sizeof(log), PSTR("%04X:"), idx);
snprintf_P(log_data, sizeof(log_data), PSTR("%04X:"), idx);
for (col = 0; col < CFG_COLS; col++) {
if (!(col%4)) {
snprintf_P(log, sizeof(log), PSTR("%s "), log);
snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
}
snprintf_P(log, sizeof(log), PSTR("%s %02X"), log, buffer[idx + col]);
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[idx + col]);
}
snprintf_P(log, sizeof(log), PSTR("%s |"), log);
snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data);
for (col = 0; col < CFG_COLS; col++) {
// if (!(col%4)) {
// snprintf_P(log, sizeof(log), PSTR("%s "), log);
// snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
// }
snprintf_P(log, sizeof(log), PSTR("%s%c"), log, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
}
snprintf_P(log, sizeof(log), PSTR("%s|"), log);
addLog(LOG_LEVEL_INFO, log);
snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
addLog(LOG_LEVEL_INFO);
}
}
#endif // DEBUG_THEO
@ -193,8 +192,6 @@ void CFG_Save(byte rotate)
* stop_flash_rotate 0 = Allow flash slot rotation (SetOption12 0)
* stop_flash_rotate 1 = Allow only eeprom flash slot use (SetOption12 1)
*/
char log[LOGSZ];
#ifndef BE_MINIMAL
if ((getHash() != _cfgHash) || rotate) {
if (1 == rotate) { // Use eeprom flash slot only and disable flash rotate from now on (upgrade)
@ -224,9 +221,9 @@ void CFG_Save(byte rotate)
delay(1);
}
}
snprintf_P(log, sizeof(log), PSTR(D_LOG_CONFIG D_SAVED_TO_FLASH_AT " %X, " D_COUNT " %d, " D_BYTES " %d"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_CONFIG D_SAVED_TO_FLASH_AT " %X, " D_COUNT " %d, " D_BYTES " %d"),
_cfgLocation, sysCfg.saveFlag, sizeof(SYSCFG));
addLog(LOG_LEVEL_DEBUG, log);
addLog(LOG_LEVEL_DEBUG);
_cfgHash = getHash();
}
#endif // BE_MINIMAL
@ -237,8 +234,6 @@ void CFG_Load()
{
/* Load configuration from eeprom or one of 7 slots below if first load does not stop_flash_rotate
*/
char log[LOGSZ];
struct SYSCFGH {
unsigned long cfg_holder;
unsigned long saveFlag;
@ -252,17 +247,17 @@ void CFG_Load()
spi_flash_read((_cfgLocation -1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
interrupts();
// snprintf_P(log, sizeof(log), PSTR("Cnfg: Check at %X with count %d and holder %X"), _cfgLocation -1, _sysCfgH.saveFlag, _sysCfgH.cfg_holder);
// addLog(LOG_LEVEL_DEBUG, log);
// snprintf_P(log_data, sizeof(log_data), PSTR("Cnfg: Check at %X with count %d and holder %X"), _cfgLocation -1, _sysCfgH.saveFlag, _sysCfgH.cfg_holder);
// addLog(LOG_LEVEL_DEBUG);
if (((sysCfg.version > 0x05000200) && sysCfg.flag.stop_flash_rotate) || (sysCfg.cfg_holder != _sysCfgH.cfg_holder) || (sysCfg.saveFlag > _sysCfgH.saveFlag)) {
break;
}
delay(1);
}
snprintf_P(log, sizeof(log), PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %d"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %d"),
_cfgLocation, sysCfg.saveFlag);
addLog(LOG_LEVEL_DEBUG, log);
addLog(LOG_LEVEL_DEBUG);
if (sysCfg.cfg_holder != CFG_HOLDER) {
// Auto upgrade
noInterrupts();
@ -283,15 +278,14 @@ void CFG_Load()
void CFG_Erase()
{
char log[LOGSZ];
SpiFlashOpResult result;
uint32_t _sectorStart = (ESP.getSketchSize() / SPI_FLASH_SEC_SIZE) + 1;
uint32_t _sectorEnd = ESP.getFlashChipRealSize() / SPI_FLASH_SEC_SIZE;
boolean _serialoutput = (LOG_LEVEL_DEBUG_MORE <= seriallog_level);
snprintf_P(log, sizeof(log), PSTR(D_LOG_APPLICATION D_ERASE " %d " D_UNIT_SECTORS), _sectorEnd - _sectorStart);
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_ERASE " %d " D_UNIT_SECTORS), _sectorEnd - _sectorStart);
addLog(LOG_LEVEL_DEBUG);
for (uint32_t _sector = _sectorStart; _sector < _sectorEnd; _sector++) {
noInterrupts();
@ -314,7 +308,6 @@ void CFG_Dump(char* parms)
{
#define CFG_COLS 16
char log[LOGSZ];
uint16_t idx;
uint16_t maxrow;
uint16_t row;
@ -327,8 +320,8 @@ void CFG_Dump(char* parms)
uint16_t srow = strtol(parms, &p, 16) / CFG_COLS;
uint16_t mrow = strtol(p, &p, 10);
// snprintf_P(log, sizeof(log), PSTR("Cnfg: Parms %s, Start row %d, rows %d"), parms, srow, mrow);
// addLog(LOG_LEVEL_DEBUG, log);
// snprintf_P(log_data, sizeof(log_data), PSTR("Cnfg: Parms %s, Start row %d, rows %d"), parms, srow, mrow);
// addLog(LOG_LEVEL_DEBUG);
if (0 == mrow) { // Default only 8 lines
mrow = 8;
@ -342,22 +335,22 @@ void CFG_Dump(char* parms)
for (row = srow; row < maxrow; row++) {
idx = row * CFG_COLS;
snprintf_P(log, sizeof(log), PSTR("%04X:"), idx);
snprintf_P(log_data, sizeof(log_data), PSTR("%04X:"), idx);
for (col = 0; col < CFG_COLS; col++) {
if (!(col%4)) {
snprintf_P(log, sizeof(log), PSTR("%s "), log);
snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
}
snprintf_P(log, sizeof(log), PSTR("%s %02X"), log, buffer[idx + col]);
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[idx + col]);
}
snprintf_P(log, sizeof(log), PSTR("%s |"), log);
snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data);
for (col = 0; col < CFG_COLS; col++) {
// if (!(col%4)) {
// snprintf_P(log, sizeof(log), PSTR("%s "), log);
// snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
// }
snprintf_P(log, sizeof(log), PSTR("%s%c"), log, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
}
snprintf_P(log, sizeof(log), PSTR("%s|"), log);
addLog(LOG_LEVEL_INFO, log);
snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
addLog(LOG_LEVEL_INFO);
delay(1);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -38,9 +38,8 @@ void osw_osWatch()
unsigned long last_run = abs(t - osw_last_loop);
#ifdef DEBUG_THEO
char log[LOGSZ];
snprintf_P(log, sizeof(log), PSTR(D_LOG_APPLICATION D_OSWATCH " FreeRam %d, rssi %d, last_run %d"), ESP.getFreeHeap(), WIFI_getRSSIasQuality(WiFi.RSSI()), last_run);
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_OSWATCH " FreeRam %d, rssi %d, last_run %d"), ESP.getFreeHeap(), WIFI_getRSSIasQuality(WiFi.RSSI()), last_run);
addLog(LOG_LEVEL_DEBUG);
#endif // DEBUG_THEO
if (last_run >= (OSWATCH_RESET_TIME * 1000)) {
addLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_OSWATCH " " D_BLOCKED_LOOP ". " D_RESTARTING));
@ -372,8 +371,6 @@ void WIFI_wps_status_cb(wps_cb_status status);
void WIFI_wps_status_cb(wps_cb_status status)
{
char log[LOGSZ];
/* from user_interface.h:
enum wps_cb_status {
WPS_CB_ST_SUCCESS = 0,
@ -383,13 +380,12 @@ void WIFI_wps_status_cb(wps_cb_status status)
WPS_CB_ST_SCAN_ERR, // can not find the target WPS AP
};
*/
_wpsresult = status;
if (WPS_CB_ST_SUCCESS == _wpsresult) {
wifi_wps_disable();
} else {
snprintf_P(log, sizeof(log), PSTR(D_LOG_WIFI D_WPS_FAILED_WITH_STATUS " %d"), _wpsresult);
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_WPS_FAILED_WITH_STATUS " %d"), _wpsresult);
addLog(LOG_LEVEL_DEBUG);
_wifiConfigCounter = 2;
}
}
@ -458,7 +454,6 @@ void WIFI_config(uint8_t type)
void WIFI_begin(uint8_t flag)
{
const char PhyMode[] = " BGN";
char log[LOGSZ];
#ifdef USE_EMULATION
UDP_Disconnect();
@ -495,9 +490,9 @@ void WIFI_begin(uint8_t flag)
}
WiFi.hostname(Hostname);
WiFi.begin(sysCfg.sta_ssid[sysCfg.sta_active], sysCfg.sta_pwd[sysCfg.sta_active]);
snprintf_P(log, sizeof(log), PSTR(D_LOG_WIFI D_CONNECTING_TO_AP "%d %s " D_IN_MODE " 11%c " D_AS " %s..."),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_CONNECTING_TO_AP "%d %s " D_IN_MODE " 11%c " D_AS " %s..."),
sysCfg.sta_active +1, sysCfg.sta_ssid[sysCfg.sta_active], PhyMode[WiFi.getPhyMode() & 0x3], Hostname);
addLog(LOG_LEVEL_INFO, log);
addLog(LOG_LEVEL_INFO);
}
void WIFI_check_ip()
@ -565,8 +560,6 @@ void WIFI_check_ip()
void WIFI_Check(uint8_t param)
{
char log[LOGSZ];
_wificounter--;
switch (param) {
case WIFI_SMARTCONFIG:
@ -593,8 +586,8 @@ void WIFI_Check(uint8_t param)
strlcpy(sysCfg.sta_pwd[0], WiFi.psk().c_str(), sizeof(sysCfg.sta_pwd[0]));
}
sysCfg.sta_active = 0;
snprintf_P(log, sizeof(log), PSTR(D_LOG_WIFI D_WCFG_1_SMARTCONFIG D_CMND_SSID "1 %s, " D_CMND_PASSWORD "1 %s"), sysCfg.sta_ssid[0], sysCfg.sta_pwd[0]);
addLog(LOG_LEVEL_INFO, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_WCFG_1_SMARTCONFIG D_CMND_SSID "1 %s, " D_CMND_PASSWORD "1 %s"), sysCfg.sta_ssid[0], sysCfg.sta_pwd[0]);
addLog(LOG_LEVEL_INFO);
}
}
if (!_wifiConfigCounter) {
@ -613,8 +606,8 @@ void WIFI_Check(uint8_t param)
#ifdef USE_DISCOVERY
if (!mDNSbegun) {
mDNSbegun = MDNS.begin(Hostname);
snprintf_P(log, sizeof(log), PSTR(D_LOG_MDNS "%s"), (mDNSbegun) ? D_INITIALIZED : D_FAILED);
addLog(LOG_LEVEL_INFO, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS "%s"), (mDNSbegun) ? D_INITIALIZED : D_FAILED);
addLog(LOG_LEVEL_INFO);
}
#endif // USE_DISCOVERY
#ifdef USE_WEBSERVER
@ -673,7 +666,6 @@ void WIFI_Connect()
#ifdef MQTT_HOST_DISCOVERY
boolean mdns_discoverMQTTServer()
{
char log[LOGSZ];
char ip_str[20];
int n;
@ -683,16 +675,16 @@ boolean mdns_discoverMQTTServer()
n = MDNS.queryService("mqtt", "tcp"); // Search for mqtt service
snprintf_P(log, sizeof(log), PSTR(D_LOG_MDNS D_QUERY_DONE " %d"), n);
addLog(LOG_LEVEL_INFO, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS D_QUERY_DONE " %d"), n);
addLog(LOG_LEVEL_INFO);
if (n > 0) {
// Note: current strategy is to get the first MQTT service (even when many are found)
IPtoCharArray(MDNS.IP(0), ip_str, 20);
snprintf_P(log, sizeof(log), PSTR(D_LOG_MDNS D_MQTT_SERVICE_FOUND " %s, " D_IP_ADDRESS " %s, " D_PORT " %d"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS D_MQTT_SERVICE_FOUND " %s, " D_IP_ADDRESS " %s, " D_PORT " %d"),
MDNS.hostname(0).c_str(), ip_str, MDNS.port(0));
addLog(LOG_LEVEL_INFO, log);
addLog(LOG_LEVEL_INFO);
strlcpy(sysCfg.mqtt_host, ip_str, sizeof(sysCfg.mqtt_host));
sysCfg.mqtt_port = MDNS.port(0);
@ -794,7 +786,7 @@ void i2c_scan(char *devs, unsigned int devs_len)
byte any = 0;
char tstr[10];
snprintf_P(devs, devs_len, PSTR("{\"" D_CMND_I2CSCAN "\":\"" D_I2CSCAN_DEVICES_FOUND_AT));
snprintf_P(devs, devs_len, PSTR("{\"I2Cscan\":\"Device(s) found at"));
for (address = 1; address <= 127; address++) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
@ -804,13 +796,13 @@ void i2c_scan(char *devs, unsigned int devs_len)
any = 1;
}
else if (4 == error) {
snprintf_P(devs, devs_len, PSTR("{\"" D_CMND_I2CSCAN "\":\"" D_I2CSCAN_UNKNOWN_ERROR_AT " 0x%2x\"}"), address);
snprintf_P(devs, devs_len, PSTR("{\"I2Cscan\":\"Unknown error at 0x%2x\"}"), address);
}
}
if (any) {
strncat(devs, "\"}", devs_len);
} else {
snprintf_P(devs, devs_len, PSTR("{\"" D_CMND_I2CSCAN "\":\"" D_I2CSCAN_NO_DEVICES_FOUND "\"}"));
snprintf_P(devs, devs_len, PSTR("{\"I2Cscan\":\"No devices found\"}"));
}
}
#endif // USE_I2C
@ -1027,7 +1019,7 @@ String rtc_time(int type)
if (1 == type) time = loctime;
if (2 == type) time = dsttime;
if (3 == type) time = stdtime;
snprintf_P(stime, sizeof(stime), PSTR("%s"), sntp_get_real_time(time));
snprintf_P(stime, sizeof(stime), sntp_get_real_time(time));
return String(stime);
}
@ -1052,7 +1044,6 @@ boolean rtc_midnight_now()
void rtc_second()
{
char log[LOGSZ];
byte ntpsync;
uint32_t stdoffset;
uint32_t dstoffset;
@ -1076,12 +1067,12 @@ void rtc_second()
rtcTime.Year = tmpTime.Year + 1970;
dsttime = toTime_t(myDST, rtcTime.Year);
stdtime = toTime_t(mySTD, rtcTime.Year);
snprintf_P(log, sizeof(log), PSTR(D_LOG_APPLICATION "(" D_UTC_TIME ") %s"), rtc_time(0).c_str());
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log, sizeof(log), PSTR(D_LOG_APPLICATION "(" D_DST_TIME ") %s"), rtc_time(2).c_str());
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log, sizeof(log), PSTR(D_LOG_APPLICATION "(" D_STD_TIME ") %s"), rtc_time(3).c_str());
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "(" D_UTC_TIME ") %s"), rtc_time(0).c_str());
addLog(LOG_LEVEL_DEBUG);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "(" D_DST_TIME ") %s"), rtc_time(2).c_str());
addLog(LOG_LEVEL_DEBUG);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "(" D_STD_TIME ") %s"), rtc_time(3).c_str());
addLog(LOG_LEVEL_DEBUG);
}
}
utctime++;
@ -1153,32 +1144,32 @@ uint16_t getAdc0()
* Syslog
\*********************************************************************************************/
void syslog(const char *message)
void syslog()
{
char str[TOPSZ + MESSZ];
if (portUDP.beginPacket(sysCfg.syslog_host, sysCfg.syslog_port)) {
snprintf_P(str, sizeof(str), PSTR("%s ESP-%s"), Hostname, message);
snprintf_P(str, sizeof(str), PSTR("%s ESP-%s"), Hostname, log_data);
portUDP.write(str);
portUDP.endPacket();
} else {
syslog_level = 0;
syslog_timer = SYSLOG_TIMER;
snprintf_P(str, sizeof(str), PSTR(D_LOG_APPLICATION D_SYSLOG_HOST_NOT_FOUND ". " D_RETRY_IN " %d " D_UNIT_SECOND), SYSLOG_TIMER);
addLog(LOG_LEVEL_INFO, str);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_SYSLOG_HOST_NOT_FOUND ". " D_RETRY_IN " %d " D_UNIT_SECOND), SYSLOG_TIMER);
addLog(LOG_LEVEL_INFO);
}
}
void addLog(byte loglevel, const char *line)
void addLog(byte loglevel)
{
char mxtime[9];
char mxtime[9]; // 13:45:21
snprintf_P(mxtime, sizeof(mxtime), PSTR("%02d" D_HOUR_MINUTE_SEPARATOR "%02d" D_MINUTE_SECOND_SEPARATOR "%02d"), rtcTime.Hour, rtcTime.Minute, rtcTime.Second);
if (loglevel <= seriallog_level) Serial.printf("%s %s\n", mxtime, line);
if (loglevel <= seriallog_level) Serial.printf("%s %s\n", mxtime, log_data);
#ifdef USE_WEBSERVER
if (sysCfg.webserver && (loglevel <= sysCfg.weblog_level)) {
Log[logidx] = String(mxtime) + " " + String(line);
Log[logidx] = String(mxtime) + " " + String(log_data);
logidx++;
if (logidx > MAX_LOG_LINES -1) {
logidx = 0;
@ -1186,27 +1177,24 @@ void addLog(byte loglevel, const char *line)
}
#endif // USE_WEBSERVER
if ((WL_CONNECTED == WiFi.status()) && (loglevel <= syslog_level)) {
syslog(line);
syslog();
}
}
void addLog_P(byte loglevel, const char *formatP)
{
char mess[LOGSZ]; // was MESSZ
snprintf_P(mess, sizeof(mess), formatP);
addLog(loglevel, mess);
snprintf_P(log_data, sizeof(log_data), formatP);
addLog(loglevel);
}
void addLog_P(byte loglevel, const char *formatP, const char *formatP2)
{
char mess[LOGSZ]; // was MESSZ
char mes2[LOGSZ];
char mes2[100];
snprintf_P(mess, sizeof(mess), formatP);
snprintf_P(log_data, sizeof(log_data), formatP);
snprintf_P(mes2, sizeof(mes2), formatP2);
strncat(mess, mes2, sizeof(mess));
addLog(loglevel, mess);
strncat(log_data, mes2, sizeof(log_data));
addLog(loglevel);
}
/*********************************************************************************************\

View File

@ -297,8 +297,6 @@ uint8_t _colcount;
void startWebserver(int type, IPAddress ipweb)
{
char log[LOGSZ];
if (!_httpflag) {
if (!webServer) {
webServer = new ESP8266WebServer((HTTP_MANAGER==type)?80:WEB_PORT);
@ -345,9 +343,9 @@ void startWebserver(int type, IPAddress ipweb)
webServer->begin(); // Web server start
}
if (_httpflag != type) {
snprintf_P(log, sizeof(log), PSTR(D_LOG_HTTP D_WEBSERVER_ACTIVE_ON " %s%s " D_WITH_IP_ADDRESS " %s"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_HTTP D_WEBSERVER_ACTIVE_ON " %s%s " D_WITH_IP_ADDRESS " %s"),
Hostname, (mDNSbegun) ? ".local" : "", ipweb.toString().c_str());
addLog(LOG_LEVEL_INFO, log);
addLog(LOG_LEVEL_INFO);
}
if (type) _httpflag = type;
}
@ -715,7 +713,6 @@ void handleWifi(boolean scan)
if (httpUser()) {
return;
}
char log[LOGSZ];
addLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_WIFI);
@ -759,8 +756,8 @@ void handleWifi(boolean scan)
cssid = WiFi.SSID(indices[i]);
for (int j = i + 1; j < n; j++) {
if (cssid == WiFi.SSID(indices[j])) {
snprintf_P(log, sizeof(log), PSTR(D_LOG_WIFI D_DUPLICATE_ACCESSPOINT " %s"), WiFi.SSID(indices[j]).c_str());
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_DUPLICATE_ACCESSPOINT " %s"), WiFi.SSID(indices[j]).c_str());
addLog(LOG_LEVEL_DEBUG);
indices[j] = -1; // set dup aps to index -1
}
}
@ -772,8 +769,8 @@ void handleWifi(boolean scan)
if (-1 == indices[i]) {
continue; // skip dups
}
snprintf_P(log, sizeof(log), PSTR(D_LOG_WIFI D_SSID " %s, " D_RSSI " %d"), WiFi.SSID(indices[i]).c_str(), WiFi.RSSI(indices[i]));
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_SSID " %s, " D_RSSI " %d"), WiFi.SSID(indices[i]).c_str(), WiFi.RSSI(indices[i]));
addLog(LOG_LEVEL_DEBUG);
int quality = WIFI_getRSSIasQuality(WiFi.RSSI(indices[i]));
if (_minimumQuality == -1 || _minimumQuality < quality) {
@ -960,7 +957,6 @@ void handleSave()
return;
}
char log[LOGSZ +20];
char stemp[TOPSZ];
char stemp2[TOPSZ];
byte what = 0;
@ -982,9 +978,9 @@ void handleSave()
strlcpy(sysCfg.sta_pwd[0], (!strlen(webServer->arg("p1").c_str())) ? STA_PASS1 : webServer->arg("p1").c_str(), sizeof(sysCfg.sta_pwd[0]));
strlcpy(sysCfg.sta_ssid[1], (!strlen(webServer->arg("s2").c_str())) ? STA_SSID2 : webServer->arg("s2").c_str(), sizeof(sysCfg.sta_ssid[1]));
strlcpy(sysCfg.sta_pwd[1], (!strlen(webServer->arg("p2").c_str())) ? STA_PASS2 : webServer->arg("p2").c_str(), sizeof(sysCfg.sta_pwd[1]));
snprintf_P(log, sizeof(log), PSTR(D_LOG_WIFI D_CMND_HOSTNAME " %s, " D_CMND_SSID "1 %s, " D_CMND_PASSWORD "1 %s, " D_CMND_SSID "2 %s, " D_CMND_PASSWORD "2 %s"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_CMND_HOSTNAME " %s, " D_CMND_SSID "1 %s, " D_CMND_PASSWORD "1 %s, " D_CMND_SSID "2 %s, " D_CMND_PASSWORD "2 %s"),
sysCfg.hostname, sysCfg.sta_ssid[0], sysCfg.sta_pwd[0], sysCfg.sta_ssid[1], sysCfg.sta_pwd[1]);
addLog(LOG_LEVEL_INFO, log);
addLog(LOG_LEVEL_INFO);
result += F("<br/>" D_TRYING_TO_CONNECT "<br/>");
break;
case 2:
@ -993,7 +989,8 @@ void handleSave()
strlcpy(stemp2, (!strlen(webServer->arg("mf").c_str())) ? MQTT_FULLTOPIC : webServer->arg("mf").c_str(), sizeof(stemp2));
mqttfy(1,stemp2);
if ((strcmp(stemp, sysCfg.mqtt_topic)) || (strcmp(stemp2, sysCfg.mqtt_fulltopic))) {
mqtt_publish_topic_P(2, S_LWT, (sysCfg.flag.mqtt_offline) ? S_OFFLINE : "", true); // Offline or remove previous retained topic
snprintf_P(mqtt_data, sizeof(mqtt_data), (sysCfg.flag.mqtt_offline) ? S_OFFLINE : "");
mqtt_publish_topic_P(2, S_LWT, true); // Offline or remove previous retained topic
}
strlcpy(sysCfg.mqtt_topic, stemp, sizeof(sysCfg.mqtt_topic));
strlcpy(sysCfg.mqtt_fulltopic, stemp2, sizeof(sysCfg.mqtt_fulltopic));
@ -1002,9 +999,9 @@ void handleSave()
strlcpy(sysCfg.mqtt_client, (!strlen(webServer->arg("mc").c_str())) ? MQTT_CLIENT_ID : webServer->arg("mc").c_str(), sizeof(sysCfg.mqtt_client));
strlcpy(sysCfg.mqtt_user, (!strlen(webServer->arg("mu").c_str())) ? MQTT_USER : (!strcmp(webServer->arg("mu").c_str(),"0")) ? "" : webServer->arg("mu").c_str(), sizeof(sysCfg.mqtt_user));
strlcpy(sysCfg.mqtt_pwd, (!strlen(webServer->arg("mp").c_str())) ? MQTT_PASS : (!strcmp(webServer->arg("mp").c_str(),"0")) ? "" : webServer->arg("mp").c_str(), sizeof(sysCfg.mqtt_pwd));
snprintf_P(log, sizeof(log), PSTR(D_LOG_MQTT D_CMND_MQTTHOST " %s, " D_CMND_MQTTPORT " %d, " D_CMND_MQTTCLIENT " %s, " D_CMND_MQTTUSER " %s, " D_CMND_MQTTPASSWORD " %s, " D_CMND_TOPIC " %s, " D_CMND_FULLTOPIC " %s"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MQTT D_CMND_MQTTHOST " %s, " D_CMND_MQTTPORT " %d, " D_CMND_MQTTCLIENT " %s, " D_CMND_MQTTUSER " %s, " D_CMND_MQTTPASSWORD " %s, " D_CMND_TOPIC " %s, " D_CMND_FULLTOPIC " %s"),
sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.mqtt_client, sysCfg.mqtt_user, sysCfg.mqtt_pwd, sysCfg.mqtt_topic, sysCfg.mqtt_fulltopic);
addLog(LOG_LEVEL_INFO, log);
addLog(LOG_LEVEL_INFO);
break;
case 3:
sysCfg.seriallog_level = (!strlen(webServer->arg("ls").c_str())) ? SERIAL_LOG_LEVEL : atoi(webServer->arg("ls").c_str());
@ -1015,9 +1012,9 @@ void handleSave()
strlcpy(sysCfg.syslog_host, (!strlen(webServer->arg("lh").c_str())) ? SYS_LOG_HOST : webServer->arg("lh").c_str(), sizeof(sysCfg.syslog_host));
sysCfg.syslog_port = (!strlen(webServer->arg("lp").c_str())) ? SYS_LOG_PORT : atoi(webServer->arg("lp").c_str());
sysCfg.tele_period = (!strlen(webServer->arg("lt").c_str())) ? TELE_PERIOD : atoi(webServer->arg("lt").c_str());
snprintf_P(log, sizeof(log), PSTR(D_LOG_LOG D_CMND_SERIALLOG " %d, " D_CMND_WEBLOG " %d, " D_CMND_SYSLOG " %d, " D_CMND_LOGHOST " %s, " D_CMND_LOGPORT " %d, " D_CMND_TELEPERIOD " %d"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_LOG D_CMND_SERIALLOG " %d, " D_CMND_WEBLOG " %d, " D_CMND_SYSLOG " %d, " D_CMND_LOGHOST " %s, " D_CMND_LOGPORT " %d, " D_CMND_TELEPERIOD " %d"),
sysCfg.seriallog_level, sysCfg.weblog_level, sysCfg.syslog_level, sysCfg.syslog_host, sysCfg.syslog_port, sysCfg.tele_period);
addLog(LOG_LEVEL_INFO, log);
addLog(LOG_LEVEL_INFO);
break;
#ifdef USE_DOMOTICZ
case 4:
@ -1034,9 +1031,9 @@ void handleSave()
strlcpy(sysCfg.friendlyname[1], (!strlen(webServer->arg("a2").c_str())) ? FRIENDLY_NAME"2" : webServer->arg("a2").c_str(), sizeof(sysCfg.friendlyname[1]));
strlcpy(sysCfg.friendlyname[2], (!strlen(webServer->arg("a3").c_str())) ? FRIENDLY_NAME"3" : webServer->arg("a3").c_str(), sizeof(sysCfg.friendlyname[2]));
strlcpy(sysCfg.friendlyname[3], (!strlen(webServer->arg("a4").c_str())) ? FRIENDLY_NAME"4" : webServer->arg("a4").c_str(), sizeof(sysCfg.friendlyname[3]));
snprintf_P(log, sizeof(log), PSTR(D_LOG_OTHER D_MQTT_ENABLE " %s, " D_CMND_EMULATION " %d, " D_CMND_FRIENDLYNAME " %s, %s, %s, %s"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_OTHER D_MQTT_ENABLE " %s, " D_CMND_EMULATION " %d, " D_CMND_FRIENDLYNAME " %s, %s, %s, %s"),
getStateText(sysCfg.flag.mqtt_enabled), sysCfg.flag.emulation, sysCfg.friendlyname[0], sysCfg.friendlyname[1], sysCfg.friendlyname[2], sysCfg.friendlyname[3]);
addLog(LOG_LEVEL_INFO, log);
addLog(LOG_LEVEL_INFO);
break;
case 6:
byte new_module = (!strlen(webServer->arg("g99").c_str())) ? MODULE : atoi(webServer->arg("g99").c_str());
@ -1056,8 +1053,8 @@ void handleSave()
}
}
snprintf_P(stemp, sizeof(stemp), modules[sysCfg.module].name);
snprintf_P(log, sizeof(log), PSTR(D_LOG_MODULE "%s " D_CMND_MODULE "%s"), stemp, gpios.c_str());
addLog(LOG_LEVEL_INFO, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MODULE "%s " D_CMND_MODULE "%s"), stemp, gpios.c_str());
addLog(LOG_LEVEL_INFO);
break;
}
@ -1176,7 +1173,6 @@ void handleUploadDone()
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_UPLOAD_DONE));
char error[100];
char log[LOGSZ];
WIFI_configCounter();
restartflag = 0;
@ -1201,8 +1197,8 @@ void handleUploadDone()
snprintf_P(error, sizeof(error), PSTR(D_UPLOAD_ERROR_CODE " %d"), _uploaderror);
}
page += error;
snprintf_P(log, sizeof(log), PSTR(D_UPLOAD ": %s"), error);
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_UPLOAD ": %s"), error);
addLog(LOG_LEVEL_DEBUG);
stop_flash_rotate = sysCfg.flag.stop_flash_rotate;
} else {
page += F("green'>" D_SUCCESSFUL "</font></b><br/>");
@ -1217,7 +1213,6 @@ void handleUploadDone()
void handleUploadLoop()
{
// Based on ESP8266HTTPUpdateServer.cpp uses ESP8266WebServer Parsing.cpp and Cores Updater.cpp (Update)
char log[LOGSZ];
boolean _serialoutput = (LOG_LEVEL_DEBUG <= seriallog_level);
if (HTTP_USER == _httpflag) {
@ -1239,8 +1234,8 @@ void handleUploadLoop()
return;
}
CFG_Save(1); // Free flash for upload
snprintf_P(log, sizeof(log), PSTR(D_LOG_UPLOAD D_FILE " %s ..."), upload.filename.c_str());
addLog(LOG_LEVEL_INFO, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD D_FILE " %s ..."), upload.filename.c_str());
addLog(LOG_LEVEL_INFO);
if (!_uploadfiletype) {
mqttcounter = 60;
#ifdef USE_EMULATION
@ -1319,8 +1314,8 @@ void handleUploadLoop()
}
}
if (!_uploaderror) {
snprintf_P(log, sizeof(log), PSTR(D_LOG_UPLOAD D_SUCCESSFUL " %u bytes. " D_RESTARTING), upload.totalSize);
addLog(LOG_LEVEL_INFO, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD D_SUCCESSFUL " %u bytes. " D_RESTARTING), upload.totalSize);
addLog(LOG_LEVEL_INFO);
}
} else if (UPLOAD_FILE_ABORTED == upload.status) {
restartflag = 0;
@ -1353,12 +1348,11 @@ void handleCmnd()
if (valid) {
byte curridx = logidx;
if (strlen(webServer->arg("cmnd").c_str())) {
// snprintf_P(svalue, sizeof(svalue), webServer->arg("cmnd").c_str());
snprintf_P(svalue, sizeof(svalue), PSTR("%s"), webServer->arg("cmnd").c_str());
byte syslog_now = syslog_level;
syslog_level = 0; // Disable UDP syslog to not trigger hardware WDT
snprintf_P(svalue, sizeof(svalue), webServer->arg("cmnd").c_str());
// byte syslog_now = syslog_level;
// syslog_level = 0; // Disable UDP syslog to not trigger hardware WDT - Seems to work fine since 5.7.1d (global logging)
do_cmnd(svalue);
syslog_level = syslog_now;
// syslog_level = syslog_now;
}
if (logidx != curridx) {
@ -1413,19 +1407,18 @@ void handleAjax()
if (httpUser()) {
return;
}
char log[LOGSZ];
char svalue[INPUT_BUFFER_SIZE]; // big to serve Backlog
byte cflg = 1;
byte counter = 99;
if (strlen(webServer->arg("c1").c_str())) {
snprintf_P(svalue, sizeof(svalue), PSTR("%s"), webServer->arg("c1").c_str());
snprintf_P(log, sizeof(log), PSTR(D_LOG_COMMAND "%s"), svalue);
addLog(LOG_LEVEL_INFO, log);
byte syslog_now = syslog_level;
syslog_level = 0; // Disable UDP syslog to not trigger hardware WDT
snprintf_P(svalue, sizeof(svalue), webServer->arg("c1").c_str());
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_COMMAND "%s"), svalue);
addLog(LOG_LEVEL_INFO);
// byte syslog_now = syslog_level;
// syslog_level = 0; // Disable UDP syslog to not trigger hardware WDT - Seems to work fine since 5.7.1d (global logging)
do_cmnd(svalue);
syslog_level = syslog_now;
// syslog_level = syslog_now;
}
if (strlen(webServer->arg("c2").c_str())) {

View File

@ -49,25 +49,23 @@ byte domoticz_update_flag = 1;
void mqtt_publishDomoticzPowerState(byte device)
{
char svalue[64]; // was MESSZ
if (sysCfg.flag.mqtt_enabled && sysCfg.domoticz_relay_idx[device -1]) {
if ((device < 1) || (device > Maxdevice)) {
device = 1;
}
if (sfl_flg) {
snprintf_P(svalue, sizeof(svalue), PSTR("{\"idx\":%d,\"nvalue\":2,\"svalue\":\"%d\"}"),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"idx\":%d,\"nvalue\":2,\"svalue\":\"%d\"}"),
sysCfg.domoticz_relay_idx[device -1], sysCfg.led_dimmer[device -1]);
mqtt_publish(domoticz_in_topic, svalue);
mqtt_publish(domoticz_in_topic);
}
else if ((Maxdevice == device) && (pin[GPIO_WS2812] < 99)) {
snprintf_P(svalue, sizeof(svalue), PSTR("{\"idx\":%d,\"nvalue\":2,\"svalue\":\"%d\"}"),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"idx\":%d,\"nvalue\":2,\"svalue\":\"%d\"}"),
sysCfg.domoticz_relay_idx[device -1], sysCfg.ws_dimmer);
mqtt_publish(domoticz_in_topic, svalue);
mqtt_publish(domoticz_in_topic);
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"idx\":%d,\"nvalue\":%d,\"svalue\":\"\"}"),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"idx\":%d,\"nvalue\":%d,\"svalue\":\"\"}"),
sysCfg.domoticz_relay_idx[device -1], (power & (0x01 << (device -1))) ? 1 : 0);
mqtt_publish(domoticz_in_topic, svalue);
mqtt_publish(domoticz_in_topic);
}
}
@ -136,7 +134,6 @@ boolean domoticz_update()
boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t sdataBuf)
{
char log[LOGSZ];
char stemp1[10];
char scommand[10];
unsigned long idx = 0;
@ -159,8 +156,8 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
idx = domoticz["idx"];
nvalue = domoticz["nvalue"];
snprintf_P(log, sizeof(log), PSTR(D_LOG_DOMOTICZ "idx %d, nvalue %d"), idx, nvalue);
addLog(LOG_LEVEL_DEBUG_MORE, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ "idx %d, nvalue %d"), idx, nvalue);
addLog(LOG_LEVEL_DEBUG_MORE);
if (nvalue >= 0 && nvalue <= 2) {
for (byte i = 0; i < Maxdevice; i++) {
@ -193,8 +190,8 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
return 1;
}
snprintf_P(log, sizeof(log), PSTR(D_LOG_DOMOTICZ D_RECEIVED_TOPIC " %s, " D_DATA " %s"), topicBuf, dataBuf);
addLog(LOG_LEVEL_DEBUG_MORE, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ D_RECEIVED_TOPIC " %s, " D_DATA " %s"), topicBuf, dataBuf);
addLog(LOG_LEVEL_DEBUG_MORE);
domoticz_update_flag = 0;
}
@ -205,7 +202,7 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
* Commands
\*********************************************************************************************/
boolean domoticz_command(const char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, char *svalue, uint16_t ssvalue)
boolean domoticz_command(const char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
{
boolean serviced = true;
uint8_t dmtcz_len = strlen(D_CMND_DOMOTICZ); // Prep for string length change
@ -216,31 +213,31 @@ boolean domoticz_command(const char *type, uint16_t index, char *dataBuf, uint16
sysCfg.domoticz_relay_idx[index -1] = payload;
restartflag = 2;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_DOMOTICZ D_CMND_IDX "%d\":%d}"), index, sysCfg.domoticz_relay_idx[index -1]);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_IDX "%d\":%d}"), index, sysCfg.domoticz_relay_idx[index -1]);
}
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_KEYIDX)) && (index > 0) && (index <= Maxdevice)) {
if (payload >= 0) {
sysCfg.domoticz_key_idx[index -1] = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_DOMOTICZ D_CMND_KEYIDX "%d\":%d}"), index, sysCfg.domoticz_key_idx[index -1]);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_KEYIDX "%d\":%d}"), index, sysCfg.domoticz_key_idx[index -1]);
}
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_SWITCHIDX)) && (index > 0) && (index <= Maxdevice)) {
if (payload >= 0) {
sysCfg.domoticz_switch_idx[index -1] = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_DOMOTICZ D_CMND_SWITCHIDX "%d\":%d}"), index, sysCfg.domoticz_key_idx[index -1]);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_SWITCHIDX "%d\":%d}"), index, sysCfg.domoticz_key_idx[index -1]);
}
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_SENSORIDX)) && (index > 0) && (index <= DOMOTICZ_MAX_SENSORS)) {
if (payload >= 0) {
sysCfg.domoticz_sensor_idx[index -1] = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_DOMOTICZ D_CMND_SENSORIDX "%d\":%d}"), index, sysCfg.domoticz_sensor_idx[index -1]);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_SENSORIDX "%d\":%d}"), index, sysCfg.domoticz_sensor_idx[index -1]);
}
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_UPDATETIMER))) {
if ((payload >= 0) && (payload < 3601)) {
sysCfg.domoticz_update_timer = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_DOMOTICZ D_CMND_UPDATETIMER "\":%d}"), sysCfg.domoticz_update_timer);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_UPDATETIMER "\":%d}"), sysCfg.domoticz_update_timer);
}
else serviced = false;
}
@ -251,11 +248,9 @@ boolean domoticz_command(const char *type, uint16_t index, char *dataBuf, uint16
boolean domoticz_button(byte key, byte device, byte state, byte svalflg)
{
if ((sysCfg.domoticz_key_idx[device -1] || sysCfg.domoticz_switch_idx[device -1]) && (svalflg)) {
char svalue[80]; // was MESSZ
snprintf_P(svalue, sizeof(svalue), PSTR("{\"command\":\"switchlight\",\"idx\":%d,\"switchcmd\":\"%s\"}"),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"command\":\"switchlight\",\"idx\":%d,\"switchcmd\":\"%s\"}"),
(key) ? sysCfg.domoticz_switch_idx[device -1] : sysCfg.domoticz_key_idx[device -1], (state) ? (2 == state) ? "Toggle" : "On" : "Off");
mqtt_publish(domoticz_in_topic, svalue);
mqtt_publish(domoticz_in_topic);
return 1;
} else {
return 0;
@ -274,12 +269,14 @@ uint8_t dom_hum_stat(char *hum)
void dom_sensor(byte idx, char *data)
{
char dmess[64];
if (sysCfg.domoticz_sensor_idx[idx]) {
snprintf_P(dmess, sizeof(dmess), PSTR("{\"idx\":%d,\"nvalue\":0,\"svalue\":\"%s\"}"),
char dmess[64];
memcpy(dmess, mqtt_data, sizeof(dmess));
snprintf_P(mqtt_data, sizeof(dmess), PSTR("{\"idx\":%d,\"nvalue\":0,\"svalue\":\"%s\"}"),
sysCfg.domoticz_sensor_idx[idx], data);
mqtt_publish(domoticz_in_topic, dmess);
mqtt_publish(domoticz_in_topic);
memcpy(mqtt_data, dmess, sizeof(dmess));
}
}
@ -372,7 +369,7 @@ void handleDomoticz()
void domoticz_saveSettings()
{
char log[LOGSZ], stemp[20];
char stemp[20];
for (byte i = 0; i < 4; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("r%d"), i +1);
@ -387,16 +384,16 @@ void domoticz_saveSettings()
sysCfg.domoticz_sensor_idx[i] = (!strlen(webServer->arg(stemp).c_str())) ? 0 : atoi(webServer->arg(stemp).c_str());
}
sysCfg.domoticz_update_timer = (!strlen(webServer->arg("ut").c_str())) ? DOMOTICZ_UPDATE_TIMER : atoi(webServer->arg("ut").c_str());
snprintf_P(log, sizeof(log), PSTR(D_LOG_DOMOTICZ D_CMND_IDX " %d, %d, %d, %d, " D_CMND_UPDATETIMER " %d"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ D_CMND_IDX " %d, %d, %d, %d, " D_CMND_UPDATETIMER " %d"),
sysCfg.domoticz_relay_idx[0], sysCfg.domoticz_relay_idx[1], sysCfg.domoticz_relay_idx[2], sysCfg.domoticz_relay_idx[3],
sysCfg.domoticz_update_timer);
addLog(LOG_LEVEL_INFO, log);
snprintf_P(log, sizeof(log), PSTR(D_LOG_DOMOTICZ D_CMND_KEYIDX " %d, %d, %d, %d, " D_CMND_SWITCHIDX " %d, %d, %d, %d, " D_CMND_SENSORIDX " %d, %d, %d, %d, %d, %d"),
addLog(LOG_LEVEL_INFO);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ D_CMND_KEYIDX " %d, %d, %d, %d, " D_CMND_SWITCHIDX " %d, %d, %d, %d, " D_CMND_SENSORIDX " %d, %d, %d, %d, %d, %d"),
sysCfg.domoticz_key_idx[0], sysCfg.domoticz_key_idx[1], sysCfg.domoticz_key_idx[2], sysCfg.domoticz_key_idx[3],
sysCfg.domoticz_switch_idx[0], sysCfg.domoticz_switch_idx[1], sysCfg.domoticz_switch_idx[2], sysCfg.domoticz_switch_idx[3],
sysCfg.domoticz_sensor_idx[0], sysCfg.domoticz_sensor_idx[1], sysCfg.domoticz_sensor_idx[2], sysCfg.domoticz_sensor_idx[3],
sysCfg.domoticz_sensor_idx[4], sysCfg.domoticz_sensor_idx[5]);
addLog(LOG_LEVEL_INFO, log);
addLog(LOG_LEVEL_INFO);
}
#endif // USE_WEBSERVER
#endif // USE_DOMOTICZ

View File

@ -68,7 +68,7 @@ void ir_send_init(void)
{ "Vendor": "<Toshiba|Mitsubishi>", "Power": <0|1>, "Mode": "<Hot|Cold|Dry|Auto>", "FanSpeed": "<1|2|3|4|5|Auto|Silence>", "Temp": <17..30> }
*/
boolean ir_send_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_len, int16_t payload, char *svalue, uint16_t ssvalue)
boolean ir_send_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_len, int16_t payload)
{
boolean serviced = true;
boolean error = false;
@ -82,16 +82,14 @@ boolean ir_send_command(char *type, uint16_t index, char *dataBufUc, uint16_t da
int HVAC_Temp = 21;
boolean HVAC_Power = true;
// char log[LOGSZ];
if (!strcasecmp_P(type, PSTR(D_CMND_IRSEND))) {
if (data_len) {
StaticJsonBuffer<128> jsonBuf;
JsonObject &ir_json = jsonBuf.parseObject(dataBufUc);
if (!ir_json.success()) {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_IRSEND "\":\"" D_INVALID_JSON "\"}")); // JSON decode failed
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_INVALID_JSON "\"}")); // JSON decode failed
} else {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_IRSEND "\":\"" D_DONE "\"}"));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_DONE "\"}"));
protocol = ir_json[D_IRSEND_PROTOCOL];
bits = ir_json[D_IRSEND_BITS];
data = ir_json[D_IRSEND_DATA];
@ -104,13 +102,13 @@ boolean ir_send_command(char *type, uint16_t index, char *dataBufUc, uint16_t da
else if (!strcmp_P(protocol,PSTR("JVC"))) irsend->sendJVC(data, bits, 1);
else if (!strcmp_P(protocol,PSTR("SAMSUNG"))) irsend->sendSAMSUNG(data, bits);
else {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_IRSEND "\":\"" D_PROTOCOL_NOT_SUPPORTED "\"}"));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_PROTOCOL_NOT_SUPPORTED "\"}"));
}
} else error = true;
}
} else error = true;
if (error) {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_IRSEND "\":\"" D_NO D_IRSEND_PROTOCOL ", " D_IRSEND_BITS " " D_OR " " D_IRSEND_DATA "\"}"));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_NO D_IRSEND_PROTOCOL ", " D_IRSEND_BITS " " D_OR " " D_IRSEND_DATA "\"}"));
}
}
#ifdef USE_IR_HVAC
@ -119,18 +117,18 @@ boolean ir_send_command(char *type, uint16_t index, char *dataBufUc, uint16_t da
StaticJsonBuffer<164> jsonBufer;
JsonObject &root = jsonBufer.parseObject(dataBufUc);
if (!root.success()) {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_IRHVAC "\":\"" D_INVALID_JSON "\"}")); // JSON decode failed
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRHVAC "\":\"" D_INVALID_JSON "\"}")); // JSON decode failed
} else {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_IRHVAC "\":\"" D_DONE "\"}"));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRHVAC "\":\"" D_DONE "\"}"));
HVAC_Vendor = root[D_IRHVAC_VENDOR];
HVAC_Power = root[D_IRHVAC_POWER];
HVAC_Mode = root[D_IRHVAC_MODE];
HVAC_FanMode = root[D_IRHVAC_FANSPEED];
HVAC_Temp = root[D_IRHVAC_TEMP];
// snprintf_P(log, sizeof(log), PSTR("IRHVAC: Received Vendor %s, Power %d, Mode %s, FanSpeed %s, Temp %d"),
// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: Received Vendor %s, Power %d, Mode %s, FanSpeed %s, Temp %d"),
// HVAC_Vendor, HVAC_Power, HVAC_Mode, HVAC_FanMode, HVAC_Temp);
// addLog(LOG_LEVEL_DEBUG, log);
// addLog(LOG_LEVEL_DEBUG);
if (HVAC_Vendor == NULL || !strcmp_P(HVAC_Vendor,PSTR("TOSHIBA"))) {
error = ir_hvac_toshiba(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
@ -142,7 +140,7 @@ boolean ir_send_command(char *type, uint16_t index, char *dataBufUc, uint16_t da
}
} else error = true;
if (error) {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_IRHVAC "\":\"" D_WRONG D_IRHVAC_VENDOR ", " D_IRHVAC_MODE " " D_OR " " D_IRHVAC_FANSPEED "\"}"));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRHVAC "\":\"" D_WRONG D_IRHVAC_VENDOR ", " D_IRHVAC_MODE " " D_OR " " D_IRHVAC_FANSPEED "\"}"));
}
}
#endif // USE_IR_HVAC
@ -246,7 +244,6 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode,const char *HVAC_FanMode, boole
char *p;
char *token;
uint8_t mode;
char log[LOGSZ];
mitsubir->stateReset();
@ -278,9 +275,9 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode,const char *HVAC_FanMode, boole
mitsubir->setVane(MITSUBISHI_AC_VANE_AUTO);
mitsubir->send();
// snprintf_P(log, sizeof(log), PSTR("IRHVAC: Mitsubishi Power %d, Mode %d, FanSpeed %d, Temp %d, VaneMode %d"),
// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: Mitsubishi Power %d, Mode %d, FanSpeed %d, Temp %d, VaneMode %d"),
// mitsubir->getPower(), mitsubir->getMode(), mitsubir->getFan(), mitsubir->getTemp(), mitsubir->getVane());
// addLog(LOG_LEVEL_DEBUG, log);
// addLog(LOG_LEVEL_DEBUG);
return false;
}

View File

@ -39,19 +39,18 @@ void sb_received()
uint16_t rhi = 0;
char svalue[90];
char rfkey[8];
char log[LOGSZ];
svalue[0] = '\0';
for (i = 0; i < SerialInByteCounter; i++) {
snprintf_P(svalue, sizeof(svalue), PSTR("%s%02X "), svalue, serialInBuf[i]);
}
snprintf_P(log, sizeof(log), PSTR(D_LOG_BRIDGE D_RECEIVED " %s"), svalue);
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_BRIDGE D_RECEIVED " %s"), svalue);
addLog(LOG_LEVEL_DEBUG);
if (0xA2 == serialInBuf[0]) { // Learn timeout
sfb_learnFlg = 0;
snprintf_P(svalue, sizeof(svalue), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARN_FAILED "\"}"), sfb_learnKey);
mqtt_publish_topic_P(5, PSTR(D_CMND_RFKEY), svalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARN_FAILED "\"}"), sfb_learnKey);
mqtt_publish_topic_P(5, PSTR(D_CMND_RFKEY));
}
else if (0xA3 == serialInBuf[0]) { // Learned A3 20 F8 01 18 03 3E 2E 1A 22 55
sfb_learnFlg = 0;
@ -61,11 +60,11 @@ void sb_received()
for (i = 0; i < 9; i++) {
sysCfg.sfb_code[sfb_learnKey][i] = serialInBuf[i +1];
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNED "\"}"), sfb_learnKey);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNED "\"}"), sfb_learnKey);
} else {
snprintf_P(svalue, sizeof(svalue), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARN_FAILED "\"}"), sfb_learnKey);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARN_FAILED "\"}"), sfb_learnKey);
}
mqtt_publish_topic_P(5, PSTR(D_CMND_RFKEY), svalue);
mqtt_publish_topic_P(5, PSTR(D_CMND_RFKEY));
}
else if (0xA4 == serialInBuf[0]) { // Received RF data A4 20 EE 01 18 03 3E 2E 1A 22 55
rsy = serialInBuf[1] << 8 | serialInBuf[2]; // Sync time in uSec
@ -87,9 +86,9 @@ void sb_received()
}
}
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"" D_RFRECEIVED "\":{\"" D_SYNC "\":%d, \"" D_LOW "\":%d, \"" D_HIGH "\":%d, \"" D_DATA "\":\"%06X\", \"" D_CMND_RFKEY "\":%s}}"),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_RFRECEIVED "\":{\"" D_SYNC "\":%d, \"" D_LOW "\":%d, \"" D_HIGH "\":%d, \"" D_DATA "\":\"%06X\", \"" D_CMND_RFKEY "\":%s}}"),
rsy, rlo, rhi, rid, rfkey);
mqtt_publish_topic_P(6, PSTR(D_RFRECEIVED), svalue);
mqtt_publish_topic_P(6, PSTR(D_RFRECEIVED));
}
}
}
@ -155,7 +154,7 @@ void sb_learn(uint8_t key)
* Commands
\*********************************************************************************************/
boolean sb_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, char *svalue, uint16_t ssvalue)
boolean sb_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
{
boolean serviced = true;
char *p;
@ -170,28 +169,28 @@ boolean sb_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len,
sysCfg.sfb_code[0][7] = lsb;
}
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_RFDEFAULT "\":\"%0X%0X\"}"), sysCfg.sfb_code[0][6], sysCfg.sfb_code[0][7]);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFDEFAULT "\":\"%0X%0X\"}"), sysCfg.sfb_code[0][6], sysCfg.sfb_code[0][7]);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_RFKEY)) && (index > 0) && (index <= 16)) {
if (!sfb_learnFlg) {
if (2 == payload) {
sb_learn(index);
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_START_LEARNING "\"}"), index);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_START_LEARNING "\"}"), index);
}
else if (3 == payload) {
sysCfg.sfb_code[index][0] = 0;
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_SET_TO_DEFAULT "\"}"), index);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_SET_TO_DEFAULT "\"}"), index);
} else {
if ((1 == payload) || (0 == sysCfg.sfb_code[index][0])) {
sb_send(0, index);
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_DEFAULT_SENT "\"}"), index);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_DEFAULT_SENT "\"}"), index);
} else {
sb_send(index, 0);
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNED_SENT "\"}"), index);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNED_SENT "\"}"), index);
}
}
} else {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNING_ACTIVE "\"}"), sfb_learnKey);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNING_ACTIVE "\"}"), sfb_learnKey);
}
}
else {

View File

@ -257,7 +257,7 @@ char* sl_getColor(char* scolor)
return scolor;
}
void sl_prepPower(char *svalue, uint16_t ssvalue)
void sl_prepPower()
{
char scolor[11];
@ -273,10 +273,10 @@ void sl_prepPower(char *svalue, uint16_t ssvalue)
domoticz_updatePowerState(1);
#endif // USE_DOMOTICZ
if (sfl_flg > 1) {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_RSLT_POWER "\":\"%s\", \"" D_CMND_DIMMER "\":%d, \"" D_CMND_COLOR "\":\"%s\"}"),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_RSLT_POWER "\":\"%s\", \"" D_CMND_DIMMER "\":%d, \"" D_CMND_COLOR "\":\"%s\"}"),
getStateText(power &1), sysCfg.led_dimmer[0], sl_getColor(scolor));
} else {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_RSLT_POWER "\":\"%s\", \"" D_CMND_DIMMER "\":%d}"),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_RSLT_POWER "\":\"%s\", \"" D_CMND_DIMMER "\":%d}"),
getStateText(power &1), sysCfg.led_dimmer[0]);
}
}
@ -293,7 +293,6 @@ void sl_setPower(uint8_t power)
void sl_animate()
{
// {"Wakeup":"Done"}
char svalue[32]; // was MESSZ
uint8_t fadeValue;
uint8_t cur_col[5];
@ -340,8 +339,8 @@ void sl_animate()
sl_tcolor[i] = sl_dcolor[i];
}
} else {
snprintf_P(svalue, sizeof(svalue), PSTR("{\"" D_CMND_WAKEUP "\":\"" D_DONE "\"}"));
mqtt_publish_topic_P(2, PSTR(D_CMND_WAKEUP), svalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUP "\":\"" D_DONE "\"}"));
mqtt_publish_topic_P(2, PSTR(D_CMND_WAKEUP));
sl_wakeupActive = 0;
}
}
@ -422,19 +421,17 @@ void sl_getHSB(float *hue, float *sat, float *bri)
void sl_setHSB(float hue, float sat, float bri, uint16_t ct)
{
char svalue[MESSZ];
HsbColor hsb;
/*
char log[LOGSZ];
char stemp1[10];
char stemp2[10];
char stemp3[10];
dtostrfi(hue, 3, stemp1);
dtostrfi(sat, 3, stemp2);
dtostrfi(bri, 3, stemp3);
snprintf_P(log, sizeof(log), PSTR("HUE: Set Hue %s, Sat %s, Bri %s, Ct %d"), stemp1, stemp2, stemp3, ct);
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR("HUE: Set Hue %s, Sat %s, Bri %s, Ct %d"), stemp1, stemp2, stemp3, ct);
addLog(LOG_LEVEL_DEBUG);
*/
if (sfl_flg > 2) {
@ -450,8 +447,8 @@ void sl_setHSB(float hue, float sat, float bri, uint16_t ct)
sl_dcolor[2] = tmp.B;
sl_setColor();
}
sl_prepPower(svalue, sizeof(svalue));
mqtt_publish_topic_P(5, PSTR(D_CMND_COLOR), svalue);
sl_prepPower();
mqtt_publish_topic_P(5, PSTR(D_CMND_COLOR));
} else {
uint8_t tmp = (uint8_t)(bri * 100);
sysCfg.led_dimmer[0] = tmp;
@ -459,11 +456,11 @@ void sl_setHSB(float hue, float sat, float bri, uint16_t ct)
if (ct > 0) {
sl_setColorTemp(ct);
}
sl_prepPower(svalue, sizeof(svalue));
mqtt_publish_topic_P(5, PSTR(D_CMND_COLOR), svalue);
sl_prepPower();
mqtt_publish_topic_P(5, PSTR(D_CMND_COLOR));
} else {
sl_prepPower(svalue, sizeof(svalue));
mqtt_publish_topic_P(5, PSTR(D_CMND_DIMMER), svalue);
sl_prepPower();
mqtt_publish_topic_P(5, PSTR(D_CMND_DIMMER));
}
}
}
@ -472,7 +469,7 @@ void sl_setHSB(float hue, float sat, float bri, uint16_t ct)
* Commands
\*********************************************************************************************/
boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_len, int16_t payload, char *svalue, uint16_t ssvalue)
boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_len, int16_t payload)
{
boolean serviced = true;
boolean coldim = false;
@ -492,7 +489,7 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
sl_setColor();
coldim = true;
} else {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_COLOR "\":\"%s\"}"), sl_getColor(scolor));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_COLOR "\":\"%s\"}"), sl_getColor(scolor));
}
}
else if (!strcasecmp_P(type, PSTR(D_CMND_COLORTEMPERATURE)) && ((2 == sfl_flg) || (5 == sfl_flg))) { // ColorTemp
@ -500,7 +497,7 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
sl_setColorTemp(payload);
coldim = true;
} else {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_COLORTEMPERATURE "\":%d}"), sl_getColorTemp());
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_COLORTEMPERATURE "\":%d}"), sl_getColorTemp());
}
}
else if (!strcasecmp_P(type, PSTR(D_CMND_DIMMER))) {
@ -508,7 +505,7 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
sysCfg.led_dimmer[0] = payload;
coldim = true;
} else {
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_DIMMER "\":%d}"), sysCfg.led_dimmer[0]);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DIMMER "\":%d}"), sysCfg.led_dimmer[0]);
}
}
else if (!strcasecmp_P(type, PSTR(D_CMND_LEDTABLE))) {
@ -524,7 +521,7 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
}
sl_any = 1;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_LEDTABLE "\":\"%s\"}"), getStateText(sysCfg.led_table));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_LEDTABLE "\":\"%s\"}"), getStateText(sysCfg.led_table));
}
else if (!strcasecmp_P(type, PSTR(D_CMND_FADE))) {
switch (payload) {
@ -536,39 +533,39 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le
sysCfg.led_fade ^= 1;
break;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_FADE "\":\"%s\"}"), getStateText(sysCfg.led_fade));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_FADE "\":\"%s\"}"), getStateText(sysCfg.led_fade));
}
else if (!strcasecmp_P(type, PSTR(D_CMND_SPEED))) { // 1 - fast, 8 - slow
if ((payload > 0) && (payload <= 8)) {
sysCfg.led_speed = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_SPEED "\":%d}"), sysCfg.led_speed);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SPEED "\":%d}"), sysCfg.led_speed);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_WAKEUPDURATION))) {
if ((payload > 0) && (payload < 3001)) {
sysCfg.led_wakeup = payload;
sl_wakeupActive = 0;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_WAKEUPDURATION "\":%d}"), sysCfg.led_wakeup);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUPDURATION "\":%d}"), sysCfg.led_wakeup);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_WAKEUP))) {
sl_wakeupActive = 3;
do_cmnd_power(1, 1);
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_WAKEUP "\":\"" D_STARTED "\"}"));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUP "\":\"" D_STARTED "\"}"));
}
else if (!strcasecmp_P(type, PSTR("UNDOCA"))) { // Theos legacy status
sl_getColor(scolor);
scolor[6] = '\0'; // RGB only
snprintf_P(svalue, ssvalue, PSTR("%s, %d, %d, 1, %d, 1"),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, %d, %d, 1, %d, 1"),
scolor, sysCfg.led_fade, sysCfg.led_table, sysCfg.led_speed);
mqtt_publish_topic_P(1, type, svalue);
svalue[0] = '\0';
mqtt_publish_topic_P(1, type);
mqtt_data[0] = '\0';
}
else {
serviced = false; // Unknown command
}
if (coldim) {
sl_prepPower(svalue, ssvalue);
sl_prepPower();
}
return serviced;
}

View File

@ -99,7 +99,7 @@ float sc_convertCtoF(float c)
return c * 1.8 + 32;
}
void sc_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
void sc_mqttPresent(uint8_t* djson)
{
if (sc_value[0] > 0) {
char stemp1[10];
@ -109,8 +109,8 @@ void sc_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
float h = sc_value[0];
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp2);
snprintf_P(svalue, ssvalue, PSTR("%s, \"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s, \"" D_LIGHT "\":%d, \"" D_NOISE "\":%d, \"" D_AIRQUALITY "\":%d"),
svalue, stemp1, stemp2, sc_value[2], sc_value[3], sc_value[4]);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s, \"" D_LIGHT "\":%d, \"" D_NOISE "\":%d, \"" D_AIRQUALITY "\":%d"),
mqtt_data, stemp1, stemp2, sc_value[2], sc_value[3], sc_value[4]);
*djson = 1;
#ifdef USE_DOMOTICZ
domoticz_sensor2(stemp1, stemp2);

View File

@ -68,7 +68,6 @@ String wemo_UUID()
void wemo_respondToMSearch()
{
char message[TOPSZ];
char log[LOGSZ];
if (portUDP.beginPacket(portUDP.remoteIP(), portUDP.remotePort())) {
String response = FPSTR(WEMO_MSEARCH);
@ -80,9 +79,9 @@ void wemo_respondToMSearch()
} else {
snprintf_P(message, sizeof(message), PSTR(D_FAILED_TO_SEND_RESPONSE));
}
snprintf_P(log, sizeof(log), PSTR(D_LOG_UPNP D_WEMO " %s " D_TO " %s:%d"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPNP D_WEMO " %s " D_TO " %s:%d"),
message, portUDP.remoteIP().toString().c_str(), portUDP.remotePort());
addLog(LOG_LEVEL_DEBUG, log);
addLog(LOG_LEVEL_DEBUG);
}
/*********************************************************************************************\
@ -140,7 +139,6 @@ String hue_UUID()
void hue_respondToMSearch()
{
char message[TOPSZ];
char log[LOGSZ];
if (portUDP.beginPacket(portUDP.remoteIP(), portUDP.remotePort())) {
String response1 = FPSTR(HUE_RESPONSE);
@ -153,31 +151,25 @@ void hue_respondToMSearch()
portUDP.write(response.c_str());
portUDP.endPacket();
//addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());
response = response1;
response += FPSTR(HUE_ST2);
response.replace("{r3}", hue_UUID());
portUDP.write(response.c_str());
portUDP.endPacket();
//addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());
response = response1;
response += FPSTR(HUE_ST3);
response.replace("{r3}", hue_UUID());
portUDP.write(response.c_str());
portUDP.endPacket();
//addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());
snprintf_P(message, sizeof(message), PSTR(D_3_RESPONSE_PACKETS_SENT));
} else {
snprintf_P(message, sizeof(message), PSTR(D_FAILED_TO_SEND_RESPONSE));
}
snprintf_P(log, sizeof(log), PSTR(D_LOG_UPNP D_HUE " %s " D_TO " %s:%d"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPNP D_HUE " %s " D_TO " %s:%d"),
message, portUDP.remoteIP().toString().c_str(), portUDP.remotePort());
addLog(LOG_LEVEL_DEBUG, log);
addLog(LOG_LEVEL_DEBUG);
}
/*********************************************************************************************\
@ -440,10 +432,8 @@ void handleUPnPsetupHue()
void hue_todo(String *path)
{
char log[LOGSZ];
snprintf_P(log, sizeof(log), PSTR(D_LOG_HTTP D_HUE_API_NOT_IMPLEMENTED " (%s)"), path->c_str());
addLog(LOG_LEVEL_DEBUG_MORE, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_HTTP D_HUE_API_NOT_IMPLEMENTED " (%s)"), path->c_str());
addLog(LOG_LEVEL_DEBUG_MORE);
webServer->send(200, FPSTR(HDR_CTYPE_JSON), "{}");
}
@ -665,8 +655,6 @@ void hue_lights(String *path)
response = FPSTR(HUE_ERROR_JSON);
}
//addLog(LOG_LEVEL_DEBUG_MORE, response.c_str());
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
}
else if(path->indexOf("/lights/") >= 0) { // Got /lights/ID
@ -718,17 +706,16 @@ void handle_hue_api(String *path)
* (c) Heiko Krupp, 2017
*/
char log[LOGSZ];
uint8_t args = 0;
path->remove(0, 4); // remove /api
uint16_t apilen = path->length();
snprintf_P(log, sizeof(log), PSTR(D_LOG_HTTP D_HUE_API " (%s)"), path->c_str());
addLog(LOG_LEVEL_DEBUG_MORE, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_HTTP D_HUE_API " (%s)"), path->c_str());
addLog(LOG_LEVEL_DEBUG_MORE);
for (args = 0; args < webServer->args(); args++) {
String json = webServer->arg(args);
snprintf_P(log, sizeof(log), PSTR(D_LOG_HTTP D_HUE_POST_ARGS " (%s)"), json.c_str());
addLog(LOG_LEVEL_DEBUG_MORE, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_HTTP D_HUE_POST_ARGS " (%s)"), json.c_str());
addLog(LOG_LEVEL_DEBUG_MORE);
}
if (path->endsWith("/invalid/")) {} // Just ignore

View File

@ -107,7 +107,6 @@ void ws2812_setDim(uint8_t myDimmer)
void ws2812_setColor(uint16_t led, char* colstr)
{
HtmlColor hcolor;
char log[LOGSZ];
char lcolstr[8];
snprintf_P(lcolstr, sizeof(lcolstr), PSTR("#%s"), colstr);
@ -119,8 +118,8 @@ void ws2812_setColor(uint16_t led, char* colstr)
} else {
dcolor = RgbColor(hcolor);
// snprintf_P(log, sizeof(log), PSTR("DBG: Red %02X, Green %02X, Blue %02X"), dcolor.R, dcolor.G, dcolor.B);
// addLog(LOG_LEVEL_DEBUG, log);
// snprintf_P(log_data, sizeof(log_data), PSTR("DBG: Red %02X, Green %02X, Blue %02X"), dcolor.R, dcolor.G, dcolor.B);
// addLog(LOG_LEVEL_DEBUG);
uint16_t temp = dcolor.R;
if (temp < dcolor.G) {
@ -145,7 +144,7 @@ void ws2812_setColor(uint16_t led, char* colstr)
}
}
void ws2812_getColor(uint16_t led, char* svalue, uint16_t ssvalue)
void ws2812_getColor(uint16_t led)
{
RgbColor mcolor;
char stemp[20];
@ -161,7 +160,7 @@ void ws2812_getColor(uint16_t led, char* svalue, uint16_t ssvalue)
uint32_t color = (uint32_t)mcolor.R << 16;
color += (uint32_t)mcolor.G << 8;
color += (uint32_t)mcolor.B;
snprintf_P(svalue, ssvalue, PSTR("{\"%s\":\"%06X\"}"), stemp, color);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%06X\"}"), stemp, color);
}
void ws2812_stripShow()
@ -342,7 +341,6 @@ void ws2812_bars()
void ws2812_animate()
{
char log[LOGSZ];
uint8_t fadeValue;
stripTimerCntr++;
@ -423,8 +421,8 @@ void ws2812_animate()
lany = 0;
lcolor = tcolor;
// snprintf_P(log, sizeof(log), PSTR("DBG: StripPixels %d, CfgPixels %d, Red %02X, Green %02X, Blue %02X"), strip->PixelCount(), sysCfg.ws_pixels, lcolor.R, lcolor.G, lcolor.B);
// addLog(LOG_LEVEL_DEBUG, log);
// snprintf_P(log_data, sizeof(log_data), PSTR("DBG: StripPixels %d, CfgPixels %d, Red %02X, Green %02X, Blue %02X"), strip->PixelCount(), sysCfg.ws_pixels, lcolor.R, lcolor.G, lcolor.B);
// addLog(LOG_LEVEL_DEBUG);
if (sysCfg.ws_ledtable) {
for (uint16_t i = 0; i < sysCfg.ws_pixels; i++) {
@ -512,7 +510,7 @@ void ws2812_setHSB(float hue, float sat, float bri)
* Commands
\*********************************************************************************************/
boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, char *svalue, uint16_t ssvalue)
boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
{
boolean serviced = true;
@ -521,13 +519,13 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
sysCfg.ws_pixels = payload;
ws2812_pixels();
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_PIXELS "\":%d}"), sysCfg.ws_pixels);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_PIXELS "\":%d}"), sysCfg.ws_pixels);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_LED)) && (index > 0) && (index <= sysCfg.ws_pixels)) {
if (6 == data_len) {
ws2812_setColor(index, dataBuf);
}
ws2812_getColor(index, svalue, ssvalue);
ws2812_getColor(index);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_COLOR))) {
if (dataBuf[0] == '#') {
@ -538,7 +536,7 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
ws2812_setColor(0, dataBuf);
bitSet(power, ws_bit);
}
ws2812_getColor(0, svalue, ssvalue);
ws2812_getColor(0);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_DIMMER))) {
if ((payload >= 0) && (payload <= 100)) {
@ -550,7 +548,7 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
domoticz_updatePowerState(ws_bit +1);
#endif // USE_DOMOTICZ
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_DIMMER "\":%d}"), sysCfg.ws_dimmer);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DIMMER "\":%d}"), sysCfg.ws_dimmer);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_LEDTABLE))) {
if ((payload >= 0) && (payload <= 2)) {
@ -565,7 +563,7 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
}
ws2812_update();
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_LEDTABLE "\":\"%s\"}"), getStateText(sysCfg.ws_ledtable));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_LEDTABLE "\":\"%s\"}"), getStateText(sysCfg.ws_ledtable));
}
else if (!strcasecmp_P(type, PSTR(D_CMND_FADE))) {
switch (payload) {
@ -577,19 +575,19 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
sysCfg.ws_fade ^= 1;
break;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_FADE "\":\"%s\"}"), getStateText(sysCfg.ws_fade));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_FADE "\":\"%s\"}"), getStateText(sysCfg.ws_fade));
}
else if (!strcasecmp_P(type, PSTR(D_CMND_SPEED))) { // 1 - fast, 5 - slow
if ((payload > 0) && (payload <= 5)) {
sysCfg.ws_speed = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_SPEED "\":%d}"), sysCfg.ws_speed);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SPEED "\":%d}"), sysCfg.ws_speed);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_WIDTH))) {
if ((payload >= 0) && (payload <= 4)) {
sysCfg.ws_width = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_WIDTH "\":%d}"), sysCfg.ws_width);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WIDTH "\":%d}"), sysCfg.ws_width);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_WAKEUP))) {
if ((payload > 0) && (payload < 3001)) {
@ -598,7 +596,7 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
sysCfg.ws_scheme = 0;
}
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_WAKEUP "\":%d}"), sysCfg.ws_wakeup);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUP "\":%d}"), sysCfg.ws_wakeup);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_SCHEME))) {
if ((payload >= 0) && (payload <= 9)) {
@ -609,7 +607,7 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
bitSet(power, ws_bit);
ws2812_resetStripTimer();
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_SCHEME "\":%d}"), sysCfg.ws_scheme);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SCHEME "\":%d}"), sysCfg.ws_scheme);
}
else if (!strcasecmp_P(type, PSTR("UNDOCA"))) { // Theos legacy status
RgbColor mcolor;
@ -618,10 +616,10 @@ boolean ws2812_command(char *type, uint16_t index, char *dataBuf, uint16_t data_
uint32_t color = (uint32_t)mcolor.R << 16;
color += (uint32_t)mcolor.G << 8;
color += (uint32_t)mcolor.B;
snprintf_P(svalue, ssvalue, PSTR("%06X, %d, %d, %d, %d, %d"),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%06X, %d, %d, %d, %d, %d"),
color, sysCfg.ws_fade, sysCfg.ws_ledtable, sysCfg.ws_scheme, sysCfg.ws_speed, sysCfg.ws_width);
mqtt_publish_topic_P(1, type, svalue);
svalue[0] = '\0';
mqtt_publish_topic_P(1, type);
mqtt_data[0] = '\0';
}
else {
serviced = false; // Unknown command

View File

@ -47,7 +47,6 @@ boolean bh1750_detect()
return true;
}
char log[LOGSZ];
uint8_t status;
boolean success = false;
@ -67,8 +66,8 @@ boolean bh1750_detect()
strcpy_P(bh1750stype, PSTR("BH1750"));
}
if (success) {
snprintf_P(log, sizeof(log), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bh1750stype, bh1750addr);
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bh1750stype, bh1750addr);
addLog(LOG_LEVEL_DEBUG);
} else {
bh1750type = 0;
}
@ -79,14 +78,14 @@ boolean bh1750_detect()
* Presentation
\*********************************************************************************************/
void bh1750_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
void bh1750_mqttPresent(uint8_t* djson)
{
if (!bh1750type) {
return;
}
uint16_t l = bh1750_readLux();
snprintf_P(svalue, ssvalue, PSTR("%s, \"%s\":{\"" D_ILLUMINANCE "\":%d}"), svalue, bh1750stype, l);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_ILLUMINANCE "\":%d}"), mqtt_data, bh1750stype, l);
*djson = 1;
#ifdef USE_DOMOTICZ
domoticz_sensor5(l);

View File

@ -394,7 +394,6 @@ boolean bmp_detect()
return true;
}
char log[LOGSZ];
boolean success = false;
bmpaddr = BMP_ADDR;
@ -418,8 +417,8 @@ boolean bmp_detect()
strcpy_P(bmpstype, PSTR("BME280"));
}
if (success) {
snprintf_P(log, sizeof(log), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bmpstype, bmpaddr);
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bmpstype, bmpaddr);
addLog(LOG_LEVEL_DEBUG);
} else {
bmptype = 0;
}
@ -430,7 +429,7 @@ boolean bmp_detect()
* Presentation
\*********************************************************************************************/
void bmp_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
void bmp_mqttPresent(uint8_t* djson)
{
if (!bmptype) {
return;
@ -447,11 +446,11 @@ void bmp_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
dtostrfd(p, sysCfg.flag.pressure_resolution, stemp2);
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp3);
if (!strcmp(bmpstype,"BME280")) {
snprintf_P(svalue, ssvalue, PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s, \"" D_PRESSURE "\":%s}"),
svalue, bmpstype, stemp1, stemp3, stemp2);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s, \"" D_PRESSURE "\":%s}"),
mqtt_data, bmpstype, stemp1, stemp3, stemp2);
} else {
snprintf_P(svalue, ssvalue, PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_PRESSURE "\":%s}"),
svalue, bmpstype, stemp1, stemp2);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_PRESSURE "\":%s}"),
mqtt_data, bmpstype, stemp1, stemp2);
}
*djson = 1;
#ifdef USE_DOMOTICZ

View File

@ -25,8 +25,6 @@ unsigned long pTimeLast[MAX_COUNTERS]; // Last counter time in milli seconds
void counter_update(byte index)
{
// char log[LOGSZ];
unsigned long pTime = millis() - pTimeLast[index -1];
if (pTime > sysCfg.pCounterDebounce) {
pTimeLast[index -1] = millis();
@ -36,8 +34,8 @@ void counter_update(byte index)
rtcMem.pCounter[index -1]++;
}
// snprintf_P(log, sizeof(log), PSTR("CNTR: Interrupt %d"), index);
// addLog(LOG_LEVEL_DEBUG, log);
// snprintf_P(log_data, sizeof(log_data), PSTR("CNTR: Interrupt %d"), index);
// addLog(LOG_LEVEL_DEBUG);
}
}
@ -87,7 +85,7 @@ void counter_init()
* Presentation
\*********************************************************************************************/
void counter_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
void counter_mqttPresent(uint8_t* djson)
{
char stemp[16];
@ -100,7 +98,7 @@ void counter_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
dsxflg++;
dtostrfd(rtcMem.pCounter[i], 0, stemp);
}
snprintf_P(svalue, ssvalue, PSTR("%s, \"" D_COUNTER "%d\":%s"), svalue, i +1, stemp);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"" D_COUNTER "%d\":%s"), mqtt_data, i +1, stemp);
*djson = 1;
#ifdef USE_DOMOTICZ
if (1 == dsxflg) {

View File

@ -64,7 +64,6 @@ uint32_t dht_expectPulse(byte sensor, bool level)
void dht_read(byte sensor)
{
char log[LOGSZ];
uint32_t cycles[80];
uint32_t currenttime = millis();
@ -117,9 +116,9 @@ void dht_read(byte sensor)
}
}
snprintf_P(log, sizeof(log), PSTR(D_LOG_DHT D_RECEIVED " %02X, %02X, %02X, %02X, %02X =? %02X"),
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DHT D_RECEIVED " %02X, %02X, %02X, %02X, %02X =? %02X"),
dht_data[0], dht_data[1], dht_data[2], dht_data[3], dht_data[4], (dht_data[0] + dht_data[1] + dht_data[2] + dht_data[3]) & 0xFF);
addLog(LOG_LEVEL_DEBUG, log);
addLog(LOG_LEVEL_DEBUG);
if (dht_data[4] == ((dht_data[0] + dht_data[1] + dht_data[2] + dht_data[3]) & 0xFF)) {
dht[sensor].lastresult = 0;
@ -191,8 +190,6 @@ boolean dht_setup(byte pin, byte type)
void dht_init()
{
char log[LOGSZ];
dht_maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for reading pulses from DHT sensor.
for (byte i = 0; i < dht_sensors; i++) {
@ -219,7 +216,7 @@ void dht_init()
* Presentation
\*********************************************************************************************/
void dht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
void dht_mqttPresent(uint8_t* djson)
{
char stemp1[10];
char stemp2[10];
@ -231,7 +228,7 @@ void dht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
if (dht_readTempHum(i, t, h)) { // Read temperature
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp2);
snprintf_P(svalue, ssvalue, JSON_SNS_TEMPHUM, svalue, dht[i].stype, stemp1, stemp2);
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, dht[i].stype, stemp1, stemp2);
*djson = 1;
#ifdef USE_DOMOTICZ
if (!dsxflg) {

View File

@ -185,14 +185,14 @@ boolean dsb_readTemp(float &t)
* Presentation
\*********************************************************************************************/
void dsb_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
void dsb_mqttPresent(uint8_t* djson)
{
char stemp1[10];
float t;
if (dsb_readTemp(t)) { // Check if read failed
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
snprintf_P(svalue, ssvalue, PSTR("%s, \"DS18B20\":{\"" D_TEMPERATURE "\":%s}"), svalue, stemp1);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"DS18B20\":{\"" D_TEMPERATURE "\":%s}"), mqtt_data, stemp1);
*djson = 1;
#ifdef USE_DOMOTICZ
domoticz_sensor1(stemp1);

View File

@ -180,7 +180,7 @@ void ds18x20_type(uint8_t sensor)
}
}
void ds18x20_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
void ds18x20_mqttPresent(uint8_t* djson)
{
char stemp1[10];
char stemp2[10];
@ -192,13 +192,13 @@ void ds18x20_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
ds18x20_type(i);
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp2);
if (!dsxflg) {
snprintf_P(svalue, ssvalue, PSTR("%s, \"DS18x20\":{"), svalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"DS18x20\":{"), mqtt_data);
*djson = 1;
stemp1[0] = '\0';
}
dsxflg++;
snprintf_P(svalue, ssvalue, PSTR("%s%s\"DS%d\":{\"" D_TYPE "\":\"%s\", \"" D_ADDRESS "\":\"%s\", \"" D_TEMPERATURE "\":%s}"),
svalue, stemp1, i +1, dsbstype, ds18x20_address(i).c_str(), stemp2);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"DS%d\":{\"" D_TYPE "\":\"%s\", \"" D_ADDRESS "\":\"%s\", \"" D_TEMPERATURE "\":%s}"),
mqtt_data, stemp1, i +1, dsbstype, ds18x20_address(i).c_str(), stemp2);
strcpy(stemp1, ", ");
#ifdef USE_DOMOTICZ
if (1 == dsxflg) domoticz_sensor1(stemp2);
@ -206,7 +206,7 @@ void ds18x20_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
}
}
if (dsxflg) {
snprintf_P(svalue, ssvalue, PSTR("%s}"), svalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
}
}

View File

@ -194,9 +194,8 @@ void hlw_readEnergy(byte option, float &et, float &ed, float &e, float &w, float
uint16_t hlw_period;
uint16_t hlw_interval;
//char log[LOGSZ];
//snprintf_P(log, sizeof(log), PSTR("HLW: CF %d, CF1U %d (%d), CF1I %d (%d)"), hlw_cf_plen, hlw_cf1u_plen, hlw_cf1u_pcntmax, hlw_cf1i_plen, hlw_cf1i_pcntmax);
//addLog(LOG_LEVEL_DEBUG, log);
//snprintf_P(log_data, sizeof(log_data), PSTR("HLW: CF %d, CF1U %d (%d), CF1I %d (%d)"), hlw_cf_plen, hlw_cf1u_plen, hlw_cf1u_pcntmax, hlw_cf1i_plen, hlw_cf1i_pcntmax);
//addLog(LOG_LEVEL_DEBUG);
et = (float)(rtcMem.hlw_kWhtotal + (cur_kWhtoday / 1000)) / 100000;
ed = 0;
@ -312,8 +311,6 @@ void hlw_setPowerSteadyCounter(byte value)
void hlw_margin_chk()
{
char log[LOGSZ];
char svalue[200]; // was MESSZ
float pet;
float ped;
float pe;
@ -339,38 +336,38 @@ void hlw_margin_chk()
puv = (uint16_t)(pu);
piv = (uint16_t)(pi * 1000);
// snprintf_P(log, sizeof(log), PSTR("HLW: W %d, U %d, I %d"), pw, pu, piv);
// addLog(LOG_LEVEL_DEBUG, log);
// snprintf_P(log_data, sizeof(log_data), PSTR("HLW: W %d, U %d, I %d"), pw, pu, piv);
// addLog(LOG_LEVEL_DEBUG);
snprintf_P(svalue, sizeof(svalue), PSTR("{"));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{"));
jsonflg = 0;
if (hlw_margin(0, sysCfg.hlw_pmin, pwv, flag, hlw_pminflg)) {
snprintf_P(svalue, sizeof(svalue), PSTR("%s%s\"" D_CMND_POWERLOW "\":\"%s\""), svalue, (jsonflg)?", ":"", getStateText(flag));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_POWERLOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
jsonflg = 1;
}
if (hlw_margin(1, sysCfg.hlw_pmax, pwv, flag, hlw_pmaxflg)) {
snprintf_P(svalue, sizeof(svalue), PSTR("%s%s\"" D_CMND_POWERHIGH "\":\"%s\""), svalue, (jsonflg)?", ":"", getStateText(flag));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_POWERHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
jsonflg = 1;
}
if (hlw_margin(0, sysCfg.hlw_umin, puv, flag, hlw_uminflg)) {
snprintf_P(svalue, sizeof(svalue), PSTR("%s%s\"" D_CMND_VOLTAGELOW "\":\"%s\""), svalue, (jsonflg)?", ":"", getStateText(flag));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_VOLTAGELOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
jsonflg = 1;
}
if (hlw_margin(1, sysCfg.hlw_umax, puv, flag, hlw_umaxflg)) {
snprintf_P(svalue, sizeof(svalue), PSTR("%s%s\"" D_CMND_VOLTAGEHIGH "\":\"%s\""), svalue, (jsonflg)?", ":"", getStateText(flag));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_VOLTAGEHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
jsonflg = 1;
}
if (hlw_margin(0, sysCfg.hlw_imin, piv, flag, hlw_iminflg)) {
snprintf_P(svalue, sizeof(svalue), PSTR("%s%s\"" D_CMND_CURRENTLOW "\":\"%s\""), svalue, (jsonflg)?", ":"", getStateText(flag));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_CURRENTLOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
jsonflg = 1;
}
if (hlw_margin(1, sysCfg.hlw_imax, piv, flag, hlw_imaxflg)) {
snprintf_P(svalue, sizeof(svalue), PSTR("%s%s\"" D_CMND_CURRENTHIGH "\":\"%s\""), svalue, (jsonflg)?", ":"", getStateText(flag));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_CURRENTHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
jsonflg = 1;
}
if (jsonflg) {
snprintf_P(svalue, sizeof(svalue), PSTR("%s}"), svalue);
mqtt_publish_topic_P(2, PSTR(D_RSLT_MARGINS), svalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
mqtt_publish_topic_P(2, PSTR(D_RSLT_MARGINS));
hlw_mqttPresent(0);
}
}
@ -384,8 +381,8 @@ void hlw_margin_chk()
} else {
hlw_mplh_counter--;
if (!hlw_mplh_counter) {
snprintf_P(svalue, sizeof(svalue), PSTR("{\"" D_MAXPOWERREACHED "\":\"%d%s\"}"), pwv, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
mqtt_publish_topic_P(1, S_RSLT_WARNING, svalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXPOWERREACHED "\":\"%d%s\"}"), pwv, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
mqtt_publish_topic_P(1, S_RSLT_WARNING);
hlw_mqttPresent(0);
do_cmnd_power(1, 0);
if (!hlw_mplr_counter) {
@ -407,12 +404,12 @@ void hlw_margin_chk()
if (hlw_mplr_counter) {
hlw_mplr_counter--;
if (hlw_mplr_counter) {
snprintf_P(svalue, sizeof(svalue), PSTR("{\"" D_POWERMONITOR "\":\"%s\"}"), getStateText(1));
mqtt_publish_topic_P(5, PSTR(D_POWERMONITOR), svalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_POWERMONITOR "\":\"%s\"}"), getStateText(1));
mqtt_publish_topic_P(5, PSTR(D_POWERMONITOR));
do_cmnd_power(1, 1);
} else {
snprintf_P(svalue, sizeof(svalue), PSTR("{\"" D_MAXPOWERREACHEDRETRY "\":\"%s\"}"), getStateText(0));
mqtt_publish_topic_P(1, S_RSLT_WARNING, svalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXPOWERREACHEDRETRY "\":\"%s\"}"), getStateText(0));
mqtt_publish_topic_P(1, S_RSLT_WARNING);
hlw_mqttPresent(0);
}
}
@ -425,15 +422,15 @@ void hlw_margin_chk()
uped = (uint16_t)(ped * 1000);
if (!hlw_mkwh_state && (rtcTime.Hour == sysCfg.hlw_mkwhs)) {
hlw_mkwh_state = 1;
snprintf_P(svalue, sizeof(svalue), PSTR("{\"" D_ENERGYMONITOR "\":\"%s\"}"), getStateText(1));
mqtt_publish_topic_P(5, PSTR(D_ENERGYMONITOR), svalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_ENERGYMONITOR "\":\"%s\"}"), getStateText(1));
mqtt_publish_topic_P(5, PSTR(D_ENERGYMONITOR));
do_cmnd_power(1, 1);
}
else if ((1 == hlw_mkwh_state) && (uped >= sysCfg.hlw_mkwh)) {
hlw_mkwh_state = 2;
dtostrfd(ped, 3, svalue);
snprintf_P(svalue, sizeof(svalue), PSTR("{\"" D_MAXENERGYREACHED "\":\"%s%s\"}"), svalue, (sysCfg.flag.value_units) ? " " D_UNIT_KILOWATTHOUR : "");
mqtt_publish_topic_P(1, S_RSLT_WARNING, svalue);
dtostrfd(ped, 3, mqtt_data);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXENERGYREACHED "\":\"%s%s\"}"), mqtt_data, (sysCfg.flag.value_units) ? " " D_UNIT_KILOWATTHOUR : "");
mqtt_publish_topic_P(1, S_RSLT_WARNING);
hlw_mqttPresent(0);
do_cmnd_power(1, 0);
}
@ -445,7 +442,7 @@ void hlw_margin_chk()
* Commands
\*********************************************************************************************/
boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, char *svalue, uint16_t ssvalue)
boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
{
boolean serviced = true;
uint8_t caltext = 0;
@ -454,37 +451,37 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
if ((payload >= 0) && (payload < 3601)) {
sysCfg.hlw_pmin = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_POWERLOW "\":\"%d%s\"}"), sysCfg.hlw_pmin, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_POWERLOW "\":\"%d%s\"}"), sysCfg.hlw_pmin, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_POWERHIGH))) {
if ((payload >= 0) && (payload < 3601)) {
sysCfg.hlw_pmax = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_POWERHIGH "\":\"%d%s\"}"), sysCfg.hlw_pmax, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_POWERHIGH "\":\"%d%s\"}"), sysCfg.hlw_pmax, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_VOLTAGELOW))) {
if ((payload >= 0) && (payload < 501)) {
sysCfg.hlw_umin = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_VOLTAGELOW "\":\"%d%s\"}"), sysCfg.hlw_umin, (sysCfg.flag.value_units) ? " " D_UNIT_VOLT : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_VOLTAGELOW "\":\"%d%s\"}"), sysCfg.hlw_umin, (sysCfg.flag.value_units) ? " " D_UNIT_VOLT : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_VOLTAGEHIGH))) {
if ((payload >= 0) && (payload < 501)) {
sysCfg.hlw_umax = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_VOLTAGEHIGH "\":\"%d%s\"}"), sysCfg.hlw_umax, (sysCfg.flag.value_units) ? " " D_UNIT_VOLT : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_VOLTAGEHIGH "\":\"%d%s\"}"), sysCfg.hlw_umax, (sysCfg.flag.value_units) ? " " D_UNIT_VOLT : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_CURRENTLOW))) {
if ((payload >= 0) && (payload < 16001)) {
sysCfg.hlw_imin = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_CURRENTLOW "\":\"%d%s\"}"), sysCfg.hlw_imin, (sysCfg.flag.value_units) ? " " D_UNIT_MILLIAMPERE : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_CURRENTLOW "\":\"%d%s\"}"), sysCfg.hlw_imin, (sysCfg.flag.value_units) ? " " D_UNIT_MILLIAMPERE : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_CURRENTHIGH))) {
if ((payload >= 0) && (payload < 16001)) {
sysCfg.hlw_imax = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_CURRENTHIGH "\":\"%d%s\"}"), sysCfg.hlw_imax, (sysCfg.flag.value_units) ? " " D_UNIT_MILLIAMPERE : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_CURRENTHIGH "\":\"%d%s\"}"), sysCfg.hlw_imax, (sysCfg.flag.value_units) ? " " D_UNIT_MILLIAMPERE : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_ENERGYRESET))) {
if ((payload >= 1) && (payload <= 3)) {
@ -509,7 +506,7 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
dtostrfd((float)sysCfg.hlw_kWhyesterday / 100000000, sysCfg.flag.energy_resolution, sey);
dtostrfd((float)rtcMem.hlw_kWhtoday / 100000000, sysCfg.flag.energy_resolution, sen);
dtostrfd((float)(rtcMem.hlw_kWhtotal + (hlw_kWhtoday / 1000)) / 100000, sysCfg.flag.energy_resolution, set);
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_ENERGYRESET "\":{\"" D_TOTAL "\":%s, \"" D_YESTERDAY "\":%s, \"" D_TODAY "\":%s}}"), set, sey, sen);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_ENERGYRESET "\":{\"" D_TOTAL "\":%s, \"" D_YESTERDAY "\":%s, \"" D_TODAY "\":%s}}"), set, sey, sen);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWPCAL))) {
if ((payload > 0) && (payload < 32001)) {
@ -552,50 +549,50 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
if ((payload >= 0) && (payload < 3601)) {
sysCfg.hlw_mpl = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_MAXPOWER "\":\"%d%s\"}"), sysCfg.hlw_mpl, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXPOWER "\":\"%d%s\"}"), sysCfg.hlw_mpl, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXPOWERHOLD))) {
if ((payload >= 0) && (payload < 3601)) {
sysCfg.hlw_mplh = (1 == payload) ? MAX_POWER_HOLD : payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_MAXPOWERHOLD "\":\"%d%s\"}"), sysCfg.hlw_mplh, (sysCfg.flag.value_units) ? " " D_UNIT_SECOND : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXPOWERHOLD "\":\"%d%s\"}"), sysCfg.hlw_mplh, (sysCfg.flag.value_units) ? " " D_UNIT_SECOND : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXPOWERWINDOW))) {
if ((payload >= 0) && (payload < 3601)) {
sysCfg.hlw_mplw = (1 == payload) ? MAX_POWER_WINDOW : payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_MAXPOWERWINDOW "\":\"%d%s\"}"), sysCfg.hlw_mplw, (sysCfg.flag.value_units) ? " " D_UNIT_SECOND : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXPOWERWINDOW "\":\"%d%s\"}"), sysCfg.hlw_mplw, (sysCfg.flag.value_units) ? " " D_UNIT_SECOND : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_SAFEPOWER))) {
if ((payload >= 0) && (payload < 3601)) {
sysCfg.hlw_mspl = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_SAFEPOWER "\":\"%d%s\"}"), sysCfg.hlw_mspl, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SAFEPOWER "\":\"%d%s\"}"), sysCfg.hlw_mspl, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_SAFEPOWERHOLD))) {
if ((payload >= 0) && (payload < 3601)) {
sysCfg.hlw_msplh = (1 == payload) ? SAFE_POWER_HOLD : payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_SAFEPOWERHOLD "\":\"%d%s\"}"), sysCfg.hlw_msplh, (sysCfg.flag.value_units) ? " " D_UNIT_SECOND : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SAFEPOWERHOLD "\":\"%d%s\"}"), sysCfg.hlw_msplh, (sysCfg.flag.value_units) ? " " D_UNIT_SECOND : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_SAFEPOWERWINDOW))) {
if ((payload >= 0) && (payload < 1440)) {
sysCfg.hlw_msplw = (1 == payload) ? SAFE_POWER_WINDOW : payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_SAFEPOWERWINDOW "\":\"%d%s\"}"), sysCfg.hlw_msplw, (sysCfg.flag.value_units) ? " " D_UNIT_MINUTE : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SAFEPOWERWINDOW "\":\"%d%s\"}"), sysCfg.hlw_msplw, (sysCfg.flag.value_units) ? " " D_UNIT_MINUTE : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXENERGY))) {
if ((payload >= 0) && (payload < 3601)) {
sysCfg.hlw_mkwh = payload;
hlw_mkwh_state = 3;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_MAXENERGY "\":\"%d%s\"}"), sysCfg.hlw_mkwh, (sysCfg.flag.value_units) ? " " D_UNIT_WATTHOUR : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXENERGY "\":\"%d%s\"}"), sysCfg.hlw_mkwh, (sysCfg.flag.value_units) ? " " D_UNIT_WATTHOUR : "");
}
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXENERGYSTART))) {
if ((payload >= 0) && (payload < 24)) {
sysCfg.hlw_mkwhs = payload;
}
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_MAXENERGYSTART "\":\"%d%s\"}"), sysCfg.hlw_mkwhs, (sysCfg.flag.value_units) ? " " D_UNIT_HOUR : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXENERGYSTART "\":\"%d%s\"}"), sysCfg.hlw_mkwhs, (sysCfg.flag.value_units) ? " " D_UNIT_HOUR : "");
}
#endif // FEATURE_POWER_LIMIT
else {
@ -603,13 +600,13 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
}
switch (caltext) {
case 1:
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_HLWPCAL "\":\"%d%s\"}"), sysCfg.hlw_pcal, (sysCfg.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_HLWPCAL "\":\"%d%s\"}"), sysCfg.hlw_pcal, (sysCfg.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
break;
case 2:
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_HLWUCAL "\":\"%d%s\"}"), sysCfg.hlw_ucal, (sysCfg.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_HLWUCAL "\":\"%d%s\"}"), sysCfg.hlw_ucal, (sysCfg.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
break;
case 3:
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_HLWICAL "\":\"%d%s\"}"), sysCfg.hlw_ical, (sysCfg.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_HLWICAL "\":\"%d%s\"}"), sysCfg.hlw_ical, (sysCfg.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
break;
}
return serviced;
@ -619,7 +616,7 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
* Presentation
\*********************************************************************************************/
void hlw_mqttStat(byte option, char* svalue, uint16_t ssvalue)
void hlw_mqttStat(byte option)
{
/* option 0 = do not show period energy usage
* option 1 = show period energy usage
@ -651,8 +648,8 @@ void hlw_mqttStat(byte option, char* svalue, uint16_t ssvalue)
dtostrfd(pc, 2, spc);
dtostrfd((float)sysCfg.hlw_kWhyesterday / 100000000, sysCfg.flag.energy_resolution, sey);
snprintf_P(speriod, sizeof(speriod), PSTR(", \"" D_PERIOD "\":%s"), spe);
snprintf_P(svalue, ssvalue, PSTR("%s\"" D_TOTAL "\":%s, \"" D_YESTERDAY "\":%s, \"" D_TODAY "\":%s%s, \"" D_POWERUSAGE "\":%s, \"" D_POWERFACTOR "\":%s, \"" D_VOLTAGE "\":%s, \"" D_CURRENT "\":%s}"),
svalue, spet, sey, sped, (option) ? speriod : "", spw, spc, spu, spi);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"" D_TOTAL "\":%s, \"" D_YESTERDAY "\":%s, \"" D_TODAY "\":%s%s, \"" D_POWERUSAGE "\":%s, \"" D_POWERFACTOR "\":%s, \"" D_VOLTAGE "\":%s, \"" D_CURRENT "\":%s}"),
mqtt_data, spet, sey, sped, (option) ? speriod : "", spw, spc, spu, spi);
#ifdef USE_DOMOTICZ
if (option) { // Only send if telemetry
dtostrfd(pet * 1000, 1, spet);
@ -667,18 +664,16 @@ void hlw_mqttPresent(byte option)
* option 1 = show period energy usage
*/
// {"Time":"2017-03-04T13:37:24", "Total":0.013, "Yesterday":0.013, "Today":0.000, "Period":0, "Power":0, "Factor":0.00, "Voltage":0, "Current":0.000}
char svalue[200]; // was MESSZ
snprintf_P(svalue, sizeof(svalue), PSTR("{\"" D_TIME "\":\"%s\", "), getDateTime().c_str());
hlw_mqttStat(option, svalue, sizeof(svalue));
mqtt_publish_topic_P(2, PSTR(D_RSLT_ENERGY), svalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_TIME "\":\"%s\", "), getDateTime().c_str());
hlw_mqttStat(option);
mqtt_publish_topic_P(2, PSTR(D_RSLT_ENERGY));
}
void hlw_mqttStatus(char* svalue, uint16_t ssvalue)
void hlw_mqttStatus()
{
snprintf_P(svalue, ssvalue, PSTR("{\"" D_CMND_STATUS D_STATUS8_POWER "\":{"));
hlw_mqttStat(0, svalue, ssvalue);
snprintf_P(svalue, ssvalue, PSTR("%s}"), svalue);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS8_POWER "\":{"));
hlw_mqttStat(0);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
}
#ifdef USE_WEBSERVER

View File

@ -211,7 +211,6 @@ uint8_t htu_detect()
return true;
}
char log[LOGSZ];
boolean success = false;
htuaddr = HTU21_ADDR;
@ -244,8 +243,8 @@ uint8_t htu_detect()
delayH=23;
}
if (success) {
snprintf_P(log, sizeof(log), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), htustype, htuaddr);
addLog(LOG_LEVEL_DEBUG, log);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), htustype, htuaddr);
addLog(LOG_LEVEL_DEBUG);
} else {
htutype = 0;
}
@ -256,7 +255,7 @@ uint8_t htu_detect()
* Presentation
\*********************************************************************************************/
void htu_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
void htu_mqttPresent(uint8_t* djson)
{
if (!htutype) {
return;
@ -270,7 +269,7 @@ void htu_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
h = htu21_compensatedHumidity(h, t);
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp2);
snprintf_P(svalue, ssvalue, JSON_SNS_TEMPHUM, svalue, htustype, stemp1, stemp2);
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, htustype, stemp1, stemp2);
*djson = 1;
#ifdef USE_DOMOTICZ
domoticz_sensor2(stemp1, stemp2);

View File

@ -184,7 +184,7 @@ boolean sht_detect()
* Presentation
\*********************************************************************************************/
void sht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
void sht_mqttPresent(uint8_t* djson)
{
if (!shttype) {
return;
@ -199,7 +199,7 @@ void sht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp);
dtostrfd(h, sysCfg.flag.humidity_resolution, shum);
snprintf_P(svalue, ssvalue, JSON_SNS_TEMPHUM, svalue, "SHT1X", stemp, shum);
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, "SHT1X", stemp, shum);
*djson = 1;
#ifdef USE_DOMOTICZ
domoticz_sensor2(stemp, shum);