This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

eventlog.lp
#1
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')
Reply
#2
Do you have anything in Error log?
Reply
#3
(16.06.2025, 06:45)admin Wrote: Do you have anything in Error log?

There are no error log. The frame just doesn't show any information.
I have setup the same as we do with any LM machines, so not sure why the NAC doesn't work.
Changed eventlog/lp name in and the frame, when we do this frame shows file does not exist. So I know its looking at the correct folder and file name eventlog.lp

We can see data in storage when we use 
items = storage.exec('lrange', 'eventlog', 0, 10)
tex = table.concat(items, '\r\n')
log(tex)
Reply
#4
Open browser Dev tools (F12), switch to Network tab and check the server response when eventlog.lp is loaded.
Reply
#5
(16.06.2025, 07:54)admin Wrote: Open browser Dev tools (F12), switch to Network tab and check the server response when eventlog.lp is loaded.

Please see attached error with bootstrap.css and js/jquery that are not found.
So think it may be associated with the require('apps') that may not be supported in NAC . Not sure though

Attached Files Thumbnail(s)
   
Reply
#6
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/
Reply
#7
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
Reply
#8
It won't work without loading apps library. It should be present in the firmware since .lp handler works.
Reply
#9
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
Reply
#10
Open /user/eventlog.lp directly in your browser, press CTRL+u to view the page source and post what you get.
Reply
#11

<!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 = ["Mon 16\/06\/2025 14:43:45 7","Mon 16\/06\/2025 14:12:39 239","Mon 16\/06\/2025 14:12:30 150"]
, 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>
Reply
#12
.lp file works correctly. Most likely jquery cannot be loaded. Check browser console (F12) for any errors.
Reply
#13
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.
Reply


Forum Jump: