Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tuya commands CMD_GET_NETWORK_STATUS and CMD_TEST_WIFI #17745

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion tasmota/tasmota_xdrv_driver/xdrv_16_tuyamcu_v1.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
#define TUYA_CMD_QUERY_STATE 0x08
#define TUYA_CMD_INITIATING_UPGRADE 0x0A
#define TUYA_CMD_UPGRADE_PACKAGE 0x0B
#define TUYA_CMD_TEST_WIFI 0x0E
#define TUYA_CMD_SET_TIME 0x1C
#define TUYA_CMD_GET_NETWORK_STATUS 0x2B
#define TUYA_CMD_GET_WIFI_STRENGTH 0x24

#define TUYA_LOW_POWER_CMD_WIFI_STATE 0x02
Expand Down Expand Up @@ -117,7 +119,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_GET_WIFI_STRENGTH
TUYA_CMD_HEARTBEAT, TUYA_CMD_WIFI_STATE, TUYA_CMD_SET_TIME, TUYA_CMD_UPGRADE_PACKAGE, TUYA_CMD_GET_WIFI_STRENGTH, TUYA_CMD_GET_NETWORK_STATUS, TUYA_CMD_TEST_WIFI
};

/*********************************************************************************************\
Expand Down Expand Up @@ -1134,6 +1136,12 @@ void TuyaNormalPowerModePacketProcess(void)
case TUYA_CMD_GET_WIFI_STRENGTH:
TuyaSetWifiStrength();
break;
case TUYA_CMD_TEST_WIFI:
TuyaCheckTestWifi();
break;
case TUYA_CMD_GET_NETWORK_STATUS:
TuyaSetNetworkState();
break;
#ifdef USE_TUYA_TIME
case TUYA_CMD_SET_TIME:
TuyaSetTime();
Expand Down Expand Up @@ -1427,6 +1435,23 @@ void TuyaSetWifiStrength(void) {
TuyaSendCmd(TUYA_CMD_GET_WIFI_STRENGTH, payload_buffer, payload_len);
}

void TuyaCheckTestWifi(void){
// MCU request the module if whose SSID is 'tuya_mdev_test' and returns the result and the signal strength in percentage.
// Assuming that nobody uses this test wifi, the payload is hardcoded.
uint8_t payload_buffer[2] = {
0x00, //'tuya_mdev_test' wifi not found
0x00 //signal strength = 0
};

TuyaSendCmd(TUYA_CMD_TEST_WIFI, payload_buffer, 2);
}

void TuyaSetNetworkState (void) {
//MCU requests the network state (this state should be consitent to the wifi state)
uint8_t network_state = TuyaGetTuyaWifiState();
TuyaSendCmd(TUYA_CMD_GET_NETWORK_STATUS, &network_state, 1);
}

#ifdef USE_TUYA_TIME
void TuyaSetTime(void) {
if (!RtcTime.valid) { return; }
Expand Down