v5.8.0i - Some fixes and Add Sealevel Pressure

5.8.0i
 * Add Domoticz counter sensor to IrReceive representing Received
IR Protocol and Data
 * Fix Southern Hemisphere TIME_STD/TIME_DST
(#968)
 * Add Sea level pressure calculation (#974)
 * Fix virtual relay
status message used with Color/Dimmer control (#989)
 * Fix command
IRSend and IRHvac case sensitive parameter regression introduced with
version 5.8.0 (#993)
This commit is contained in:
arendst 2017-10-08 16:51:05 +02:00
parent 3bc7dd4e83
commit ff52288efe
14 changed files with 445 additions and 319 deletions

View File

@ -1,7 +1,7 @@
## Sonoff-Tasmota ## 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. 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.8.0h** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. Current version is **5.8.0i** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
### ATTENTION All versions ### ATTENTION All versions

View File

@ -1,6 +1,13 @@
/* 5.8.0h /* 5.8.0i
* Add Domoticz counter sensor to IrReceive representing Received IR Protocol and Data
* Fix Southern Hemisphere TIME_STD/TIME_DST (#968)
* Add Sea level pressure calculation (#974)
* Fix virtual relay status message used with Color/Dimmer control (#989)
* Fix command IRSend and IRHvac case sensitive parameter regression introduced with version 5.8.0 (#993)
*
* 5.8.0h
* Rename command IRRemote to IRSend (#956) * Rename command IRRemote to IRSend (#956)
* Add optional IR Receiver support (#956) * Add IR Receiver support. Disable in user_config.h (#956)
* Change default PWM assignment for Witty Cloud to support optional Color/Dimmer control (#976) * Change default PWM assignment for Witty Cloud to support optional Color/Dimmer control (#976)
* GPIO12 (Green) from GPIO_PWM4 to GPIO_PWM2 * GPIO12 (Green) from GPIO_PWM4 to GPIO_PWM2
* GPIO13 (Blue) from GPIO_PWM5 to GPIO_PWM3 * GPIO13 (Blue) from GPIO_PWM5 to GPIO_PWM3

View File

@ -134,6 +134,7 @@
#define D_POWERFACTOR "Factor" #define D_POWERFACTOR "Factor"
#define D_POWERUSAGE "Power" #define D_POWERUSAGE "Power"
#define D_PRESSURE "Pressure" #define D_PRESSURE "Pressure"
#define D_PRESSUREATSEALEVEL "SeaPressure"
#define D_PROGRAM_FLASH_SIZE "Program Flash Size" #define D_PROGRAM_FLASH_SIZE "Program Flash Size"
#define D_PROGRAMFLASHSIZE "ProgramFlashSize" #define D_PROGRAMFLASHSIZE "ProgramFlashSize"
#define D_PROGRAM_SIZE "Program Size" #define D_PROGRAM_SIZE "Program Size"
@ -617,6 +618,7 @@
#define D_RESET_AND_RESTARTING "Reset and Restarting" #define D_RESET_AND_RESTARTING "Reset and Restarting"
#define D_ONE_TO_RESET "1 to reset" #define D_ONE_TO_RESET "1 to reset"
#define D_CMND_TIMEZONE "Timezone" #define D_CMND_TIMEZONE "Timezone"
#define D_CMND_ALTITUDE "Altitude"
#define D_CMND_LEDPOWER "LedPower" #define D_CMND_LEDPOWER "LedPower"
#define D_CMND_LEDSTATE "LedState" #define D_CMND_LEDSTATE "LedState"
#define D_CMND_CFGDUMP "CfgDump" #define D_CMND_CFGDUMP "CfgDump"

View File

@ -134,6 +134,7 @@
#define D_POWERFACTOR "Factor" #define D_POWERFACTOR "Factor"
#define D_POWERUSAGE "Vermogen" #define D_POWERUSAGE "Vermogen"
#define D_PRESSURE "Luchtdruk" #define D_PRESSURE "Luchtdruk"
#define D_PRESSUREATSEALEVEL "ZeeLuchtdruk"
#define D_PROGRAM_FLASH_SIZE "Programma Flash Grootte" #define D_PROGRAM_FLASH_SIZE "Programma Flash Grootte"
#define D_PROGRAMFLASHSIZE "ProgrammaFlashGrootte" #define D_PROGRAMFLASHSIZE "ProgrammaFlashGrootte"
#define D_PROGRAM_SIZE "Programma Grootte" #define D_PROGRAM_SIZE "Programma Grootte"
@ -617,6 +618,7 @@
#define D_RESET_AND_RESTARTING "Reset en herstarten" #define D_RESET_AND_RESTARTING "Reset en herstarten"
#define D_ONE_TO_RESET "1 voor reset" #define D_ONE_TO_RESET "1 voor reset"
#define D_CMND_TIMEZONE "Timezone" #define D_CMND_TIMEZONE "Timezone"
#define D_CMND_ALTITUDE "Altitude"
#define D_CMND_LEDPOWER "LedPower" #define D_CMND_LEDPOWER "LedPower"
#define D_CMND_LEDSTATE "LedState" #define D_CMND_LEDSTATE "LedState"
#define D_CMND_CFGDUMP "CfgDump" #define D_CMND_CFGDUMP "CfgDump"

View File

@ -89,8 +89,9 @@ struct SYSCFG {
char ex_state_text[3][11]; // was state_text until 5.1.6, was ex_mqtt_subtopic[33] until 4.1.1 char ex_state_text[3][11]; // was state_text until 5.1.6, was ex_mqtt_subtopic[33] until 4.1.1
byte ex_mqtt_button_retain; // Not used since 5.0.2 byte ex_mqtt_button_retain; // Not used since 5.0.2
byte ex_mqtt_power_retain; // Not used since 5.0.2 byte ex_mqtt_power_retain; // Not used since 5.0.2
byte ex_value_units; // Not used since 5.0.2 //byte ex_value_units; // Not used since 5.0.2
byte ex_button_restrict; // Not used since 5.0.2 //byte ex_button_restrict; // Not used since 5.0.2
int16_t altitude; // Add since 5.8.0i
uint16_t tele_period; uint16_t tele_period;
uint8_t power; uint8_t power;

View File

@ -639,9 +639,6 @@ void CFG_Delta()
if (sysCfg.version < 0x03091500) { if (sysCfg.version < 0x03091500) {
for (byte i = 0; i < 4; i++) sysCfg.switchmode[i] = SWITCH_MODE; for (byte i = 0; i < 4; i++) sysCfg.switchmode[i] = SWITCH_MODE;
} }
if (sysCfg.version < 0x04000200) {
sysCfg.ex_button_restrict = 0;
}
if (sysCfg.version < 0x04000400) { if (sysCfg.version < 0x04000400) {
CFG_DefaultSet_4_0_4(); CFG_DefaultSet_4_0_4();
} }
@ -663,8 +660,8 @@ void CFG_Delta()
if (sysCfg.version < 0x05000105) { if (sysCfg.version < 0x05000105) {
sysCfg.flag = { 0 }; sysCfg.flag = { 0 };
sysCfg.flag.savestate = SAVE_STATE; sysCfg.flag.savestate = SAVE_STATE;
sysCfg.flag.button_restrict = sysCfg.ex_button_restrict; sysCfg.flag.button_restrict = 0;
sysCfg.flag.value_units = sysCfg.ex_value_units; sysCfg.flag.value_units = 0;
sysCfg.flag.mqtt_enabled = sysCfg.ex_mqtt_enabled; sysCfg.flag.mqtt_enabled = sysCfg.ex_mqtt_enabled;
// sysCfg.flag.mqtt_response = 0; // sysCfg.flag.mqtt_response = 0;
sysCfg.flag.mqtt_power_retain = sysCfg.ex_mqtt_power_retain; sysCfg.flag.mqtt_power_retain = sysCfg.ex_mqtt_power_retain;

View File

@ -25,11 +25,12 @@
- Select IDE Tools - Flash Size: "1M (no SPIFFS)" - Select IDE Tools - Flash Size: "1M (no SPIFFS)"
====================================================*/ ====================================================*/
#define VERSION 0x05080008 // 5.8.0h #define VERSION 0x05080009 // 5.8.0i
enum week_t {Last, First, Second, Third, Fourth}; enum week_t {Last, First, Second, Third, Fourth};
enum dow_t {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat}; enum dow_t {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
enum month_t {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec}; enum month_t {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
enum hemis_t {North, South};
enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL}; // SerialLog, Syslog, Weblog enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL}; // SerialLog, Syslog, Weblog
enum wifi_t {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, MAX_WIFI_OPTION}; // WifiConfig enum wifi_t {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, MAX_WIFI_OPTION}; // WifiConfig
enum swtch_t {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, MAX_SWITCH_OPTION}; // SwitchMode enum swtch_t {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, MAX_SWITCH_OPTION}; // SwitchMode
@ -206,6 +207,7 @@ struct TIME_T {
struct TimeChangeRule struct TimeChangeRule
{ {
uint8_t hemis; // 0-Northern, 1=Southern Hemisphere (=Opposite DST/STD)
uint8_t week; // 1=First, 2=Second, 3=Third, 4=Fourth, or 0=Last week of the month uint8_t week; // 1=First, 2=Second, 3=Third, 4=Fourth, or 0=Last week of the month
uint8_t dow; // day of week, 1=Sun, 2=Mon, ... 7=Sat uint8_t dow; // day of week, 1=Sun, 2=Mon, ... 7=Sat
uint8_t month; // 1=Jan, 2=Feb, ... 12=Dec uint8_t month; // 1=Jan, 2=Feb, ... 12=Dec
@ -1510,6 +1512,12 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
} }
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_TIMEZONE "\":%d}"), sysCfg.timezone); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_TIMEZONE "\":%d}"), sysCfg.timezone);
} }
else if (!strcasecmp_P(type, PSTR(D_CMND_ALTITUDE))) {
if ((data_len > 0) && ((payload >= -30000) && (payload <= 30000))) {
sysCfg.altitude = payload;
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_ALTITUDE "\":%d}"), sysCfg.altitude);
}
else if (!strcasecmp_P(type, PSTR(D_CMND_LEDPOWER))) { else if (!strcasecmp_P(type, PSTR(D_CMND_LEDPOWER))) {
if ((payload >= 0) && (payload <= 2)) { if ((payload >= 0) && (payload <= 2)) {
sysCfg.ledstate &= 8; sysCfg.ledstate &= 8;

View File

@ -1086,8 +1086,13 @@ void rtc_second()
loctime = utctime; loctime = utctime;
if (loctime > 1451602800) { // 2016-01-01 if (loctime > 1451602800) { // 2016-01-01
if (99 == sysCfg.timezone) { if (99 == sysCfg.timezone) {
dstoffset = myDST.offset * SECS_PER_MIN; if (myDST.hemis) {
dstoffset = mySTD.offset * SECS_PER_MIN; // Southern hemisphere
stdoffset = myDST.offset * SECS_PER_MIN;
} else {
dstoffset = myDST.offset * SECS_PER_MIN; // Northern hemisphere
stdoffset = mySTD.offset * SECS_PER_MIN; stdoffset = mySTD.offset * SECS_PER_MIN;
}
if ((utctime >= (dsttime - stdoffset)) && (utctime < (stdtime - dstoffset))) { if ((utctime >= (dsttime - stdoffset)) && (utctime < (stdtime - dstoffset))) {
loctime += dstoffset; // Daylight Saving Time loctime += dstoffset; // Daylight Saving Time
} else { } else {

View File

@ -131,10 +131,10 @@
#define NTP_SERVER3 "0.nl.pool.ntp.org" // [NtpServer3] Select third NTP server by name or IP address (93.94.224.67) #define NTP_SERVER3 "0.nl.pool.ntp.org" // [NtpServer3] Select third NTP server by name or IP address (93.94.224.67)
// -- Time - Start Daylight Saving Time and timezone offset from UTC in minutes // -- Time - Start Daylight Saving Time and timezone offset from UTC in minutes
#define TIME_DST Last, Sun, Mar, 2, +120 // Last sunday in march at 02:00 +120 minutes #define TIME_DST North, Last, Sun, Mar, 2, +120 // Northern Hemisphere, Last sunday in march at 02:00 +120 minutes
// -- Time - Start Standard Time and timezone offset from UTC in minutes // -- Time - Start Standard Time and timezone offset from UTC in minutes
#define TIME_STD Last, Sun, Oct, 3, +60 // Last sunday in october 02:00 +60 minutes #define TIME_STD North, Last, Sun, Oct, 3, +60 // Northern Hemisphere, Last sunday in october 02:00 +60 minutes
// -- Application --------------------------------- // -- Application ---------------------------------
#define APP_TIMEZONE 1 // [Timezone] +1 hour (Amsterdam) (-12 .. 12 = hours from UTC, 99 = use TIME_DST/TIME_STD) #define APP_TIMEZONE 1 // [Timezone] +1 hour (Amsterdam) (-12 .. 12 = hours from UTC, 99 = use TIME_DST/TIME_STD)

View File

@ -270,6 +270,8 @@ const char HTTP_SNS_HUM[] PROGMEM =
"<tr><th>%s " D_HUMIDITY "</th><td>%s%</td></tr>"; "<tr><th>%s " D_HUMIDITY "</th><td>%s%</td></tr>";
const char HTTP_SNS_PRESSURE[] PROGMEM = const char HTTP_SNS_PRESSURE[] PROGMEM =
"<tr><th>%s " D_PRESSURE "</th><td>%s " D_UNIT_PRESSURE "</td></tr>"; "<tr><th>%s " D_PRESSURE "</th><td>%s " D_UNIT_PRESSURE "</td></tr>";
const char HTTP_SNS_PRESSUREATSEALEVEL[] PROGMEM =
"<tr><th>%s " D_PRESSUREATSEALEVEL "</th><td>%s " D_UNIT_PRESSURE "</td></tr>";
const char HTTP_SNS_LIGHT[] PROGMEM = const char HTTP_SNS_LIGHT[] PROGMEM =
"<tr><th>%s " D_LIGHT "</th><td>%d%</td></tr>"; "<tr><th>%s " D_LIGHT "</th><td>%d%</td></tr>";
const char HTTP_SNS_NOISE[] PROGMEM = const char HTTP_SNS_NOISE[] PROGMEM =

View File

@ -43,6 +43,10 @@
const char HVACMODE[] = "HDCA"; const char HVACMODE[] = "HDCA";
#endif #endif
/*********************************************************************************************\
* IR Send
\*********************************************************************************************/
IRsend *irsend = NULL; IRsend *irsend = NULL;
void ir_send_init(void) void ir_send_init(void)
@ -56,6 +60,10 @@ void ir_send_init(void)
} }
#ifdef USE_IR_RECEIVE #ifdef USE_IR_RECEIVE
/*********************************************************************************************\
* IR Receive
\*********************************************************************************************/
#define IR_TIME_AVOID_DUPLICATE 500 // Milliseconds #define IR_TIME_AVOID_DUPLICATE 500 // Milliseconds
IRrecv *irrecv = NULL; IRrecv *irrecv = NULL;
@ -65,106 +73,59 @@ void ir_recv_init(void)
{ {
irrecv = new IRrecv(pin[GPIO_IRRECV]); // an IR led is at GPIO_IRRECV irrecv = new IRrecv(pin[GPIO_IRRECV]); // an IR led is at GPIO_IRRECV
irrecv->enableIRIn(); // Start the receiver irrecv->enableIRIn(); // Start the receiver
// addLog_P(LOG_LEVEL_DEBUG, PSTR("IrReceive initialized")); // addLog_P(LOG_LEVEL_DEBUG, PSTR("IrReceive initialized"));
} }
void ir_recv_check()
{
char sirtype[100];
char *protocol;
int8_t iridx = 0;
decode_results results;
if (irrecv->decode(&results)) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_IRR "RawLen %d, Bits %d, Value %08X, Decode %d"),
results.rawlen, results.bits, results.value, results.decode_type);
addLog(LOG_LEVEL_DEBUG);
unsigned long now = millis();
if ((now - ir_lasttime > IR_TIME_AVOID_DUPLICATE) && (UNKNOWN != results.decode_type) && (results.bits > 0)) {
ir_lasttime = now;
iridx = results.decode_type;
if ((iridx < 0) || (iridx > 14)) {
iridx = 0;
}
// Based on IRremoteESP8266.h enum decode_type_t
snprintf_P(sirtype, sizeof(sirtype), PSTR("UNKNOWN RC5 RC6 NEC SONY PANASONIC JVC SAMSUNG WHYNTER AIWA_RC_T501 LG SANYO MITSUBISHI DISH SHARP"));
protocol = strtok(sirtype, " ");
while (iridx) {
iridx--;
protocol = strtok(NULL, " ");
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_IRRECEIVED "\":{\"" D_IR_PROTOCOL "\":\"%s\", \"" D_IR_BITS "\":%d, \"" D_IR_DATA "\":\"%X\"}}"),
protocol, results.bits, results.value);
mqtt_publish_topic_P(6, PSTR(D_IRRECEIVED));
#ifdef USE_DOMOTICZ
unsigned long value = results.value | (iridx << 28); // [Protocol:4, Data:28]
domoticz_sensor(DZ_COUNT, value); // Send data as Domoticz Counter value
#endif // USE_DOMOTICZ
}
irrecv->resume();
}
}
#endif // USE_IR_RECEIVE #endif // USE_IR_RECEIVE
#ifdef USE_IR_HVAC
/*********************************************************************************************\ /*********************************************************************************************\
* Commands * IR Heating, Ventilation and Air Conditioning using IRMitsubishiAC library
\*********************************************************************************************/ \*********************************************************************************************/
/*
* ArduinoJSON entry used to calculate jsonBuf: JSON_OBJECT_SIZE(3) + 40 = 96
IRsend:
{ "protocol": "SAMSUNG", "bits": 32, "data": 551502015 }
IRhvac:
{ "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 *dataBuf, uint16_t data_len, int16_t payload)
{
boolean serviced = true;
boolean error = false;
const char *protocol;
uint8_t bits = 0;
uint32_t data = 0;
const char *HVAC_Mode;
const char *HVAC_FanMode;
const char *HVAC_Vendor;
int HVAC_Temp = 21;
boolean HVAC_Power = true;
if (!strcasecmp_P(type, PSTR(D_CMND_IRSEND))) {
if (data_len) {
StaticJsonBuffer<128> jsonBuf;
JsonObject &ir_json = jsonBuf.parseObject(dataBuf);
if (!ir_json.success()) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_INVALID_JSON "\"}")); // JSON decode failed
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_DONE "\"}"));
protocol = ir_json[D_IR_PROTOCOL];
bits = ir_json[D_IR_BITS];
data = ir_json[D_IR_DATA];
if (protocol && bits && data) {
if (!strcasecmp_P(protocol, PSTR("NEC"))) irsend->sendNEC(data, bits);
else if (!strcasecmp_P(protocol, PSTR("SONY"))) irsend->sendSony(data, bits);
else if (!strcasecmp_P(protocol, PSTR("RC5"))) irsend->sendRC5(data, bits);
else if (!strcasecmp_P(protocol, PSTR("RC6"))) irsend->sendRC6(data, bits);
else if (!strcasecmp_P(protocol, PSTR("DISH"))) irsend->sendDISH(data, bits);
else if (!strcasecmp_P(protocol, PSTR("JVC"))) irsend->sendJVC(data, bits, 1);
else if (!strcasecmp_P(protocol, PSTR("SAMSUNG"))) irsend->sendSAMSUNG(data, bits);
else {
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(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_NO " " D_IR_PROTOCOL ", " D_IR_BITS " " D_OR " " D_IR_DATA "\"}"));
}
}
#ifdef USE_IR_HVAC
else if (!strcasecmp_P(type, PSTR(D_CMND_IRHVAC))) {
if (data_len) {
StaticJsonBuffer<164> jsonBufer;
JsonObject &root = jsonBufer.parseObject(dataBuf);
if (!root.success()) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRHVAC "\":\"" D_INVALID_JSON "\"}")); // JSON decode failed
} else {
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_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);
if (HVAC_Vendor == NULL || !strcasecmp_P(HVAC_Vendor, PSTR("TOSHIBA"))) {
error = ir_hvac_toshiba(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
}
else if (!strcasecmp_P(HVAC_Vendor, PSTR("MITSUBISHI"))) {
error = ir_hvac_mitsubishi(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
}
else error = true;
}
} else error = true;
if (error) {
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
else {
serviced = false; // Unknown command
}
return serviced;
}
#ifdef USE_IR_HVAC
boolean ir_hvac_toshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) boolean ir_hvac_toshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
{ {
unsigned int rawdata[2 + 2 * 8 * HVAC_TOSHIBA_DATALEN + 2]; unsigned int rawdata[2 + 2 * 8 * HVAC_TOSHIBA_DATALEN + 2];
@ -176,7 +137,8 @@ boolean ir_hvac_toshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean
if (HVAC_Mode == NULL) { if (HVAC_Mode == NULL) {
p = (char *)HVACMODE; // default HVAC_HOT p = (char *)HVACMODE; // default HVAC_HOT
} else { }
else {
p = strchr(HVACMODE, toupper(HVAC_Mode[0])); p = strchr(HVACMODE, toupper(HVAC_Mode[0]));
} }
if (!p) { if (!p) {
@ -190,7 +152,8 @@ boolean ir_hvac_toshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean
if (HVAC_FanMode == NULL) { if (HVAC_FanMode == NULL) {
p = (char *)FANSPEED; // default FAN_SPEED_AUTO p = (char *)FANSPEED; // default FAN_SPEED_AUTO
} else { }
else {
p = strchr(FANSPEED, toupper(HVAC_FanMode[0])); p = strchr(FANSPEED, toupper(HVAC_FanMode[0]));
} }
if (!p) { if (!p) {
@ -263,7 +226,8 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode,const char *HVAC_FanMode, boole
if (HVAC_Mode == NULL) { if (HVAC_Mode == NULL) {
p = (char *)HVACMODE; // default HVAC_HOT p = (char *)HVACMODE; // default HVAC_HOT
} else { }
else {
p = strchr(HVACMODE, toupper(HVAC_Mode[0])); p = strchr(HVACMODE, toupper(HVAC_Mode[0]));
} }
if (!p) { if (!p) {
@ -276,7 +240,8 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode,const char *HVAC_FanMode, boole
if (HVAC_FanMode == NULL) { if (HVAC_FanMode == NULL) {
p = (char *)FANSPEED; // default FAN_SPEED_AUTO p = (char *)FANSPEED; // default FAN_SPEED_AUTO
} else { }
else {
p = strchr(FANSPEED, toupper(HVAC_FanMode[0])); p = strchr(FANSPEED, toupper(HVAC_FanMode[0]));
} }
if (!p) { if (!p) {
@ -297,38 +262,122 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode,const char *HVAC_FanMode, boole
} }
#endif // USE_IR_HVAC #endif // USE_IR_HVAC
#ifdef USE_IR_RECEIVE /*********************************************************************************************\
void ir_recv_check() * Commands
{ \*********************************************************************************************/
char sirtype[100];
char *protocol;
int8_t iridx = 0;
decode_results results; /*
if (irrecv->decode(&results)) { * ArduinoJSON entry used to calculate jsonBuf: JSON_OBJECT_SIZE(3) + 40 = 96
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_IRR "RawLen %d, Bits %d, Value %08X, Decode %d"), IRsend:
results.rawlen, results.bits, results.value, results.decode_type); { "protocol": "SAMSUNG", "bits": 32, "data": 551502015 }
addLog(LOG_LEVEL_DEBUG);
unsigned long now = millis(); IRhvac:
if ((now - ir_lasttime > IR_TIME_AVOID_DUPLICATE) && (UNKNOWN != results.decode_type) && (results.bits > 0)) { { "Vendor": "<Toshiba|Mitsubishi>", "Power": <0|1>, "Mode": "<Hot|Cold|Dry|Auto>", "FanSpeed": "<1|2|3|4|5|Auto|Silence>", "Temp": <17..30> }
ir_lasttime = now; */
iridx = results.decode_type;
if ((iridx < 0) || (iridx > 14)) { boolean ir_send_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
iridx = 0; {
boolean serviced = true;
boolean error = false;
char dataBufUc[data_len];
const char *protocol;
uint8_t bits = 0;
uint32_t data = 0;
const char *HVAC_Mode;
const char *HVAC_FanMode;
const char *HVAC_Vendor;
int HVAC_Temp = 21;
boolean HVAC_Power = true;
for (uint16_t i = 0; i <= sizeof(dataBufUc); i++) {
dataBufUc[i] = toupper(dataBuf[i]);
} }
// Based on IRremoteESP8266.h enum decode_type_t if (!strcasecmp_P(type, PSTR(D_CMND_IRSEND))) {
snprintf_P(sirtype, sizeof(sirtype), PSTR("UNKNOWN RC5 RC6 NEC SONY PANASONIC JVC SAMSUNG WHYNTER AIWA_RC_T501 LG SANYO MITSUBISHI DISH SHARP")); if (data_len) {
protocol = strtok(sirtype, " "); StaticJsonBuffer<128> jsonBuf;
while (iridx) { JsonObject &ir_json = jsonBuf.parseObject(dataBufUc);
iridx--; if (!ir_json.success()) {
protocol = strtok(NULL, " "); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_INVALID_JSON "\"}")); // JSON decode failed
} }
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_IRRECEIVED "\":{\"" D_IR_PROTOCOL "\":\"%s\", \"" D_IR_BITS "\":%d, \"" D_IR_DATA "\":\"%X\"}}"), else {
protocol, results.bits, results.value); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_DONE "\"}"));
mqtt_publish_topic_P(6, PSTR(D_IRRECEIVED)); protocol = ir_json[D_IR_PROTOCOL];
} bits = ir_json[D_IR_BITS];
irrecv->resume(); data = ir_json[D_IR_DATA];
if (protocol && bits && data) {
if (!strcasecmp_P(protocol, PSTR("NEC")))
irsend->sendNEC(data, bits);
else if (!strcasecmp_P(protocol, PSTR("SONY")))
irsend->sendSony(data, bits);
else if (!strcasecmp_P(protocol, PSTR("RC5")))
irsend->sendRC5(data, bits);
else if (!strcasecmp_P(protocol, PSTR("RC6")))
irsend->sendRC6(data, bits);
else if (!strcasecmp_P(protocol, PSTR("DISH")))
irsend->sendDISH(data, bits);
else if (!strcasecmp_P(protocol, PSTR("JVC")))
irsend->sendJVC(data, bits, 1);
else if (!strcasecmp_P(protocol, PSTR("SAMSUNG")))
irsend->sendSAMSUNG(data, bits);
else {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_PROTOCOL_NOT_SUPPORTED "\"}"));
} }
} }
#endif // USE_IR_RECEIVE else {
error = true;
}
}
}
else {
error = true;
}
if (error) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_NO " " D_IR_PROTOCOL ", " D_IR_BITS " " D_OR " " D_IR_DATA "\"}"));
}
}
#ifdef USE_IR_HVAC
else if (!strcasecmp_P(type, PSTR(D_CMND_IRHVAC))) {
if (data_len) {
StaticJsonBuffer<164> jsonBufer;
JsonObject &root = jsonBufer.parseObject(dataBufUc);
if (!root.success()) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRHVAC "\":\"" D_INVALID_JSON "\"}")); // JSON decode failed
}
else {
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_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);
if (HVAC_Vendor == NULL || !strcasecmp_P(HVAC_Vendor, PSTR("TOSHIBA"))) {
error = ir_hvac_toshiba(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
}
else if (!strcasecmp_P(HVAC_Vendor, PSTR("MITSUBISHI"))) {
error = ir_hvac_mitsubishi(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
}
else {
error = true;
}
}
}
else {
error = true;
}
if (error) {
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
else {
serviced = false; // Unknown command
}
return serviced;
}
#endif // USE_IR_REMOTE #endif // USE_IR_REMOTE

View File

@ -294,6 +294,7 @@ char* sl_getColor(char* scolor)
void sl_prepPower() void sl_prepPower()
{ {
char scolor[11]; char scolor[11];
char scommand[16];
if (sysCfg.led_dimmer && !(sl_power)) { if (sysCfg.led_dimmer && !(sl_power)) {
do_cmnd_power(Maxdevice, 7); // No publishPowerState do_cmnd_power(Maxdevice, 7); // No publishPowerState
@ -305,12 +306,14 @@ void sl_prepPower()
// mqtt_publishDomoticzPowerState(1); // mqtt_publishDomoticzPowerState(1);
domoticz_updatePowerState(Maxdevice); domoticz_updatePowerState(Maxdevice);
#endif // USE_DOMOTICZ #endif // USE_DOMOTICZ
getPowerDevice(scommand, Maxdevice, sizeof(scommand));
if ((sfl_flg &7) > 1) { if ((sfl_flg &7) > 1) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_RSLT_POWER "\":\"%s\", \"" D_CMND_DIMMER "\":%d, \"" D_CMND_COLOR "\":\"%s\"}"), snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%s\", \"" D_CMND_DIMMER "\":%d, \"" D_CMND_COLOR "\":\"%s\"}"),
getStateText(sl_power), sysCfg.led_dimmer, sl_getColor(scolor)); scommand, getStateText(sl_power), sysCfg.led_dimmer, sl_getColor(scolor));
} else { } else {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_RSLT_POWER "\":\"%s\", \"" D_CMND_DIMMER "\":%d}"), snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%s\", \"" D_CMND_DIMMER "\":%d}"),
getStateText(sl_power), sysCfg.led_dimmer); scommand, getStateText(sl_power), sysCfg.led_dimmer);
} }
} }

View File

@ -33,14 +33,13 @@
#define BMP_REGISTER_CHIPID 0xD0 #define BMP_REGISTER_CHIPID 0xD0
double bmp_sealevel = 0.0;
uint8_t bmpaddr; uint8_t bmpaddr;
uint8_t bmptype = 0; uint8_t bmptype = 0;
char bmpstype[7]; char bmpstype[7];
/*********************************************************************************************\ /*********************************************************************************************\
* BMP085 and BME180 * BMP085 and BME180
*
* Programmer : Heiko Krupp with changes from Theo Arends
\*********************************************************************************************/ \*********************************************************************************************/
#define BMP180_REG_CONTROL 0xF4 #define BMP180_REG_CONTROL 0xF4
@ -104,7 +103,6 @@ boolean bmp180_calibration()
(cal_md == 0xFFFF)) { (cal_md == 0xFFFF)) {
return false; return false;
} }
return true; return true;
} }
@ -146,7 +144,8 @@ double bmp180_readPressure()
if (b7 < 0x80000000) { if (b7 < 0x80000000) {
p = (b7 * 2) / b4; p = (b7 * 2) / b4;
} else { }
else {
p = (b7 / b4) * 2; p = (b7 / b4) * 2;
} }
@ -282,7 +281,8 @@ double bmp280_readTemperature(void)
var1 = ((((adc_T >> 3) - ((int32_t)_bme280_calib.dig_T1 << 1))) * ((int32_t)_bme280_calib.dig_T2)) >> 11; var1 = ((((adc_T >> 3) - ((int32_t)_bme280_calib.dig_T1 << 1))) * ((int32_t)_bme280_calib.dig_T2)) >> 11;
var2 = (((((adc_T >> 4) - ((int32_t)_bme280_calib.dig_T1)) * ((adc_T >> 4) - ((int32_t)_bme280_calib.dig_T1))) >> 12) * var2 = (((((adc_T >> 4) - ((int32_t)_bme280_calib.dig_T1)) * ((adc_T >> 4) - ((int32_t)_bme280_calib.dig_T1))) >> 12) *
((int32_t)_bme280_calib.dig_T3)) >> 14; ((int32_t)_bme280_calib.dig_T3)) >>
14;
t_fine = var1 + var2; t_fine = var1 + var2;
double T = (t_fine * 5 + 128) >> 8; double T = (t_fine * 5 + 128) >> 8;
return T / 100.0; return T / 100.0;
@ -329,12 +329,19 @@ double bme280_readHumidity(void)
v_x1_u32r = (t_fine - ((int32_t)76800)); v_x1_u32r = (t_fine - ((int32_t)76800));
v_x1_u32r = (((((adc_H << 14) - (((int32_t)_bme280_calib.dig_H4) << 20) - v_x1_u32r = (((((adc_H << 14) - (((int32_t)_bme280_calib.dig_H4) << 20) -
(((int32_t)_bme280_calib.dig_H5) * v_x1_u32r)) + ((int32_t)16384)) >> 15) * (((int32_t)_bme280_calib.dig_H5) * v_x1_u32r)) +
((int32_t)16384)) >>
15) *
(((((((v_x1_u32r * ((int32_t)_bme280_calib.dig_H6)) >> 10) * (((((((v_x1_u32r * ((int32_t)_bme280_calib.dig_H6)) >> 10) *
(((v_x1_u32r * ((int32_t)_bme280_calib.dig_H3)) >> 11) + ((int32_t)32768))) >> 10) + (((v_x1_u32r * ((int32_t)_bme280_calib.dig_H3)) >> 11) + ((int32_t)32768))) >>
((int32_t)2097152)) * ((int32_t)_bme280_calib.dig_H2) + 8192) >> 14)); 10) +
((int32_t)2097152)) *
((int32_t)_bme280_calib.dig_H2) +
8192) >>
14));
v_x1_u32r = (v_x1_u32r - (((((v_x1_u32r >> 15) * (v_x1_u32r >> 15)) >> 7) * v_x1_u32r = (v_x1_u32r - (((((v_x1_u32r >> 15) * (v_x1_u32r >> 15)) >> 7) *
((int32_t)_bme280_calib.dig_H1)) >> 4)); ((int32_t)_bme280_calib.dig_H1)) >>
4));
v_x1_u32r = (v_x1_u32r < 0) ? 0 : v_x1_u32r; v_x1_u32r = (v_x1_u32r < 0) ? 0 : v_x1_u32r;
v_x1_u32r = (v_x1_u32r > 419430400) ? 419430400 : v_x1_u32r; v_x1_u32r = (v_x1_u32r > 419430400) ? 419430400 : v_x1_u32r;
double h = (v_x1_u32r >> 12); double h = (v_x1_u32r >> 12);
@ -345,11 +352,36 @@ double bme280_readHumidity(void)
* BMP * BMP
\*********************************************************************************************/ \*********************************************************************************************/
double fastPrecisePow(double a, double b)
{
// https://martin.ankerl.com/2012/01/25/optimized-approximative-pow-in-c-and-cpp/
// calculate approximation with fraction of the exponent
int e = (int)b;
union {
double d;
int x[2];
} u = { a };
u.x[1] = (int)((b - e) * (u.x[1] - 1072632447) + 1072632447);
u.x[0] = 0;
// exponentiation by squaring with the exponent's integer part
// double r = u.d makes everything much slower, not sure why
double r = 1.0;
while (e) {
if (e & 1) {
r *= a;
}
a *= a;
e >>= 1;
}
return r * u.d;
}
double bmp_readTemperature(void) double bmp_readTemperature(void)
{ {
double t = NAN; double t = NAN;
switch (bmptype) { switch (bmptype)
{
case BMP180_CHIPID: case BMP180_CHIPID:
t = bmp180_readTemperature(); t = bmp180_readTemperature();
break; break;
@ -357,7 +389,8 @@ double bmp_readTemperature(void)
case BME280_CHIPID: case BME280_CHIPID:
t = bmp280_readTemperature(); t = bmp280_readTemperature();
} }
if (!isnan(t)) { if (!isnan(t))
{
t = convertTemp(t); t = convertTemp(t);
return t; return t;
} }
@ -366,14 +399,20 @@ double bmp_readTemperature(void)
double bmp_readPressure(void) double bmp_readPressure(void)
{ {
double pressure = 0.0;
switch (bmptype) { switch (bmptype) {
case BMP180_CHIPID: case BMP180_CHIPID:
return bmp180_readPressure(); pressure = bmp180_readPressure();
case BMP280_CHIPID: case BMP280_CHIPID:
case BME280_CHIPID: case BME280_CHIPID:
return bmp280_readPressure(); pressure = bmp280_readPressure();
} }
return 0; if (pressure != 0.0) {
// bmp_sealevel = pressure / pow(1.0 - ((float)sysCfg.altitude / 44330.0), 5.255); // Adds 8k to the code
bmp_sealevel = (pressure / fastPrecisePow(1.0 - ((float)sysCfg.altitude / 44330.0), 5.255)) - 21.6;
}
return pressure;
} }
double bmp_readHumidity(void) double bmp_readHumidity(void)
@ -419,7 +458,8 @@ boolean bmp_detect()
if (success) { if (success) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bmpstype, bmpaddr); snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bmpstype, bmpaddr);
addLog(LOG_LEVEL_DEBUG); addLog(LOG_LEVEL_DEBUG);
} else { }
else {
bmptype = 0; bmptype = 0;
} }
return success; return success;
@ -438,6 +478,8 @@ void bmp_mqttPresent(uint8_t* djson)
char stemp1[10]; char stemp1[10];
char stemp2[10]; char stemp2[10];
char stemp3[10]; char stemp3[10];
char stemp4[10];
char sealevel[40];
double t = bmp_readTemperature(); double t = bmp_readTemperature();
double p = bmp_readPressure(); double p = bmp_readPressure();
@ -445,12 +487,16 @@ void bmp_mqttPresent(uint8_t* djson)
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1); dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
dtostrfd(p, sysCfg.flag.pressure_resolution, stemp2); dtostrfd(p, sysCfg.flag.pressure_resolution, stemp2);
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp3); dtostrfd(h, sysCfg.flag.humidity_resolution, stemp3);
dtostrfd(bmp_sealevel, sysCfg.flag.pressure_resolution, stemp4);
snprintf_P(sealevel, sizeof(sealevel), PSTR(", \"" D_PRESSUREATSEALEVEL "\":%s"), stemp4);
if (!strcmp(bmpstype, "BME280")) { if (!strcmp(bmpstype, "BME280")) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s, \"" D_PRESSURE "\":%s}"), snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s, \"" D_PRESSURE "\":%s%s}"),
mqtt_data, bmpstype, stemp1, stemp3, stemp2); mqtt_data, bmpstype, stemp1, stemp3, stemp2, (sysCfg.altitude != 0) ? sealevel : "");
} else { }
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_PRESSURE "\":%s}"), else {
mqtt_data, bmpstype, stemp1, stemp2); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_PRESSURE "\":%s%s}"),
mqtt_data, bmpstype, stemp1, stemp2, (sysCfg.altitude != 0) ? sealevel : "");
} }
*djson = 1; *djson = 1;
#ifdef USE_DOMOTICZ #ifdef USE_DOMOTICZ
@ -480,10 +526,14 @@ String bmp_webPresent()
dtostrfi(p_bmp, sysCfg.flag.pressure_resolution, stemp); dtostrfi(p_bmp, sysCfg.flag.pressure_resolution, stemp);
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSURE, bmpstype, stemp); snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSURE, bmpstype, stemp);
page += sensor; page += sensor;
if (sysCfg.altitude != 0) {
dtostrfi(bmp_sealevel, sysCfg.flag.pressure_resolution, stemp);
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSUREATSEALEVEL, bmpstype, stemp);
page += sensor;
}
} }
return page; return page;
} }
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
#endif // USE_BMP #endif // USE_BMP
#endif // USE_I2C #endif // USE_I2C