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
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

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)
* 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)
* GPIO12 (Green) from GPIO_PWM4 to GPIO_PWM2
* GPIO13 (Blue) from GPIO_PWM5 to GPIO_PWM3

View File

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

View File

@ -134,6 +134,7 @@
#define D_POWERFACTOR "Factor"
#define D_POWERUSAGE "Vermogen"
#define D_PRESSURE "Luchtdruk"
#define D_PRESSUREATSEALEVEL "ZeeLuchtdruk"
#define D_PROGRAM_FLASH_SIZE "Programma Flash Grootte"
#define D_PROGRAMFLASHSIZE "ProgrammaFlashGrootte"
#define D_PROGRAM_SIZE "Programma Grootte"
@ -617,6 +618,7 @@
#define D_RESET_AND_RESTARTING "Reset en herstarten"
#define D_ONE_TO_RESET "1 voor reset"
#define D_CMND_TIMEZONE "Timezone"
#define D_CMND_ALTITUDE "Altitude"
#define D_CMND_LEDPOWER "LedPower"
#define D_CMND_LEDSTATE "LedState"
#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
byte ex_mqtt_button_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_button_restrict; // 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
int16_t altitude; // Add since 5.8.0i
uint16_t tele_period;
uint8_t power;

View File

@ -639,9 +639,6 @@ void CFG_Delta()
if (sysCfg.version < 0x03091500) {
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) {
CFG_DefaultSet_4_0_4();
}
@ -663,8 +660,8 @@ void CFG_Delta()
if (sysCfg.version < 0x05000105) {
sysCfg.flag = { 0 };
sysCfg.flag.savestate = SAVE_STATE;
sysCfg.flag.button_restrict = sysCfg.ex_button_restrict;
sysCfg.flag.value_units = sysCfg.ex_value_units;
sysCfg.flag.button_restrict = 0;
sysCfg.flag.value_units = 0;
sysCfg.flag.mqtt_enabled = sysCfg.ex_mqtt_enabled;
// sysCfg.flag.mqtt_response = 0;
sysCfg.flag.mqtt_power_retain = sysCfg.ex_mqtt_power_retain;

View File

@ -25,11 +25,12 @@
- 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 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 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 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
@ -206,6 +207,7 @@ struct TIME_T {
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 dow; // day of week, 1=Sun, 2=Mon, ... 7=Sat
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);
}
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))) {
if ((payload >= 0) && (payload <= 2)) {
sysCfg.ledstate &= 8;

View File

@ -1086,8 +1086,13 @@ void rtc_second()
loctime = utctime;
if (loctime > 1451602800) { // 2016-01-01
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;
}
if ((utctime >= (dsttime - stdoffset)) && (utctime < (stdtime - dstoffset))) {
loctime += dstoffset; // Daylight Saving Time
} 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)
// -- 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
#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 ---------------------------------
#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>";
const char HTTP_SNS_PRESSURE[] PROGMEM =
"<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 =
"<tr><th>%s " D_LIGHT "</th><td>%d%</td></tr>";
const char HTTP_SNS_NOISE[] PROGMEM =

View File

@ -43,6 +43,10 @@
const char HVACMODE[] = "HDCA";
#endif
/*********************************************************************************************\
* IR Send
\*********************************************************************************************/
IRsend *irsend = NULL;
void ir_send_init(void)
@ -56,6 +60,10 @@ void ir_send_init(void)
}
#ifdef USE_IR_RECEIVE
/*********************************************************************************************\
* IR Receive
\*********************************************************************************************/
#define IR_TIME_AVOID_DUPLICATE 500 // Milliseconds
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->enableIRIn(); // Start the receiver
// 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
#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)
{
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) {
p = (char *)HVACMODE; // default HVAC_HOT
} else {
}
else {
p = strchr(HVACMODE, toupper(HVAC_Mode[0]));
}
if (!p) {
@ -190,7 +152,8 @@ boolean ir_hvac_toshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean
if (HVAC_FanMode == NULL) {
p = (char *)FANSPEED; // default FAN_SPEED_AUTO
} else {
}
else {
p = strchr(FANSPEED, toupper(HVAC_FanMode[0]));
}
if (!p) {
@ -263,7 +226,8 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode,const char *HVAC_FanMode, boole
if (HVAC_Mode == NULL) {
p = (char *)HVACMODE; // default HVAC_HOT
} else {
}
else {
p = strchr(HVACMODE, toupper(HVAC_Mode[0]));
}
if (!p) {
@ -276,7 +240,8 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode,const char *HVAC_FanMode, boole
if (HVAC_FanMode == NULL) {
p = (char *)FANSPEED; // default FAN_SPEED_AUTO
} else {
}
else {
p = strchr(FANSPEED, toupper(HVAC_FanMode[0]));
}
if (!p) {
@ -297,38 +262,122 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode,const char *HVAC_FanMode, boole
}
#endif // USE_IR_HVAC
#ifdef USE_IR_RECEIVE
void ir_recv_check()
{
char sirtype[100];
char *protocol;
int8_t iridx = 0;
/*********************************************************************************************\
* Commands
\*********************************************************************************************/
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;
/*
* 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;
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
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, " ");
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(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\"}}"),
protocol, results.bits, results.value);
mqtt_publish_topic_P(6, PSTR(D_IRRECEIVED));
}
irrecv->resume();
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 "\"}"));
}
}
#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

View File

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

View File

@ -33,14 +33,13 @@
#define BMP_REGISTER_CHIPID 0xD0
double bmp_sealevel = 0.0;
uint8_t bmpaddr;
uint8_t bmptype = 0;
char bmpstype[7];
/*********************************************************************************************\
* BMP085 and BME180
*
* Programmer : Heiko Krupp with changes from Theo Arends
\*********************************************************************************************/
#define BMP180_REG_CONTROL 0xF4
@ -104,7 +103,6 @@ boolean bmp180_calibration()
(cal_md == 0xFFFF)) {
return false;
}
return true;
}
@ -146,7 +144,8 @@ double bmp180_readPressure()
if (b7 < 0x80000000) {
p = (b7 * 2) / b4;
} else {
}
else {
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;
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;
double T = (t_fine * 5 + 128) >> 8;
return T / 100.0;
@ -329,12 +329,19 @@ double bme280_readHumidity(void)
v_x1_u32r = (t_fine - ((int32_t)76800));
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_H3)) >> 11) + ((int32_t)32768))) >> 10) +
((int32_t)2097152)) * ((int32_t)_bme280_calib.dig_H2) + 8192) >> 14));
(((v_x1_u32r * ((int32_t)_bme280_calib.dig_H3)) >> 11) + ((int32_t)32768))) >>
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) *
((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 > 419430400) ? 419430400 : v_x1_u32r;
double h = (v_x1_u32r >> 12);
@ -345,11 +352,36 @@ double bme280_readHumidity(void)
* 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 t = NAN;
switch (bmptype) {
switch (bmptype)
{
case BMP180_CHIPID:
t = bmp180_readTemperature();
break;
@ -357,7 +389,8 @@ double bmp_readTemperature(void)
case BME280_CHIPID:
t = bmp280_readTemperature();
}
if (!isnan(t)) {
if (!isnan(t))
{
t = convertTemp(t);
return t;
}
@ -366,14 +399,20 @@ double bmp_readTemperature(void)
double bmp_readPressure(void)
{
double pressure = 0.0;
switch (bmptype) {
case BMP180_CHIPID:
return bmp180_readPressure();
pressure = bmp180_readPressure();
case BMP280_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)
@ -419,7 +458,8 @@ boolean bmp_detect()
if (success) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bmpstype, bmpaddr);
addLog(LOG_LEVEL_DEBUG);
} else {
}
else {
bmptype = 0;
}
return success;
@ -438,6 +478,8 @@ void bmp_mqttPresent(uint8_t* djson)
char stemp1[10];
char stemp2[10];
char stemp3[10];
char stemp4[10];
char sealevel[40];
double t = bmp_readTemperature();
double p = bmp_readPressure();
@ -445,12 +487,16 @@ void bmp_mqttPresent(uint8_t* djson)
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
dtostrfd(p, sysCfg.flag.pressure_resolution, stemp2);
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")) {
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(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_PRESSURE "\":%s}"),
mqtt_data, bmpstype, stemp1, stemp2);
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, (sysCfg.altitude != 0) ? sealevel : "");
}
else {
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;
#ifdef USE_DOMOTICZ
@ -480,10 +526,14 @@ String bmp_webPresent()
dtostrfi(p_bmp, sysCfg.flag.pressure_resolution, stemp);
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSURE, bmpstype, stemp);
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;
}
#endif // USE_WEBSERVER
#endif // USE_BMP
#endif // USE_I2C