xap.Timer issues with LCD Applet
Hi All,
Im scripting an Applet to use with my 20x4 LCD, all is working well so far except i appear to have a timer issue
the script will happily run for 5 - 10 minutes or so and then appears to just stop - occasionally the HAH becomes unresponsive - memory leak??
im not stopping or the deleting the timer at anypoint as yet, its scripted in a way that i want the timer to continuly run... perhaps this is the issue
module(...,package.seeall)
require("xap")
info = {version="1.0", description="20x4LCDInfo"}
lcdcols = 20 -- Specify for LCD Row length
fill = " " -- Char used to fill blank LCD colums
Line1 = "Waiting for Data - 1"..string.rep(fill, lcdcols - string.len("Waiting for Data - 1")) -- Sets Line Var to contain basic text until overwritten with Catch routines
Line2 = "Waiting for Data - 2"..string.rep(fill, lcdcols - string.len("Waiting for Data - 2"))
Line3 = "Waiting for Data - 3"..string.rep(fill, lcdcols - string.len("Waiting for Data - 3"))
Line4 = "Waiting for Data - 4"..string.rep(fill, lcdcols - string.len("Waiting for Data - 4"))
Unit1 = " oC" -- Customisable Units (note the space prefix)
Unit2 = " oC"
Unit3 = " Watts"
function init() -- Sets up 3 filters
Filter1 = xap.Filter()
Filter1:add("xap-header", "source", "dbzoo.livebox.Controller:1wire.1")
Filter1:callback(catch1wire1) -- A temperature change in the filter will trigger the Catch1wire1 routine
Filter2 = xap.Filter()
Filter2:add("xap-header", "source", "dbzoo.livebox.Controller:1wire.2")
Filter2:callback(catch1wire2)
Filter3 = xap.Filter()
Filter3:add("xap-header", "source", "dbzoo.livebox.CurrentCost:ch.*")
Filter3:callback(catchCurrentCost)
send2lcd("Waiting for Data") -- Test LCD at applet start
xap.Timer(update, 10):start() -- Starts update routine timer with a 10 second interval
end
function catch1wire1()
Value1 = xap.getValue("input.state","displaytext") -- Sets Value1 as 1Wire data
Line1 = Value1..Unit1..string.rep(fill, (lcdcols - string.len(Value1) - string.len(Unit1))) -- Sets Line1 Var with 1Wire data (Value1) and appends Unit1, fills remaining Lcd colums with spaces
end
function catch1wire2()
Value2 = xap.getValue("input.state","displaytext")
Line2 = Value2..Unit2..string.rep(fill, (lcdcols - string.len(Value2) - string.len(Unit2)))
end
function catchCurrentCost()
Value3 = xap.getValue("input.state","text")
Line3 = Value3..Unit3..string.rep(fill, (lcdcols - string.len(Value3) - string.len(unit3)))
end
function update(self) -- Timer routine
Line4 = " "..os.date("%H:%M") -- Sets Line 4 as basic clock
lcdstring = Line1..Line2..Line3..Line4 -- Conbines all LCD Lines1-4 into one string ready to send to the LCD every 10 seconds
send2lcd(lcdstring) -- Sends to LCD
end
function send2lcd(lcdstr) -- LCD Routine
xap.sendShort(string.format([[xap-header
{
target=dbzoo.livebox.Controller:lcd
class=xAPBSC.cmd
}
output.state.1
{
id=*
state=on
text=%s
}]], lcdstr))
end
Hi Andrew
I've edited it for my system, ironed out a couple of bugs and it's been working fine now for a couple of hours.
Well done on the coding, I'm sure Brett will pull it to bits but hey ho, we can only try to follow the LUA Jedi master, we can never become one with him ;)
There were a couple of typos in the code that would have only thrown up an error every now and then depending on your system.
Here is my version
Attachment | Size |
---|---|
20x4lcdApplet.lua | 2.61 KB |
The bit that made it crash fo me was this bit
function catchCurrentCost() Value3 = xap.getValue("input.state","text") Line3 = Value3..Unit3..string.rep(fill, (lcdcols - string.len(Value3) - string.len(unit3))) end
I changed it to this
function catchCurrentCost()
Value3 = "Electric live - "..xap.getValue("input.state","text")
Line3 = Value3..Unit3..string.rep(fill, (lcdcols - string.len(Value3) - string.len(Unit3)))
end
Spot the difference :)
string.len(unit3)))
string.len(Unit3)))
LUA is fussy sometimes about capitalisation
This is why I started the 20x4 display, I knew someone else would get interested too :)
I'm liking what you are trying to do. If you want I'll try it out myself and see what I find.