Scripting

Description

Queries re using the xap-plugboard component to script xAP action events.

Forums

Hi,

after a long day of searching for the error, I found, that the functions for xap cache access

  • xapcache_find
  • xapcache_getvalue
  • xapcache_gettime

as described in http://www.dbzoo.com/livebox/hah_plugboard#implementation

are no more available (obviously since a new version of lua).

Is there any workarround how to easily access the xap cache now?

I would like to do exactly the described function for evaluating the state of RFs and Relays.

Thank you for your help!

Markus

Forums

When running Lua scripts the module(..., seeall) generates an error, I'm running HAH version 283, but have had the same problem on other versions as well.  Take the following test script :-

module(..., package.seeall)

function hello()
  print("Hello")
end

This generates the following error :-

# lua test1.lua
lua: test1.lua:1: bad argument #1 to 'module' (string expected, got nil)
stack traceback:
        [C]: in function 'module'
        test1.lua:1: in main chunk
        [C]: ?

 

And running Lua interactively :-

# lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require "test1"
> a.hello()
stdin:1: attempt to index global 'a' (a nil value)
stack traceback:
        stdin:1: in main chunk
        [C]: ?

Checking the Lua wiki, where I got the test code from, I can't see anything wrong with what I'm doing. 

Can anyone else help ?

Thanks

 

Karl

Forums

Hi,

Is it possible to reboot the microcontroller via a lua script without reboot the HAH?

 

Thanks,

 

Garry

 

Forums

Here's the scenario.

 

i have a cc128 with 2 sensors (soon to be 3-to monitor grid supply) the main power sensor which monitors house usage power:-

dbzoo.livebox.CurrentCost:ch.1

 

a second which monitors solar power produced :-

dbzoo.livebox.CurrentCost:sensor.1

 

now if i do an xap-snoop all seems fine and is uploaded to pachube (feed 15114 if your interested)

 

problem is after a while (1-2 hours typical) sensor .1 (solar) is not registering on xap-snoop or pachube-stays at same value, a reboot of the HAH fixes this.

 

now short term i want to add a reboot script to reboot the HAH every hour can someone give me a low down on how to do this?

 

long term i am going to put a pc/laptop on the cc128 usb feed to see if its that or the hah playing nasty.

 

help?

 

 

PLEASE

Forums

Hello,

Should following script work - ie. is the syntax/spelling ok?  Or it should not with M8?  Have been trying with 279.14/1.0 and lcd does not change; see no errors and do not manage to snoop related xAP messages either.

Regards,
Aivo 


require("xap")

function send2lcd(lcdstr)
        local msg = string.format([[xap-header
{
target=dbzoo.livebox.controller:lcd
class=xAPBSC.cmd
}
output.state.1
{
id=*
text=%s
}]], lcdstr)
  delay(5)
  xap.sendShort(msg)
  os.exit()
end

function delay(duration)
  duration = duration or 1
  local time_to = os.time() + duration
  while os.time() < time_to do end
end

xap.init("dbzoo.lua.testlcd","FF00DD00","br0")
send2lcd("test123")
xap.process()

 

Forums

 

Hello Bertt / Derek

I’m working on a project to log solar watts/meter – and post the results to Pachube via the HAH livebox. Just now I’m experimenting with several different sensors to see which gives the best tracking over the changing light levels, and to speed up the process I wanted to run multiple sensors in parallel –  I’ve been looking at extracting the channel 1,2,3 data from a TX unit paired as an additional sensor.

The XMl data looks good:

<msg><src>CC128-v1.29</src><dsb>00018</dsb><time>21:05:57</time><tmpr>19.3</tmpr><sensor>0</sensor><id>03402</id><type>1</type><ch1><watts>00363</watts></ch1></msg>

<msg><src>CC128-v1.29</src><dsb>00018</dsb><time>21:09:21</time><tmpr>19.4</tmpr><sensor>1</sensor><id>00759</id><type>1</type><ch1><watts>00367</watts></ch1><ch2><watts>00430</watts></ch2><ch3><watts>00411</watts></ch3></msg>

 

The 3 channels of data associated with sensor 1 seem to be sent from the CC128,

and my question is ................

can I point the existing current cost xAP to this channel data for sensor 1, and hence post the data to Pachube?

 

Regards

 

Harry

Forums

I'm trying to get a timer to automatically restart, as per the wiki example, however it wont.  Below is the simple test lua script that I'm using :-

-- Update the LCD every minute with the current time
function init()
  -- After 10 seconds the 't1' timer will expire and call the 'doclock' function.
  start_timer("t1",10,"doclock")
end
 
function doclock()
  print("Starting LCD timer!")
  -- Reset the timer so it calls 'doclock' again in 10 seconds.
  start_timer("t1",10,"doclock")
end

 

This produces the following output :-

# xap-plugboard -d 5 -i br0

xAP Plugboard - for xAP v1.2
Copyright (C) DBzoo 2009

br0: address 192.168.1.55
br0: netmask 255.255.255.0
Autoconfig: xAP broadcasts on 192.168.1.255:3639
xAP uid=FF02D800, source=dbzoo.livebox.2.Plugboard
Debug level 5
Broadcast socket port 3639 in use
Assuming a hub is active
Socket port 3640 in use
Discovered port 3641
loadScripts(/etc/plugboard)
loadScript(lcd_timer.lua)
start_timer(t1,1290268780,doclock)
Ready
Fire Timer t1 calling doclock
Starting LCD timer!
start_timer(t1,1290268791,doclock)

 

And that's it, I would have expected to see the "Starting LCD timer!" and the "start_timer(.....", output on the screen every 10 seconds. 

Can anyone see what I'm doing wrong?  I'm running with HAH version 255.

Thanks

 

Karl

Forums

Hi,

I've been having a go with the plugboard and sample scripts, in particular the gcal_on_state script. The script seems to be working fine however no event appears on my calendar. I ran xap-googlecal with debug level 9 and got this:

 

Send EVENT to Google

event(title=Relay 1 is off,start=2010-10-17T00:00:00,end=2010-10-17T00:01:00,where=xap-event,content=LUA monitored event)

Failed adding a new event! HTTP code: 201

msg: (null)

Any ideas what's going on?
Chris

 

Forums

I don't think the the Google Alias is working correctly.  It doesn't produce the xAP message as described on the Wiki, http://www.dbzoo.com/livebox/hah#calendar_aliases.

The debug log below shows the xap-googlecal detecting events, but instead of sending a properly formatted xAP message, it just sends "xap".

Looking at the googlecal.c code, does it have anything to do with a /etc/xap-alias.xml file, which doesn't exist on my HAH.


# xap-googlecal -d 7

Google Calendar Connector for xAP v12
Copyright (C) DBzoo 2009

br0: address 192.168.1.5
br0: netmask 255.255.255.0
Autoconfig: xAP broadcasts on 192.168.1.255:3639
xAP uid=FF00DA00, source=dbzoo.livebox.GoogleCal
Debug level 7
Broadcast socket port 3639 in use
Assuming a hub is active
Socket port 3639 in use
Socket port 3640 in use
Socket port 3641 in use
Socket port 3642 in use
Discovered port 3643
Connecting to google
19:43:00 - Reloading EVENT cache
Google query params: start-min=2010-09-30T19:43:00Z&start-max=2010-09-30T19:44:00Z&singleevents=true
Dump event cache - found 1 events
event(title=rf 1 off,start=2010-09-30T20:25:00.000+01:00,end=2010-09-30T21:26:00.000+01:00,where=xap,content=)
19:43:00 - Check Trigger events
Trigger event(title=rf 1 off,start=2010-09-30T20:25:00.000+01:00,end=2010-09-30T21:26:00.000+01:00,where=xap,content=)
Send XAP message
xap
19:44:00 - Reloading EVENT cache
Google query params: start-min=2010-09-30T19:44:00Z&start-max=2010-09-30T19:45:00Z&singleevents=true
Dump event cache - found 2 events
event(title=rf 1 on,start=2010-09-30T20:44:00.000+01:00,end=2010-09-30T20:45:00.000+01:00,where=xap,content=)
event(title=rf 1 off,start=2010-09-30T20:25:00.000+01:00,end=2010-09-30T21:26:00.000+01:00,where=xap,content=)
19:44:00 - Check Trigger events
Trigger event(title=rf 1  on,start=2010-09-30T20:44:00.000+01:00,end=2010-09-30T20:45:00.000+01:00,where=xap,content=)
Send XAP message
xap
Trigger event(title=rf 1 off,start=2010-09-30T20:25:00.000+01:00,end=2010-09-30T21:26:00.000+01:00,where=xap,content=)
Send XAP message
xap
19:45:00 - Reloading EVENT cache
Google query params: start-min=2010-09-30T19:45:00Z&start-max=2010-09-30T19:46:00Z&singleevents=true
Dump event cache - found 1 events
event(title=rf 1 off,start=2010-09-30T20:25:00.000+01:00,end=2010-09-30T21:26:00.000+01:00,where=xap,content=)
19:45:00 - Check Trigger events
Trigger event(title=rf 1 off,start=2010-09-30T20:25:00.000+01:00,end=2010-09-30T21:26:00.000+01:00,where=xap,content=)
Send XAP message
xap
19:46:00 - Reloading EVENT cache
Google query params: start-min=2010-09-30T19:46:00Z&start-max=2010-09-30T19:47:00Z&singleevents=true
Dump event cache - found 1 events
event(title=rf 1 off,start=2010-09-30T20:25:00.000+01:00,end=2010-09-30T21:26:00.000+01:00,where=xap,content=)
19:46:00 - Check Trigger events
Trigger event(title=rf 1 off,start=2010-09-30T20:25:00.000+01:00,end=2010-09-30T21:26:00.000+01:00,where=xap,content=)
Send XAP message
xap

#

Forums

Hi Brett,

I've been wondering about the scripts and have a couple of questions for you, hope you don't mind, I've just chucked em into a list:

1. Why lots of scripts (per function), is this necessary?

I suspect this is down to efficiency, having observed the plugboard, it only has to run a small script if an event is triggered....am I close?  How many function would you suggest to run in one script?

2. Is it possible to pass variables accross scripts

i.e. set a global variable of presence=true --  someone is at home

or dusk=true -- it's dark out

and then be able to work with these variables from any script?

3. Why use "local" in front of a variable, does that just limit the variable to that function or that script file?

4. Do I need to be careful about variable names accross my scripts, so as not to have same variables names?

5. What is a class used for as opposed to a target or a source?

i.e can you explain laymans terms why I would register a class as opposed to a source? as in your alias examples.

 

The whole LUA thing is just alien to me and I think the answers to some of the questions above, may just help me step forward a little.

 

Cheers

Gary