``Publish3`` to send binary data encoded as Hex, disabled in safeboot (#21345)

This commit is contained in:
s-hadinger 2024-05-04 15:26:07 +02:00 committed by GitHub
parent 3be5f630e1
commit 599526a90c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 7 deletions

View File

@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- TCP Tx En GPIO type
- Berry `webserver.content_close()`
- HASPmota demo of Renaissance Watch for 480x480 displays
- ``Publish3`` to send binary data encoded as Hex, disabled in safeboot
### Breaking Changed
- ESP32-C3 OTA binary name from `tasmota32c3cdc.bin` to `tasmota32c3.bin` with USB HWCDC and fallback to serial (#21212)

View File

@ -611,15 +611,18 @@ String HexToString(uint8_t* data, uint32_t length) {
// Converts a Hex string (case insensitive) into an array of bytes
// Returns the number of bytes in the array, or -1 if an error occured
// The `out` buffer must be at least half the size of hex string
int32_t HexToBytes(const char* hex, uint8_t* out, size_t outLen) {
int32_t HexToBytes(const char* hex, uint8_t* out, size_t out_len) {
size_t len = strlen_P(hex);
if (len % 2 != 0) {
return -1;
}
size_t outLength = len / 2;
size_t bytes_out = len / 2;
if (bytes_out < out_len) {
bytes_out = out_len;
}
for (size_t i = 0; i < outLength && i < outLen; i++) {
for (size_t i = 0; i < bytes_out; i++) {
char byte[3];
byte[0] = hex[i*2];
byte[1] = hex[i*2 + 1];
@ -628,11 +631,11 @@ int32_t HexToBytes(const char* hex, uint8_t* out, size_t outLen) {
char* endPtr;
out[i] = strtoul(byte, &endPtr, 16);
if(*endPtr != '\0') {
if (*endPtr != '\0') {
return -1;
}
}
return outLength;
return bytes_out;
}
String UrlEncode(const String& text) {

View File

@ -742,7 +742,7 @@ void MqttPublish(const char* topic, bool retained) {
MqttPublishPayload(topic, ResponseData(), 0, retained);
}
void MqttPublish(const char* topic, bool retained, bool binary) {
void MqttPublishBinary(const char* topic, bool retained, bool binary) {
int32_t binary_length = 0;
char *response_data = ResponseData();
if (binary) {
@ -1569,7 +1569,12 @@ void CmndPublish(void) {
} else {
ResponseClear();
}
MqttPublish(stemp1, (XdrvMailbox.index == 2), (XdrvMailbox.index == 3));
#ifndef FIRMWARE_MINIMAL
// Publish3 binary is not enabled in MINIMAL
MqttPublishBinary(stemp1, (XdrvMailbox.index == 2), (XdrvMailbox.index == 3));
#else
MqttPublish(stemp1, (XdrvMailbox.index == 2));
#endif
ResponseClear();
}
}