From 687362b25b4ac38cd52c1c1cded9c7b874dee9d0 Mon Sep 17 00:00:00 2001 From: joBr99 <29555657+joBr99@users.noreply.github.com> Date: Sat, 12 Mar 2022 09:36:01 +0100 Subject: [PATCH 1/3] added nextion flash 1.2 as FlashNextionFast command --- tasmota/README.md | 6 ++++++ tasmota/autoexec.be | 36 +++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/tasmota/README.md b/tasmota/README.md index eb0a38f4..a63cb551 100644 --- a/tasmota/README.md +++ b/tasmota/README.md @@ -17,9 +17,15 @@ Send's normal Custom Commands to the Screen in the following format: - `FlashNextion URL` +Start's flashing a tft file to the nextion screen via Nextion Upload Protocol 1.1 +Might be required to send the command twice (known issue, didn't investigate yet) + +- `FlashNextionFast URL` + Start's flashing a tft file to the nextion screen via Nextion Upload Protocol 1.2 Might be required to send the command twice (known issue, didn't investigate yet) + Webserver must be reachable via HTTP and support Range Header Example: `FlashNextion http://192.168.75.30:8123/local/nspanel.tft` diff --git a/tasmota/autoexec.be b/tasmota/autoexec.be index eee0dc32..3675c876 100644 --- a/tasmota/autoexec.be +++ b/tasmota/autoexec.be @@ -15,10 +15,11 @@ class TftDownloader var current_chunk var current_chunk_start var download_range + def init(host, port, file, download_range) self.tft_file_size = 0 - + self.host = host self.port = port self.file = file @@ -118,6 +119,7 @@ class Nextion : Driver var ser var flash_size var flash_mode + var flash_version var flash_skip var flash_current_byte var tftd @@ -128,6 +130,7 @@ class Nextion : Driver log("NSP: Initializing Driver") self.ser = serial(17, 16, 115200, serial.SERIAL_8N1) self.flash_mode = 0 + self.flash_version = 1 self.flash_skip = false tasmota.add_driver(self) end @@ -199,8 +202,7 @@ class Nextion : Driver end end - def start_flash(url) - + def start_flash(url) import string var host var port @@ -224,7 +226,6 @@ class Nextion : Driver #print(host,port,file) self.tftd = TftDownloader(host, port, file, 32768) - #self.tftd = TftDownloader("192.168.75.30", 8123, "/local/test.tft", 32768) # get size of tft file self.flash_size = self.tftd.get_file_size() @@ -270,13 +271,18 @@ class Nextion : Driver var msg = self.ser.read() if size(msg) > 0 print("NSP: Received Raw =", msg) - if (self.flash_mode==1) + if self.flash_mode==1 var str = msg[0..-4].asstring() log(str, 3) # TODO: add check for firmware versions < 126 and send proto 1.1 command for thoose if (string.find(str,"comok 2")==0) - self.sendnx(string.format("whmi-wri %d,115200,1",self.flash_size)) # Nextion Upload Protocol 1.1 - #self.sendnx(string.format("whmi-wris %d,115200,1",self.flash_size)) # Nextion Upload Protocol 1.2 + if self.flash_version==1 + log("NSP: Flashing 1.1") + self.sendnx(string.format("whmi-wri %d,115200,1",self.flash_size)) # Nextion Upload Protocol 1.1 + else + log("NSP: Flashing 1.2") + self.sendnx(string.format("whmi-wris %d,115200,1",self.flash_size)) # Nextion Upload Protocol 1.2 + end # skip to byte (upload protocol 1.2) elif (size(msg)==1 && msg[0]==0x08) @@ -324,7 +330,8 @@ end var nextion = Nextion() def flash_nextion(cmd, idx, payload, payload_json) - def task() + def task() + nextion.flash_version = 1 nextion.start_flash(payload) end tasmota.set_timer(0,task) @@ -333,6 +340,17 @@ end tasmota.add_cmd('FlashNextion', flash_nextion) +def flash_nextion_1_2(cmd, idx, payload, payload_json) + def task() + nextion.flash_version = 2 + nextion.start_flash(payload) + end + tasmota.set_timer(0,task) + tasmota.resp_cmnd_done() +end + +tasmota.add_cmd('FlashNextionFast', flash_nextion_1_2) + def send_cmd(cmd, idx, payload, payload_json) nextion.sendnx(payload) tasmota.resp_cmnd_done() @@ -345,4 +363,4 @@ def send_cmd2(cmd, idx, payload, payload_json) tasmota.resp_cmnd_done() end -tasmota.add_cmd('CustomSend', send_cmd2) +tasmota.add_cmd('CustomSend', send_cmd2) \ No newline at end of file From e2d1d2f15e3c6ba029fc874da00004c1f6d7f037 Mon Sep 17 00:00:00 2001 From: joBr99 <29555657+joBr99@users.noreply.github.com> Date: Sat, 12 Mar 2022 12:49:08 +0100 Subject: [PATCH 2/3] implemented update commands for berry driver --- tasmota/README.md | 9 ++++++++- tasmota/autoexec.be | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/tasmota/README.md b/tasmota/README.md index a63cb551..8aec41a6 100644 --- a/tasmota/README.md +++ b/tasmota/README.md @@ -25,11 +25,18 @@ Might be required to send the command twice (known issue, didn't investigate yet Start's flashing a tft file to the nextion screen via Nextion Upload Protocol 1.2 Might be required to send the command twice (known issue, didn't investigate yet) - Webserver must be reachable via HTTP and support Range Header Example: `FlashNextion http://192.168.75.30:8123/local/nspanel.tft` +- `GetDriverVersion` + +Returns the version currently defined in the berry script + +- `UpdateDriverVersion URL` + +Downloads the autoexec.be script from the specified URL and loads it. + Besides the commands, serial input will be published on 'RESULT' Topic, depending on the input in one of the following formats: - `{"CustomRecv":%s}` diff --git a/tasmota/autoexec.be b/tasmota/autoexec.be index 3675c876..0dad315b 100644 --- a/tasmota/autoexec.be +++ b/tasmota/autoexec.be @@ -327,6 +327,48 @@ class Nextion : Driver end end +def get_current_version(cmd, idx, payload, payload_json) + import string + var version_of_this_script = 1 + var jm = string.format("{\"berry_version\":\"%s\"}", version_of_this_script) + tasmota.publish_result(jm, "RESULT") +end + +tasmota.add_cmd('GetDriverVersion', get_current_version) + +def update_berry_driver(cmd, idx, payload, payload_json) + def task() + import string + var cl = webclient() + cl.begin(payload) + var r = cl.GET() + if r == 200 + print("Sucessfully downloaded nspanel-lovelace-ui berry driver") + else + print("Error while downloading nspanel-lovelace-ui berry driver") + end + r = cl.write_file("autoexec.be") + if r < 0 + print("Error while writeing nspanel-lovelace-ui berry driver") + else + print("Scucessfully written nspanel-lovelace-ui berry driver") + var s = load('autoexec.be') + if s == true + var jm = string.format("{\"berry_update\":\"%s\"}", "succeeded") + tasmota.publish_result(jm, "RESULT") + else + var jm = string.format("{\"berry_update\":\"%s\"}", "failed") + tasmota.publish_result(jm, "RESULT") + end + + end + end + tasmota.set_timer(0,task) + tasmota.resp_cmnd_done() +end + +tasmota.add_cmd('UpdateDriverVersion', update_berry_driver) + var nextion = Nextion() def flash_nextion(cmd, idx, payload, payload_json) From f17bb1613e2c36e3cdc25ef546144dad3691eea6 Mon Sep 17 00:00:00 2001 From: joBr99 <29555657+joBr99@users.noreply.github.com> Date: Sat, 12 Mar 2022 12:53:12 +0100 Subject: [PATCH 3/3] change response names, to avoid confusion with berry lang itself --- tasmota/autoexec.be | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tasmota/autoexec.be b/tasmota/autoexec.be index 0dad315b..ae98514c 100644 --- a/tasmota/autoexec.be +++ b/tasmota/autoexec.be @@ -329,8 +329,8 @@ end def get_current_version(cmd, idx, payload, payload_json) import string - var version_of_this_script = 1 - var jm = string.format("{\"berry_version\":\"%s\"}", version_of_this_script) + var version_of_this_script = 2 + var jm = string.format("{\"nlui_driver_version\":\"%s\"}", version_of_this_script) tasmota.publish_result(jm, "RESULT") end @@ -354,10 +354,10 @@ def update_berry_driver(cmd, idx, payload, payload_json) print("Scucessfully written nspanel-lovelace-ui berry driver") var s = load('autoexec.be') if s == true - var jm = string.format("{\"berry_update\":\"%s\"}", "succeeded") + var jm = string.format("{\"nlui_driver_update\":\"%s\"}", "succeeded") tasmota.publish_result(jm, "RESULT") else - var jm = string.format("{\"berry_update\":\"%s\"}", "failed") + var jm = string.format("{\"nlui_driver_update\":\"%s\"}", "failed") tasmota.publish_result(jm, "RESULT") end @@ -405,4 +405,4 @@ def send_cmd2(cmd, idx, payload, payload_json) tasmota.resp_cmnd_done() end -tasmota.add_cmd('CustomSend', send_cmd2) \ No newline at end of file +tasmota.add_cmd('CustomSend', send_cmd2)