Fix TuyaSend exception

This commit is contained in:
Theo Arends 2022-08-20 13:46:31 +02:00
parent 9a66687085
commit 204289e1ab

View File

@ -160,21 +160,23 @@ TuyaSend6 11,ABCD -> Sends raw (Type 0) data to dpId
*/ */
void CmndTuyaSend(void) { void CmndTuyaSend(void) {
if (XdrvMailbox.index > 5 && XdrvMailbox.index < 8) { if (XdrvMailbox.index > 6 && XdrvMailbox.index < 8) {
return; return;
} }
if (XdrvMailbox.index == 0) { if (XdrvMailbox.index == 0) {
TuyaRequestState(0); TuyaRequestState(0);
ResponseCmndDone();
} else if (XdrvMailbox.index == 8) { } else if (XdrvMailbox.index == 8) {
TuyaRequestState(8); TuyaRequestState(8);
ResponseCmndDone();
} else if (XdrvMailbox.index == 9) { // TuyaSend Topic Toggle } else if (XdrvMailbox.index == 9) { // TuyaSend Topic Toggle
Settings->tuyamcu_topic = !Settings->tuyamcu_topic; Settings->tuyamcu_topic = !Settings->tuyamcu_topic;
AddLog(LOG_LEVEL_INFO, PSTR("TYA: TuyaMCU Stat Topic %s"), (Settings->tuyamcu_topic ? PSTR("enabled") : PSTR("disabled"))); AddLog(LOG_LEVEL_INFO, PSTR("TYA: TuyaMCU Stat Topic %s"), (Settings->tuyamcu_topic ? PSTR("enabled") : PSTR("disabled")));
ResponseCmndDone();
} else { } else {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
char *p; char *p;
char *data; char *data = nullptr;
uint8_t i = 0; uint8_t i = 0;
uint8_t dpId = 0; uint8_t dpId = 0;
for (char *str = strtok_r(XdrvMailbox.data, ", ", &p); str && i < 2; str = strtok_r(nullptr, ", ", &p)) { for (char *str = strtok_r(XdrvMailbox.data, ", ", &p); str && i < 2; str = strtok_r(nullptr, ", ", &p)) {
@ -186,22 +188,25 @@ void CmndTuyaSend(void) {
i++; i++;
} }
if (1 == XdrvMailbox.index) { if (data) {
TuyaSendBool(dpId, strtoul(data, nullptr, 0)); if (1 == XdrvMailbox.index) {
} else if (2 == XdrvMailbox.index) { TuyaSendBool(dpId, strtoul(data, nullptr, 0));
TuyaSendValue(dpId, strtoull(data, nullptr, 0)); } else if (2 == XdrvMailbox.index) {
} else if (3 == XdrvMailbox.index) { TuyaSendValue(dpId, strtoull(data, nullptr, 0));
TuyaSendString(dpId, data); } else if (3 == XdrvMailbox.index) {
} else if (5 == XdrvMailbox.index) { TuyaSendString(dpId, data);
TuyaSendHexString(dpId, data); } else if (5 == XdrvMailbox.index) {
} else if (4 == XdrvMailbox.index) { TuyaSendHexString(dpId, data);
TuyaSendEnum(dpId, strtoul(data, nullptr, 0)); } else if (4 == XdrvMailbox.index) {
} else if (6 == XdrvMailbox.index) { TuyaSendEnum(dpId, strtoul(data, nullptr, 0));
TuyaSendRaw(dpId, data); } else if (6 == XdrvMailbox.index) {
TuyaSendRaw(dpId, data);
}
ResponseCmndDone();
} }
} }
} }
ResponseCmndDone(); // {"TuyaSend":"error"}
} }
// TuyaMcu fnid,dpid // TuyaMcu fnid,dpid