|
10 | 10 | * ====================================================
|
11 | 11 | */
|
12 | 12 |
|
13 |
| -#define VERSION 0x05000200 // 5.0.2 |
| 13 | +#define VERSION 0x05000300 // 5.0.3 |
14 | 14 |
|
15 | 15 | enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
|
16 | 16 | enum week_t {Last, First, Second, Third, Fourth};
|
@@ -258,6 +258,7 @@ uint8_t holdcount = 0; // Timer recording button hold
|
258 | 258 | uint8_t multiwindow = 0; // Max time between button presses to record press count
|
259 | 259 | uint8_t multipress = 0; // Number of button presses within multiwindow
|
260 | 260 | uint8_t lastwallswitch[4]; // Last wall switch states
|
| 261 | +uint8_t blockgpio0 = 4; // Block GPIO0 for 4 seconds after poweron to workaround Wemos D1 RTS circuit |
261 | 262 |
|
262 | 263 | mytmplt my_module; // Active copy of GPIOs
|
263 | 264 | uint8_t pin[GPIO_MAX]; // Possible pin configurations
|
@@ -460,15 +461,20 @@ void mqtt_publish(const char* topic, const char* data)
|
460 | 461 | mqtt_publish(topic, data, false);
|
461 | 462 | }
|
462 | 463 |
|
463 |
| -void mqtt_publish_topic_P(uint8_t prefix, const char* subtopic, const char* data) |
| 464 | +void mqtt_publish_topic_P(uint8_t prefix, const char* subtopic, const char* data, boolean retained) |
464 | 465 | {
|
465 | 466 | char romram[16];
|
466 | 467 | char stopic[TOPSZ];
|
467 | 468 |
|
468 | 469 | snprintf_P(romram, sizeof(romram), ((prefix > 3) && !sysCfg.flag.mqtt_response) ? PSTR("RESULT") : subtopic);
|
469 | 470 | prefix &= 1;
|
470 | 471 | snprintf_P(stopic, sizeof(stopic), PSTR("%s/%s/%s"), sysCfg.mqtt_prefix[prefix +1], sysCfg.mqtt_topic, romram);
|
471 |
| - mqtt_publish(stopic, data); |
| 472 | + mqtt_publish(stopic, data, retained); |
| 473 | +} |
| 474 | + |
| 475 | +void mqtt_publish_topic_P(uint8_t prefix, const char* subtopic, const char* data) |
| 476 | +{ |
| 477 | + mqtt_publish_topic_P(prefix, subtopic, data, false); |
472 | 478 | }
|
473 | 479 |
|
474 | 480 | void mqtt_publishPowerState(byte device)
|
@@ -793,6 +799,17 @@ boolean mqtt_command(boolean grpflg, char *type, uint16_t index, char *dataBuf,
|
793 | 799 | }
|
794 | 800 | snprintf_P(svalue, ssvalue, PSTR("{\"PowerRetain\":\"%s\"}"), getStateText(sysCfg.flag.mqtt_power_retain));
|
795 | 801 | }
|
| 802 | + else if (!strcmp_P(type,PSTR("SENSORRETAIN"))) { |
| 803 | + if ((data_len > 0) && (payload >= 0) && (payload <= 1)) { |
| 804 | + if (!payload) { |
| 805 | + svalue[0] = '\0'; |
| 806 | + mqtt_publish_topic_P(1, PSTR("SENSOR"), svalue, sysCfg.flag.mqtt_sensor_retain); |
| 807 | + } |
| 808 | + sysCfg.flag.mqtt_sensor_retain = payload; |
| 809 | + } |
| 810 | + snprintf_P(svalue, ssvalue, PSTR("{\"SensorRetain\":\"%s\"}"), getStateText(sysCfg.flag.mqtt_sensor_retain)); |
| 811 | + } |
| 812 | + |
796 | 813 | #ifdef USE_DOMOTICZ
|
797 | 814 | else if (domoticz_command(type, index, dataBuf, data_len, payload, svalue, ssvalue)) {
|
798 | 815 | // Serviced
|
@@ -1765,6 +1782,10 @@ void every_second()
|
1765 | 1782 | {
|
1766 | 1783 | char svalue[MESSZ];
|
1767 | 1784 |
|
| 1785 | + if (blockgpio0) { |
| 1786 | + blockgpio0--; |
| 1787 | + } |
| 1788 | + |
1768 | 1789 | for (byte i = 0; i < MAX_PULSETIMERS; i++) {
|
1769 | 1790 | if (pulse_timer[i] > 111) {
|
1770 | 1791 | pulse_timer[i]--;
|
@@ -1849,7 +1870,7 @@ void every_second()
|
1849 | 1870 | svalue[0] = '\0';
|
1850 | 1871 | sensors_mqttPresent(svalue, sizeof(svalue), &djson);
|
1851 | 1872 | if (djson) {
|
1852 |
| - mqtt_publish_topic_P(1, PSTR("SENSOR"), svalue); |
| 1873 | + mqtt_publish_topic_P(1, PSTR("SENSOR"), svalue, sysCfg.flag.mqtt_sensor_retain); |
1853 | 1874 | }
|
1854 | 1875 |
|
1855 | 1876 | if (hlw_flg) {
|
@@ -1947,7 +1968,7 @@ void stateloop()
|
1947 | 1968 | button = NOT_PRESSED;
|
1948 | 1969 | }
|
1949 | 1970 | } else {
|
1950 |
| - if (pin[GPIO_KEY1] < 99) { |
| 1971 | + if ((pin[GPIO_KEY1] < 99) && !blockgpio0) { |
1951 | 1972 | button = digitalRead(pin[GPIO_KEY1]);
|
1952 | 1973 | }
|
1953 | 1974 | }
|
@@ -2067,7 +2088,7 @@ void stateloop()
|
2067 | 2088 | }
|
2068 | 2089 | } else {
|
2069 | 2090 | if (sysCfg.ledstate &0x01) {
|
2070 |
| - setLed(power); |
| 2091 | + setLed((SONOFF_TOUCH == sysCfg.module) ? (power ^1) : power); |
2071 | 2092 | }
|
2072 | 2093 | }
|
2073 | 2094 | }
|
|
0 commit comments