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

Some comment fixes and TuyaMCU signal strength #971

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/autoexecs/TEQOOZ-SmartFanRegulatorWi-Fi.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ setChannelType 22 TextField
setChannelType 23 TextField

// link output 1 to channel 1
// linkTuyaMCUOutputToChannel dpId varType tgChannel
linkTuyaMCUOutputToChannel 1 1 1

// link output 3 to channel 3
Expand Down
1 change: 1 addition & 0 deletions docs/autoexecs/manual_tuyamcu_flash_save.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ setChannelType 9 TextField
setChannelType 10 TextField
setChannelType 14 TextField

// linkTuyaMCUOutputToChannel dpId varType tgChannel
linkTuyaMCUOutputToChannel 1 1 1
linkTuyaMCUOutputToChannel 2 1 2
linkTuyaMCUOutputToChannel 3 1 3
Expand Down
37 changes: 28 additions & 9 deletions src/driver/drv_tuyaMCU.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ TuyaMCU version 0, aka low power protocol, documented here:
#define TUYA_CMD_SET_RSSI 0x24
#define TUYA_CMD_NETWORK_STATUS 0x2B

#define TUYA_V0_CMD_PRODUCTINFORMATION 0x01
#define TUYA_V0_CMD_NETWEORKSTATUS 0x02
#define TUYA_V0_CMD_RESETWIFI 0x03
#define TUYA_V0_CMD_RESETWIFI_AND_SEL_CONF 0x04
#define TUYA_V0_CMD_REALTIMESTATUS 0x05
#define TUYA_V0_CMD_OBTAINLOCALTIME 0x06
#define TUYA_V0_CMD_RECORDSTATUS 0x08
#define TUYA_V0_CMD_OBTAINDPCACHE 0x10
#define TUYA_V0_CMD_QUERYSIGNALSTRENGTH 0x0B

#define TUYA_NETWORK_STATUS_AP_MODE 0x01
#define TUYA_NETWORK_STATUS_NOT_CONNECTED 0x02
#define TUYA_NETWORK_STATUS_CONNECTED_TO_ROUTER 0x03
Expand Down Expand Up @@ -119,6 +129,8 @@ const char* TuyaMCU_GetCommandTypeLabel(int t) {
return "NetworkStatus";
if (t == TUYA_CMD_SET_RSSI)
return "SetRSSI";
if (t == TUYA_V0_CMD_QUERYSIGNALSTRENGTH)
return "QuerySignalStrngth";
return "Unknown";
}
typedef struct rtcc_s {
Expand Down Expand Up @@ -681,6 +693,12 @@ commandResult_t Cmd_TuyaMCU_Send_RSSI(const void* context, const char* cmd, cons
TuyaMCU_Send_RSSI(toSend);
return CMD_RES_OK;
}
void TuyaMCU_Send_SignalStrength(byte state, byte strength) {
byte payload_buffer[2];
payload_buffer[0] = state;
payload_buffer[1] = strength;
TuyaMCU_SendCommandWithData(TUYA_V0_CMD_QUERYSIGNALSTRENGTH, payload_buffer, sizeof(payload_buffer));
}
void TuyaMCU_Send_SetTime(struct tm* pTime, bool bSensorMode) {
byte payload_buffer[8];

Expand Down Expand Up @@ -1433,15 +1451,6 @@ void TuyaMCU_ResetWiFi() {
g_openAP = 1;
}
}
#define TUYA_V0_CMD_PRODUCTINFORMATION 0x01
#define TUYA_V0_CMD_NETWEORKSTATUS 0x02
#define TUYA_V0_CMD_RESETWIFI 0x03
#define TUYA_V0_CMD_RESETWIFI_AND_SEL_CONF 0x04
#define TUYA_V0_CMD_REALTIMESTATUS 0x05
#define TUYA_V0_CMD_OBTAINLOCALTIME 0x06
#define TUYA_V0_CMD_RECORDSTATUS 0x08
#define TUYA_V0_CMD_OBTAINDPCACHE 0x10

void TuyaMCU_V0_SendDPCacheReply() {
#if 0
// send empty?
Expand Down Expand Up @@ -1631,6 +1640,16 @@ void TuyaMCU_ProcessIncoming(const byte* data, int len) {
}
else {

}
break;
case TUYA_V0_CMD_QUERYSIGNALSTRENGTH:
if (version == 0) {
addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU, "TuyaMCU_ProcessIncoming: received TUYA_V0_CMD_QUERYSIGNALSTRENGTH, so sending back signal");

TuyaMCU_Send_SignalStrength(1,80);
}
else {

}
break;
case TUYA_V0_CMD_OBTAINLOCALTIME:
Expand Down
2 changes: 1 addition & 1 deletion src/new_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ typedef struct mainConfig_s {
char ping_host[64];
// ofs 0x000005E0 (dec 1504)
//char initCommandLine[512];
#if PLATFORM_W600
#if PLATFORM_W600 || PLATFORM_W800
#define ALLOW_SSID2 0
char initCommandLine[512];
#else
Expand Down
30 changes: 30 additions & 0 deletions src/selftest/selftest_tuyaMCU_batteryPowered.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,34 @@ void Test_TuyaMCU_BatteryPowered_DPcacheFeature2() {

SELFTEST_ASSERT_HAS_SENT_UART_STRING("55 AA 00 10 00 02 0100 12");
}
void Test_TuyaMCU_BatteryPowered_QuerySignalStrength() {
// reset whole device
SIM_ClearOBK(0);
SIM_UART_InitReceiveRingBuffer(1024);

CMD_ExecuteCommand("startDriver TuyaMCU", 0);
CMD_ExecuteCommand("startDriver tmSensor", 0);

// nothing is sent by OBK at that point
SELFTEST_ASSERT_HAS_UART_EMPTY();
/*
Pressed: 1. Send query product information
(simulated delays are disabled)
Sent: 55 AA 00 01 00 00 00
Sent: Ver=0, Cmd=QueryInfo, Len=0, CHECKSUM OK
*/
Sim_RunSeconds(3.0f, false);
SELFTEST_ASSERT_HAS_SENT_UART_STRING("55 AA 00 01 00 00 00");
// nothing is sent by OBK at that point
SELFTEST_ASSERT_HAS_UART_EMPTY();

CMD_ExecuteCommand("uartFakeHex 55 AA 00 0B 00 00 0A", 0);
Sim_RunSeconds(0.1f, false);

SELFTEST_ASSERT_HAS_SENT_UART_STRING("55 AA 00 0B 00 02 01 50 5D");
// nothing is sent by OBK at that point
SELFTEST_ASSERT_HAS_UART_EMPTY();
}
void Test_TuyaMCU_BatteryPowered() {
Test_TuyaMCU_BatteryPowered_Style2();
Test_TuyaMCU_BatteryPowered_Style1();
Expand All @@ -336,6 +364,8 @@ void Test_TuyaMCU_BatteryPowered() {
Test_TuyaMCU_BatteryPowered_DPcacheFeature2();
Test_TuyaMCU_BatteryPowered_DPcacheFeature3();
Test_TuyaMCU_BatteryPowered_DPcacheFeature4();

Test_TuyaMCU_BatteryPowered_QuerySignalStrength();
}

#endif
Expand Down
Loading