From d0fefe2c8b4c39c96bba64107275bff9088c2332 Mon Sep 17 00:00:00 2001 From: Michael Andreasen Date: Mon, 24 Jan 2022 13:04:51 +0000 Subject: [PATCH] --- berry/nextion.be | 71 ++++++++++++++++--- .../proto/nsflash/MakeChunksFrame.java | 2 + 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/berry/nextion.be b/berry/nextion.be index 8cf6293..8235948 100644 --- a/berry/nextion.be +++ b/berry/nextion.be @@ -6,7 +6,7 @@ class Nextion : Driver static CHUNK_FILE = "nextion" - static header = "PS" + static header = bytes().fromstring("PS") var flash_mode var ser @@ -36,6 +36,7 @@ class Nextion : Driver def encode(payload) var b = bytes() b += self.header + var nsp_type = 0 # not used b.add(nsp_type) # add a single byte b.add(size(payload), 2) # add size as 2 bytes, little endian b += bytes().fromstring(payload) @@ -54,7 +55,17 @@ class Nextion : Driver import string var payload_bin = self.encodenx(payload) self.ser.write(payload_bin) - log(string.format("NSP: Nextion command sent = %s",str(payload_bin)), 3) + log(string.format("NSP: Nextion command sent = %s",str(payload_bin)), 3) + end + + def send(payload) + var payload_bin = self.encode(payload) + if self.flash_mode==1 + log("NSP: skipped command becuase still flashing", 3) + else + self.ser.write(payload_bin) + log("NSP: payload sent = " + str(payload_bin), 3) + end end def getPage(url) @@ -70,7 +81,7 @@ class Nextion : Driver else s = nil retry = retry + 1 - log("NSP: HTTP retry reuired") + log("NSP: HTTP retry required") end wc.close() end @@ -110,6 +121,7 @@ class Nextion : Driver def screeninit() log("NSP: Screen Initialized") + tasmota.publish_result("{\"Init\": \"true\"", "RESULT") end def every_100ms() @@ -130,7 +142,7 @@ class Nextion : Driver var per = (self.tot_read*100)/self.flash_size if (self.last_per!=per) self.last_per = per - tasmota.publish_result(string.format("{\"NSPanel\":{\"Flashing\":{\"complete\": %d}}}",per), "RESULT") + tasmota.publish_result(string.format("{\"Flashing\":{\"complete\": %d}}",per), "RESULT") end if (self.tot_read==self.flash_size) log("NSP: Flashing complete") @@ -141,13 +153,13 @@ class Nextion : Driver else if msg == bytes('000000FFFFFF88FFFFFF') self.screeninit() - elif msg[0]==0x4A # J - var jm = string.format("{\"NSPanel\":{\"JSON\":\"%s\"}}",msg[1..-1].asstring()) + elif msg[0]==0x7B + var jm = string.format("{\"json\":%s}",msg[0..-1].asstring()) tasmota.publish_result(jm, "RESULT") - elif msg[0]==0x54 # T + elif msg[0]==0x07 # T tasmota.cmd("buzzer 1,1") else - var jm = string.format("{\"NSPanel\":{\"Nextion\":\"%s\"}}",str(msg[0..-4])) + var jm = string.format("{\"nextion\":\"%s\"}",str(msg[0..-4])) tasmota.publish_result(jm, "RESULT") end end @@ -156,6 +168,7 @@ class Nextion : Driver end def begin_file_flash() + self.flash_mode = 1 var f = open("test.bin","w") f.close() while self.tot_read nextion.set_power()) +tasmota.add_rule("power2#state", /-> nextion.set_power()) +tasmota.cmd("Rule3 1") # needed until Berry bug fixed +tasmota.add_rule("Time#Minute", /-> nextion.set_clock()) +tasmota.cmd("State") + + diff --git a/src/systems/proto/nsflash/MakeChunksFrame.java b/src/systems/proto/nsflash/MakeChunksFrame.java index 7794b76..7b714a0 100644 --- a/src/systems/proto/nsflash/MakeChunksFrame.java +++ b/src/systems/proto/nsflash/MakeChunksFrame.java @@ -83,6 +83,8 @@ private void build() { props.setProperty(PROP_FILE, tftFile.getAbsolutePath()); props.setProperty(PROP_DIR, chunkDir.getAbsolutePath()); props.store(new FileWriter(propsFile), null); + outFile.close(); + is.close(); } catch (Exception ex) { Logger.getLogger(MakeChunksFrame.class.getName()).log(Level.SEVERE, null, ex); }