Posts: 109
Threads: 41
Joined: Apr 2018
Reputation:
0
Got this script working on LM devices we have, but trying to use this on a project which is using SE's C-BUS NAC / SHAC (MK 1 ), but unfortunately the scripts don't work.
Is there something missing the C-BUS controllers which is preventing the script from working correctly.
May be something like require('apps')
Posts: 8187
Threads: 43
Joined: Jun 2015
Reputation:
473
Do you have anything in Error log?
Posts: 8187
Threads: 43
Joined: Jun 2015
Reputation:
473
Open browser Dev tools (F12), switch to Network tab and check the server response when eventlog.lp is loaded.
Posts: 8187
Threads: 43
Joined: Jun 2015
Reputation:
473
You can copy the missing files from LM via browser and then upload to user directory via FTP. Edit eventlog.lp and change /apps/js/ and /apps/css/ to /user/
Posts: 109
Threads: 41
Joined: Apr 2018
Reputation:
0
Getting closer, now getting an error in the Vis frame "Error in /www/user/eventlog.lp at line 2: attempt to index global 'storage' (a nil value)"
<?
items = storage.exec('lrange', 'eventlog5', 0, 999)
?>
I removed the require ('apps') as this is not being and change the store to eventlog5 so I can test a new.
So the frame is throughing up error with storage.exec line
Posts: 8187
Threads: 43
Joined: Jun 2015
Reputation:
473
It won't work without loading apps library. It should be present in the firmware since .lp handler works.
Posts: 109
Threads: 41
Joined: Apr 2018
Reputation:
0
Unfortunately back to nothing again. BUt no errors in Network Window anymore which is good I think.
This is the Common Function script:-
function eventlog(text)
local max = 1000 -- max number of entries
-- add formatted date
text = os.date('%a %d/%m/%Y %T ') .. text
storage.exec('lpush', 'eventlog5', text)
storage.exec('ltrim', 'eventlog5', 0, max - 1)
end
This is what's in the eventlog.lp
<?
require('apps')
items = storage.exec('lrange', 'eventlog5', 0, 999)
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Event log</title>
<script src="/user/jquery.js.gz"></script>
<link rel="stylesheet" href="/user/bootstrap.css">
</head>
<body>
<script>
$(function() {
var items = <? json.write(items) ?>
, container = $('.container')
, header;
$.each(items, function(index, item) {
var chunks = item.split(' ')
, newheader = chunks.shift() + ' ' + chunks.shift();
// output data header each time it changes
if (newheader != header) {
header = newheader;
$('<h3></h3>').text(header).appendTo(container);
}
// output log entry
$('<p></p>').text(chunks.join(' ')).appendTo(container);
});
});
</script>
<div class="container"></div>
</body>
</html>
For testing used in Event Script
eventlog(event.getvalue())
log(io.ls('/data/apps/store/user'))
log(storage.exec('lrange', 'eventlog5', 0, 999))
This gives back in log:-
Event for 0/1/0 16.06.2025 14:43:45
* table:
[1]
* string: eventlog.lp
[2]
* string: bootstrap.css.gz
[3]
* string: jquery.js.gz
[4]
* string: bootstrap.css
[5]
* string: log.txt
Event for 0/1/0 16.06.2025 14:43:45
* table:
[1]
* string: Mon 16/06/2025 14:43:45 7
[2]
* string: Mon 16/06/2025 14:12:39 239
[3]
* string: Mon 16/06/2025 14:12:30 150
Posts: 8187
Threads: 43
Joined: Jun 2015
Reputation:
473
Open /user/eventlog.lp directly in your browser, press CTRL+u to view the page source and post what you get.
Posts: 8187
Threads: 43
Joined: Jun 2015
Reputation:
473
.lp file works correctly. Most likely jquery cannot be loaded. Check browser console (F12) for any errors.
Posts: 109
Threads: 41
Joined: Apr 2018
Reputation:
0
Thanks for the help.
error was the jquery.js.gz file so extract to just jquery.js and then changed eventlog.lp to /user/jquery.js
Now working thank you for all the help.