Berry mqtt.publish now distinguishes between string and bytes (#19196)

This commit is contained in:
s-hadinger 2023-07-26 19:54:14 +02:00 committed by GitHub
parent 0a664b3613
commit 9f16f09f29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
### Changed
- Initial ``DisplayMode`` from 1 to 0 and ``DisplayDimmmer`` from 10% to 50% (#19138)
- ESP32 Framework (Core) from v2.0.10 to v2.0.11
- Berry `mqtt.publish` now distinguishes between `string` and `bytes`
### Fixed
- Initial battery level percentage (#19160)

View File

@ -33,8 +33,10 @@ extern "C" {
bool retain = false;
int32_t payload_start = 0;
int32_t len = -1; // send all of it
bool is_binary = be_isbytes(vm, 3); // is this a binary payload (or false = string)
if (top >= 4) { retain = be_tobool(vm, 4); }
if (top >= 5) {
if (!is_binary) { be_raise(vm, "argument_error", "start and len are not allowed with string payloads"); }
payload_start = be_toint(vm, 5);
if (payload_start < 0) payload_start = 0;
}
@ -60,7 +62,7 @@ extern "C" {
be_pop(vm, be_top(vm)); // clear stack to avoid any indirect warning message in subsequent calls to Berry
MqttPublishPayload(topic, payload, len, retain);
MqttPublishPayload(topic, payload, is_binary ? len : 0 /*if string don't send length*/, retain);
be_return_nil(vm); // Return
}