From f19cf5f3244176c730afa3dd8067501847901dee Mon Sep 17 00:00:00 2001 From: joBr99 <29555657+joBr99@users.noreply.github.com> Date: Sat, 12 Mar 2022 16:54:05 +0100 Subject: [PATCH] fixed offset in berry driver for new msg format --- tasmota/autoexec.be | 11 ++++++----- test-msg-gen.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tasmota/autoexec.be b/tasmota/autoexec.be index ae98514c..97f45654 100644 --- a/tasmota/autoexec.be +++ b/tasmota/autoexec.be @@ -167,11 +167,11 @@ class Nextion : Driver return ret end - # encode using custom protocol 55 BB [payload length] [payload] [crc] [crc] + # encode using custom protocol 55 BB [payload length] [payload length] [payload] [crc] [crc] def encode(payload) var b = bytes() b += self.header - b.add(size(payload), 1) # add size as 1 byte + b.add(size(payload), 2) # add size as 2 bytes, little endian b += bytes().fromstring(payload) var msg_crc = self.crc16(b) b.add(msg_crc, 2) # crc 2 bytes, little endian @@ -303,13 +303,14 @@ class Nextion : Driver self.flash_nextion() end else - # Recive messages using custom protocol 55 BB [payload length] [payload] [crc] [crc] + # Recive messages using custom protocol 55 BB [payload length] [payload length] [payload] [crc] [crc] if msg[0..1] == self.header var lst = self.split_55(msg) for i:0..size(lst)-1 msg = lst[i] - var j = msg[2]+2 - msg = msg[3..j] + #var j = msg[2]+2 + var j = size(msg) - 3 + msg = msg[4..j] if size(msg) > 2 var jm = string.format("{\"CustomRecv\":\"%s\"}",msg.asstring()) tasmota.publish_result(jm, "RESULT") diff --git a/test-msg-gen.py b/test-msg-gen.py index 1f2cf813..30f6f0b7 100644 --- a/test-msg-gen.py +++ b/test-msg-gen.py @@ -27,7 +27,7 @@ header = binascii.unhexlify('55BB') print("length:", len(value)) -length = len(value).to_bytes(1, 'little') +length = len(value).to_bytes(2, 'little') bytes_payload = header + length + payload