xap.Timer issues with LCD Applet

9 replies [Last post]
AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012

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

 

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
Build it and they will come

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.

AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Hi Mark, Give it a go! this

Hi Mark,

 

Give it a go! this is only possibly thanks to you :)

 

Andrew

AttachmentSize
20x4lcdApplet.lua 2.45 KB
mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
20 x 4 display

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

AttachmentSize
20x4lcdApplet.lua 2.61 KB
AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Hi Mark,thanks for the

Hi Mark,

thanks for the comments, Brett is indeed the true master of lua prehaps he will be along to optimise both our efforts ;)

Strangely enough i cannot get your code to run up at all, it just sits at the ip address and doesnt attempt to run...(same behavior once i have changed the jeenode to my 1wire code)

i have compared our codes and can see you have modified filter2 with the jeenode code, change the function name accordingly and set the currentcost channel from * to 1

spaced out a few of the functions, tided up some spacing etc

I just tided up my version and still have the same issue, timer stops after a couple of minutes, im assuming its quiting at the CatchCurrentCost section as it never gets far enough to display the watts

thanks

Andrew

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
The bit that made it crash fo

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
mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
I changed it to thisfunction

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 :)

AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Other than adding the prefix

Other than adding the prefix for the Wattage i cant see any other difference? puzzled

im guessing its related to setting a text var "Value3" to a numeric value (Wattage) without prefixing with text first as the other values all start with A-Z as pulled from the ini i.e "Sensor 1"

just added a prefix and all is well :)

p.s i was going to add a prefix section in V2 :)

next up - to add text scrolling next and maybe a status line for RF / Relay commands

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
spot the difference
string.len(unit3)))

string.len(Unit3)))

LUA is fussy sometimes about capitalisation
AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
I wouldnt have spotted that

I wouldnt have spotted that in a million years :)

even had the other half staring at it for 10 minutes

LUA is extremely fussy in general!!

Andrew

Hardware Info