Logic Machine Forum
eventlog.lp - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: eventlog.lp (/showthread.php?tid=6023)



eventlog.lp - sjfp - 15.06.2025

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


RE: eventlog.lp - admin - 16.06.2025

Do you have anything in Error log?


RE: eventlog.lp - sjfp - 16.06.2025

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


RE: eventlog.lp - admin - 16.06.2025

Open browser Dev tools (F12), switch to Network tab and check the server response when eventlog.lp is loaded.


RE: eventlog.lp - sjfp - 16.06.2025

(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


RE: eventlog.lp - admin - 16.06.2025

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/


RE: eventlog.lp - sjfp - 16.06.2025

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


RE: eventlog.lp - admin - 16.06.2025

It won't work without loading apps library. It should be present in the firmware since .lp handler works.


RE: eventlog.lp - sjfp - 16.06.2025

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


RE: eventlog.lp - admin - 16.06.2025

Open /user/eventlog.lp directly in your browser, press CTRL+u to view the page source and post what you get.


RE: eventlog.lp - sjfp - 16.06.2025


<!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>



RE: eventlog.lp - admin - 16.06.2025

.lp file works correctly. Most likely jquery cannot be loaded. Check browser console (F12) for any errors.


RE: eventlog.lp - sjfp - 16.06.2025

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.