mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 04:36:31 +00:00
Merge pull request #7065 from andrethomas/tasmota_slave
TasmotaSlave: Bugfix for slave sent Tele & Add support for sending commands to Tasmota
This commit is contained in:
commit
f6302dbeca
@ -3,6 +3,8 @@
|
|||||||
### 7.1.0.1 20191130
|
### 7.1.0.1 20191130
|
||||||
|
|
||||||
- Fix slider for devices with one or two channels like only white or white/yellow
|
- Fix slider for devices with one or two channels like only white or white/yellow
|
||||||
|
- Fix TasmotaSlave buffer overrun on Tele
|
||||||
|
- Add support for TasmotaSlave executing commands on Tasmota
|
||||||
|
|
||||||
## Released
|
## Released
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#define CMND_FUNC_EVERY_100_MSECOND 0x04
|
#define CMND_FUNC_EVERY_100_MSECOND 0x04
|
||||||
#define CMND_SLAVE_SEND 0x05
|
#define CMND_SLAVE_SEND 0x05
|
||||||
#define CMND_PUBLISH_TELE 0x06
|
#define CMND_PUBLISH_TELE 0x06
|
||||||
|
#define CMND_EXECUTE_CMND 0x07
|
||||||
|
|
||||||
#define PARAM_DATA_START 0xFE
|
#define PARAM_DATA_START 0xFE
|
||||||
#define PARAM_DATA_END 0xFF
|
#define PARAM_DATA_END 0xFF
|
||||||
@ -142,6 +143,7 @@ struct TSLAVE {
|
|||||||
bool flashing = false;
|
bool flashing = false;
|
||||||
bool SerialEnabled = false;
|
bool SerialEnabled = false;
|
||||||
uint8_t waitstate = 0; // We use this so that features detection does not slow down other stuff on startup
|
uint8_t waitstate = 0; // We use this so that features detection does not slow down other stuff on startup
|
||||||
|
bool unsupported = false;
|
||||||
} TSlave;
|
} TSlave;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
@ -461,9 +463,14 @@ void TasmotaSlave_Init(void)
|
|||||||
TasmotaSlave_Serial->readBytesUntil(char(PARAM_DATA_START), buffer, sizeof(buffer));
|
TasmotaSlave_Serial->readBytesUntil(char(PARAM_DATA_START), buffer, sizeof(buffer));
|
||||||
uint8_t len = TasmotaSlave_Serial->readBytesUntil(char(PARAM_DATA_END), buffer, sizeof(buffer));
|
uint8_t len = TasmotaSlave_Serial->readBytesUntil(char(PARAM_DATA_END), buffer, sizeof(buffer));
|
||||||
memcpy(&TSlaveSettings, &buffer, sizeof(TSlaveSettings));
|
memcpy(&TSlaveSettings, &buffer, sizeof(TSlaveSettings));
|
||||||
if (20191101 == TSlaveSettings.features_version) {
|
if (20191129 == TSlaveSettings.features_version) {
|
||||||
TSlave.type = true;
|
TSlave.type = true;
|
||||||
AddLog_P2(LOG_LEVEL_INFO, PSTR("Tasmota Slave Version %u"), TSlaveSettings.features_version);
|
AddLog_P2(LOG_LEVEL_INFO, PSTR("Tasmota Slave Version %u"), TSlaveSettings.features_version);
|
||||||
|
} else {
|
||||||
|
if ((!TSlave.unsupported) && (TSlaveSettings.features_version > 0)) {
|
||||||
|
AddLog_P2(LOG_LEVEL_INFO, PSTR("Tasmota Slave Version %u not supported!"), TSlaveSettings.features_version);
|
||||||
|
TSlave.unsupported = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -508,6 +515,7 @@ void CmndTasmotaSlaveReset(void)
|
|||||||
TasmotaSlave_Reset();
|
TasmotaSlave_Reset();
|
||||||
TSlave.type = false; // Force redetection
|
TSlave.type = false; // Force redetection
|
||||||
TSlave.waitstate = 7; // give it at least 3 seconds to restart from bootloader
|
TSlave.waitstate = 7; // give it at least 3 seconds to restart from bootloader
|
||||||
|
TSlave.unsupported = false; // Reset unsupported flag
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,8 +544,7 @@ void TasmotaSlave_ProcessIn(void)
|
|||||||
}
|
}
|
||||||
TasmotaSlave_Serial->read(); // read trailing byte of command
|
TasmotaSlave_Serial->read(); // read trailing byte of command
|
||||||
memcpy(&TSlaveCommand, &buffer, sizeof(TSlaveCommand));
|
memcpy(&TSlaveCommand, &buffer, sizeof(TSlaveCommand));
|
||||||
if (CMND_PUBLISH_TELE == TSlaveCommand.command) { // We need to publish stat/ with incoming stream as content
|
char inbuf[TSlaveCommand.parameter+1];
|
||||||
char inbuf[sizeof(TSlaveCommand.parameter)+1];
|
|
||||||
TasmotaSlave_waitForSerialData(TSlaveCommand.parameter, 50);
|
TasmotaSlave_waitForSerialData(TSlaveCommand.parameter, 50);
|
||||||
TasmotaSlave_Serial->read(); // Read leading byte
|
TasmotaSlave_Serial->read(); // Read leading byte
|
||||||
for (uint8_t idx = 0; idx < TSlaveCommand.parameter; idx++) {
|
for (uint8_t idx = 0; idx < TSlaveCommand.parameter; idx++) {
|
||||||
@ -545,12 +552,17 @@ void TasmotaSlave_ProcessIn(void)
|
|||||||
}
|
}
|
||||||
TasmotaSlave_Serial->read(); // Read trailing byte
|
TasmotaSlave_Serial->read(); // Read trailing byte
|
||||||
inbuf[TSlaveCommand.parameter] = '\0';
|
inbuf[TSlaveCommand.parameter] = '\0';
|
||||||
|
|
||||||
|
if (CMND_PUBLISH_TELE == TSlaveCommand.command) { // We need to publish stat/ with incoming stream as content
|
||||||
Response_P(PSTR("{\"TasmotaSlave\":"));
|
Response_P(PSTR("{\"TasmotaSlave\":"));
|
||||||
ResponseAppend_P("%s", inbuf);
|
ResponseAppend_P("%s", inbuf);
|
||||||
ResponseJsonEnd();
|
ResponseJsonEnd();
|
||||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, mqtt_data);
|
MqttPublishPrefixTopic_P(RESULT_OR_TELE, mqtt_data);
|
||||||
XdrvRulesProcess();
|
XdrvRulesProcess();
|
||||||
}
|
}
|
||||||
|
if (CMND_EXECUTE_CMND == TSlaveCommand.command) { // We need to execute the incoming command
|
||||||
|
ExecuteCommand(inbuf, SRC_IGNORE);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user