Skip to content

Commit

Permalink
add command to set default wifi state for tuayMCU tuyaMcu_defWiFiState
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Jan 15, 2023
1 parent 9c37b0d commit e180c6e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/driver/drv_tuyaMCU.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ static bool self_processing_mode = true;
static bool state_updated = false;
static int g_sendQueryStatePackets = 0;

// wifistate to send when not online
// See: https://imgur.com/a/mEfhfiA
static byte g_defaultTuyaMCUWiFiState = 0x00;

tuyaMCUMapping_t *TuyaMCU_FindDefForID(int fnId) {
tuyaMCUMapping_t *cur;

Expand Down Expand Up @@ -443,6 +447,12 @@ void TuyaMCU_Send_RSSI(int rssi) {

TuyaMCU_SendCommandWithData(TUYA_CMD_SET_RSSI, (byte*)&payload_signedByte, 1);
}
commandResult_t Cmd_TuyaMCU_Set_DefaultWiFiState(const void *context, const char *cmd, const char *args, int cmdFlags) {

g_defaultTuyaMCUWiFiState = atoi(args);

return CMD_RES_OK;
}
commandResult_t Cmd_TuyaMCU_Send_RSSI(const void *context, const char *cmd, const char *args, int cmdFlags) {
int toSend;

Expand Down Expand Up @@ -1240,7 +1250,7 @@ void TuyaMCU_RunWiFiUpdateAndPackets() {
{
addLogAdv(LOG_EXTRADEBUG, LOG_FEATURE_TUYAMCU, "Will send SetWiFiState 0.\n");

Tuya_SetWifiState(0);
Tuya_SetWifiState(g_defaultTuyaMCUWiFiState);
wifi_state = false;
wifi_state_timer++;
}
Expand Down Expand Up @@ -1343,7 +1353,7 @@ void TuyaMCU_RunFrame() {
else if ((wifi_state_valid == false) && (self_processing_mode == false))
{
/* Reset wifi state -> Aquirring network connection */
Tuya_SetWifiState(0);
Tuya_SetWifiState(g_defaultTuyaMCUWiFiState);
addLogAdv(LOG_EXTRADEBUG, LOG_FEATURE_TUYAMCU, "Will send TUYA_CMD_WIFI_STATE.\n");
TuyaMCU_SendCommandWithData(TUYA_CMD_WIFI_STATE, NULL, 0);
}
Expand Down Expand Up @@ -1452,10 +1462,15 @@ void TuyaMCU_Init()
//cmddetail:"examples":""}
CMD_RegisterCommand("tuyaMcu_setBaudRate","",TuyaMCU_SetBaudRate, NULL, NULL);
//cmddetail:{"name":"tuyaMcu_sendRSSI","args":"",
//cmddetail:"descr":"NULL",
//cmddetail:"descr":"Command sends the specific RSSI value to TuyaMCU (it will send current RSSI if no argument is set)",
//cmddetail:"fn":"Cmd_TuyaMCU_Send_RSSI","file":"driver/drv_tuyaMCU.c","requires":"",
//cmddetail:"examples":""}
CMD_RegisterCommand("tuyaMcu_sendRSSI", "", Cmd_TuyaMCU_Send_RSSI, NULL, NULL);
//cmddetail:{"name":"tuyaMcu_defWiFiState","args":"",
//cmddetail:"descr":"Command sets the default WiFi state for TuyaMCU when device is not online.",
//cmddetail:"fn":"Cmd_TuyaMCU_Send_RSSI","file":"driver/drv_tuyaMCU.c","requires":"",
//cmddetail:"examples":""}
CMD_RegisterCommand("tuyaMcu_defWiFiState", "", Cmd_TuyaMCU_Set_DefaultWiFiState, NULL, NULL);

}
// Door sensor with TuyaMCU version 0 (not 3), so all replies have x00 and not 0x03 byte
Expand Down

0 comments on commit e180c6e

Please sign in to comment.