mirror of https://github.com/arendst/Tasmota.git
Merge pull request #4221 from chaosmaster/tuya-wifi-state
tuya: properly indicate wifi-status
This commit is contained in:
commit
07ac25ce34
|
@ -1110,7 +1110,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
||||||
wifi_state_flag = Settings.sta_config;
|
wifi_state_flag = Settings.sta_config;
|
||||||
snprintf_P(stemp1, sizeof(stemp1), kWifiConfig[Settings.sta_config]);
|
snprintf_P(stemp1, sizeof(stemp1), kWifiConfig[Settings.sta_config]);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WIFICONFIG "\":\"%s " D_JSON_SELECTED "\"}"), stemp1);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WIFICONFIG "\":\"%s " D_JSON_SELECTED "\"}"), stemp1);
|
||||||
if (WifiState() != WIFI_RESTART) {
|
if (WifiState() > WIFI_RESTART) {
|
||||||
// snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s after restart"), mqtt_data);
|
// snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s after restart"), mqtt_data);
|
||||||
restart_flag = 2;
|
restart_flag = 2;
|
||||||
}
|
}
|
||||||
|
@ -1795,7 +1795,7 @@ void ButtonHandler()
|
||||||
// Success
|
// Success
|
||||||
} else {
|
} else {
|
||||||
if (multipress[button_index] < 3) { // Single or Double press
|
if (multipress[button_index] < 3) { // Single or Double press
|
||||||
if (WifiState()) { // WPSconfig, Smartconfig or Wifimanager active
|
if (WifiState() > WIFI_RESTART) { // WPSconfig, Smartconfig or Wifimanager active
|
||||||
restart_flag = 1;
|
restart_flag = 1;
|
||||||
} else {
|
} else {
|
||||||
ExecuteCommandPower(button_index + multipress[button_index], POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally
|
ExecuteCommandPower(button_index + multipress[button_index], POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally
|
||||||
|
|
|
@ -1613,7 +1613,7 @@ void WifiCheck(uint8_t param)
|
||||||
|
|
||||||
int WifiState()
|
int WifiState()
|
||||||
{
|
{
|
||||||
int state;
|
int state = -1;
|
||||||
|
|
||||||
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0)) {
|
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0)) {
|
||||||
state = WIFI_RESTART;
|
state = WIFI_RESTART;
|
||||||
|
|
|
@ -33,7 +33,7 @@ boolean tuya_ignore_dim = false; // Flag to skip serial send to preve
|
||||||
uint8_t tuya_cmd_status = 0; // Current status of serial-read
|
uint8_t tuya_cmd_status = 0; // Current status of serial-read
|
||||||
uint8_t tuya_cmd_checksum = 0; // Checksum of tuya command
|
uint8_t tuya_cmd_checksum = 0; // Checksum of tuya command
|
||||||
uint8_t tuya_data_len = 0; // Data lenght of command
|
uint8_t tuya_data_len = 0; // Data lenght of command
|
||||||
bool tuya_wifi_state = false;
|
int8_t tuya_wifi_state = -2;
|
||||||
|
|
||||||
char tuya_buffer[TUYA_BUFFER_SIZE]; // Serial receive buffer
|
char tuya_buffer[TUYA_BUFFER_SIZE]; // Serial receive buffer
|
||||||
int tuya_byte_counter = 0; // Index in serial receive buffer
|
int tuya_byte_counter = 0; // Index in serial receive buffer
|
||||||
|
@ -148,10 +148,10 @@ void TuyaPacketProcess()
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("TYA: WiFi Reset Rcvd"));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR("TYA: WiFi Reset Rcvd"));
|
||||||
TuyaResetWifi();
|
TuyaResetWifi();
|
||||||
}
|
}
|
||||||
else if (tuya_byte_counter == 7 && tuya_buffer[3] == 3 && tuya_buffer[6] == 2) { // WiFi LED has been sucessfully reset.
|
else if (tuya_byte_counter == 7 && tuya_buffer[3] == 3 && tuya_buffer[6] == 2) { // WiFi LED has been sucessfully set.
|
||||||
|
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("TYA: WiFi LED reset ACK"));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR("TYA: WiFi LED set ACK"));
|
||||||
tuya_wifi_state = true;
|
tuya_wifi_state = WifiState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,8 +225,22 @@ boolean TuyaModuleSelected()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TuyaResetWifiLed(){
|
void TuyaSetWifiLed(){
|
||||||
snprintf_P(log_data, sizeof(log_data), "TYA: Reset WiFi LED");
|
uint8_t wifi_state = 0x02;
|
||||||
|
switch(WifiState()){
|
||||||
|
case WIFI_SMARTCONFIG:
|
||||||
|
wifi_state = 0x00;
|
||||||
|
break;
|
||||||
|
case WIFI_MANAGER:
|
||||||
|
case WIFI_WPSCONFIG:
|
||||||
|
wifi_state = 0x01;
|
||||||
|
break;
|
||||||
|
case WIFI_RESTART:
|
||||||
|
wifi_state = 0x03;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf_P(log_data, sizeof(log_data), "TYA: Set WiFi LED to state %d (%d)", wifi_state, WifiState());
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
TuyaSerial->write((uint8_t)0x55); // header 55AA
|
TuyaSerial->write((uint8_t)0x55); // header 55AA
|
||||||
|
@ -235,8 +249,8 @@ void TuyaResetWifiLed(){
|
||||||
TuyaSerial->write((uint8_t)0x03); // command 03 - set wifi state
|
TuyaSerial->write((uint8_t)0x03); // command 03 - set wifi state
|
||||||
TuyaSerial->write((uint8_t)0x00);
|
TuyaSerial->write((uint8_t)0x00);
|
||||||
TuyaSerial->write((uint8_t)0x01); // following data length 0x01
|
TuyaSerial->write((uint8_t)0x01); // following data length 0x01
|
||||||
TuyaSerial->write((uint8_t)0x03); // wifi state 4 (configured and connected)
|
TuyaSerial->write((uint8_t)wifi_state); // wifi state (0x00 == smartconfig, 0x01 == AP, 0x02 == not connected, 0x03 == connected)
|
||||||
TuyaSerial->write((uint8_t)0x06); // checksum:sum of all bytes in packet mod 256
|
TuyaSerial->write((uint8_t)(0x03 + wifi_state)); // checksum:sum of all bytes in packet mod 256
|
||||||
TuyaSerial->flush();
|
TuyaSerial->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,9 +282,9 @@ void TuyaResetWifi()
|
||||||
{
|
{
|
||||||
if (!Settings.flag.button_restrict) {
|
if (!Settings.flag.button_restrict) {
|
||||||
char scmnd[20];
|
char scmnd[20];
|
||||||
|
tuya_wifi_state = -1;
|
||||||
snprintf_P(scmnd, sizeof(scmnd), D_CMND_WIFICONFIG " %d", 2);
|
snprintf_P(scmnd, sizeof(scmnd), D_CMND_WIFICONFIG " %d", 2);
|
||||||
ExecuteCommand(scmnd, SRC_BUTTON);
|
ExecuteCommand(scmnd, SRC_BUTTON);
|
||||||
tuya_wifi_state = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +328,7 @@ boolean Xdrv16(byte function)
|
||||||
result = TuyaButtonPressed();
|
result = TuyaButtonPressed();
|
||||||
break;
|
break;
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
if(TuyaSerial && !tuya_wifi_state) { TuyaResetWifiLed(); }
|
if(TuyaSerial && tuya_wifi_state!=WifiState()) { TuyaSetWifiLed(); }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue