mirror of https://github.com/arendst/Tasmota.git
Tuya - WIFI_STRENGTH + Save check on MCU_CONF (#17724)
* adding response to command 36 Get Wifi Strength * more logs * poperly check and warn if Mode 2 provide bad GPIOs * final test on gpio
This commit is contained in:
parent
457f706d17
commit
d904e0aa7f
|
@ -1658,7 +1658,7 @@ uint32_t ValidPin(uint32_t pin, uint32_t gpio) {
|
|||
#elif defined(CONFIG_IDF_TARGET_ESP32)
|
||||
// ignore
|
||||
#else // not ESP32C3 and not ESP32S2
|
||||
if ((WEMOS == Settings->module) && !Settings->flag3.user_esp8285_enable) { // SetOption51 - Enable ESP8285 user GPIO's
|
||||
if (((WEMOS == Settings->module) || (TUYA_DIMMER == Settings->module) || (USER_MODULE == Settings->module)) && !Settings->flag3.user_esp8285_enable) { // SetOption51 - Enable ESP8285 user GPIO's
|
||||
if ((9 == pin) || (10 == pin)) {
|
||||
return GPIO_NONE; // Disable possible flash GPIO9 and GPIO10
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#define TUYA_CMD_INITIATING_UPGRADE 0x0A
|
||||
#define TUYA_CMD_UPGRADE_PACKAGE 0x0B
|
||||
#define TUYA_CMD_SET_TIME 0x1C
|
||||
#define TUYA_CMD_GET_WIFI_STRENGTH 0x24
|
||||
|
||||
#define TUYA_LOW_POWER_CMD_WIFI_STATE 0x02
|
||||
#define TUYA_LOW_POWER_CMD_WIFI_RESET 0x03
|
||||
|
@ -116,7 +117,7 @@ void (* const TuyaCommand[])(void) PROGMEM = {
|
|||
};
|
||||
|
||||
const uint8_t TuyaExcludeCMDsFromMQTT[] PROGMEM = { // don't publish this received commands via MQTT if SetOption66 and SetOption137 is active (can be expanded in the future)
|
||||
TUYA_CMD_HEARTBEAT, TUYA_CMD_WIFI_STATE, TUYA_CMD_SET_TIME, TUYA_CMD_UPGRADE_PACKAGE
|
||||
TUYA_CMD_HEARTBEAT, TUYA_CMD_WIFI_STATE, TUYA_CMD_SET_TIME, TUYA_CMD_UPGRADE_PACKAGE, TUYA_CMD_GET_WIFI_STRENGTH
|
||||
};
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
@ -1097,23 +1098,42 @@ void TuyaNormalPowerModePacketProcess(void)
|
|||
if (Tuya.buffer[5] == 2) { // Processing by ESP module mode
|
||||
uint8_t led1_gpio = Tuya.buffer[6];
|
||||
uint8_t key1_gpio = Tuya.buffer[7];
|
||||
AddLog(LOG_LEVEL_DEBUG, PSTR("TYA: Mode=2 led:%d, key:%d"), led1_gpio, key1_gpio);
|
||||
bool key1_set = false;
|
||||
bool led1_set = false;
|
||||
// Check if LED_1 and KEY_1 are not already configured
|
||||
for (uint32_t i = 0; i < nitems(Settings->my_gp.io); i++) {
|
||||
if (Settings->my_gp.io[i] == AGPIO(GPIO_LED1)) led1_set = true;
|
||||
else if (Settings->my_gp.io[i] == AGPIO(GPIO_KEY1)) key1_set = true;
|
||||
}
|
||||
if (!Settings->my_gp.io[led1_gpio] && !led1_set) {
|
||||
Settings->my_gp.io[led1_gpio] = AGPIO(GPIO_LED1);
|
||||
TasmotaGlobal.restart_flag = 2;
|
||||
// If LED_1 not yet configured
|
||||
if (!led1_set) {
|
||||
// Check is the GPIO is not already in use and if it is valid
|
||||
if (!Settings->my_gp.io[led1_gpio] && ValidPin(led1_gpio,GPIO_LED1)) {
|
||||
Settings->my_gp.io[led1_gpio] = AGPIO(GPIO_LED1);
|
||||
TasmotaGlobal.restart_flag = 2;
|
||||
AddLog(LOG_LEVEL_DEBUG, PSTR("TYA: Set LED1 on gpio%d, will restart"), led1_gpio);
|
||||
} else {
|
||||
AddLog(LOG_LEVEL_ERROR, PSTR("TYA: In use or illegal gpio%d for LED1, ignored"), led1_gpio);
|
||||
}
|
||||
}
|
||||
if (!Settings->my_gp.io[key1_gpio] && !key1_set) {
|
||||
Settings->my_gp.io[key1_gpio] = AGPIO(GPIO_KEY1);
|
||||
TasmotaGlobal.restart_flag = 2;
|
||||
// If KEY_1 not yet configured
|
||||
if (!key1_set) {
|
||||
// Check is the GPIO is not already in use and if it is valid
|
||||
if (!Settings->my_gp.io[key1_gpio] && ValidPin(key1_gpio,GPIO_KEY1)) {
|
||||
Settings->my_gp.io[key1_gpio] = AGPIO(GPIO_KEY1);
|
||||
TasmotaGlobal.restart_flag = 2;
|
||||
AddLog(LOG_LEVEL_DEBUG, PSTR("TYA: Set KEY1 on gpio%d, will restart"), key1_gpio);
|
||||
} else {
|
||||
AddLog(LOG_LEVEL_ERROR, PSTR("TYA: In use or illegal gpio%d for KEY1, ignored"), key1_gpio);
|
||||
}
|
||||
}
|
||||
}
|
||||
TuyaRequestState(0);
|
||||
break;
|
||||
case TUYA_CMD_GET_WIFI_STRENGTH:
|
||||
TuyaSetWifiStrength();
|
||||
break;
|
||||
#ifdef USE_TUYA_TIME
|
||||
case TUYA_CMD_SET_TIME:
|
||||
TuyaSetTime();
|
||||
|
@ -1395,6 +1415,18 @@ void TuyaSetWifiLed(void)
|
|||
}
|
||||
}
|
||||
|
||||
void TuyaSetWifiStrength(void) {
|
||||
uint16_t payload_len = 1;
|
||||
uint8_t payload_buffer[1];
|
||||
int32_t rssi = WiFi.RSSI();
|
||||
int signal_strength = WifiGetRssiAsQuality(rssi);
|
||||
|
||||
AddLog(LOG_LEVEL_DEBUG, PSTR("TYA: RX MCU Get Wifi Strength -> sending %d"), signal_strength);
|
||||
payload_buffer[0] = (uint8_t)signal_strength;
|
||||
|
||||
TuyaSendCmd(TUYA_CMD_GET_WIFI_STRENGTH, payload_buffer, payload_len);
|
||||
}
|
||||
|
||||
#ifdef USE_TUYA_TIME
|
||||
void TuyaSetTime(void) {
|
||||
if (!RtcTime.valid) { return; }
|
||||
|
|
Loading…
Reference in New Issue