We have moved at community.getvera.com

Author Topic: openLuup: Tips & Tricks  (Read 6657 times)

Offline d55m14

  • Sr. Member
  • ****
  • Posts: 449
  • Karma: +8/-1
Re: openLuup: Tips & Tricks
« Reply #15 on: October 30, 2017, 06:04:40 am »
Hi akbooer,

sorry  if this is not the correct thread but I'd ask you if there's any problem to run Openluup on a 64 bit Unix Operating System.

tnks

donato

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: Tips & Tricks
« Reply #16 on: October 30, 2017, 06:32:50 am »
sorry  if this is not the correct thread but I'd ask you if there's any problem to run Openluup on a 64 bit Unix Operating System.

openLuup runs on any system that supports Lua.  That's no problem at all.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: Tips & Tricks
« Reply #17 on: February 07, 2018, 06:24:07 am »
On an RPi you can use shared memory to store openLuup logs with the following Lua Startup code:

Code: [Select]
-- openLuup logs in RAM
local lfs = require "lfs"
local logs = "/dev/shm/logs"
if not lfs.attributes (logs) then lfs.mkdir (logs) end
luup.attr_set ("openLuup.Logfile.Name", logs .. "/LuaUPnP.log")

-- /var/log/cmh/  ensure it's there for AltUI logs
-- won't work the first time it's created
local altlog = logs .. "/altui"
lfs.mkdir (altlog)
lfs.link (altlog, "/var/log/cmh", true)     -- true for symbolic link

...you'll need to reload twice after editing Lua Startup to make this effective.

It's a good way to be kind to your RPi non-volatile memory, since it's stored in RAM.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline pls90

  • Sr. Member
  • ****
  • Posts: 314
  • Karma: +2/-0
Re: openLuup: Tips & Tricks
« Reply #18 on: February 22, 2018, 02:57:19 pm »
when I add your ram drive code to lua startup I get
Code: [Select]
Lua Startup can only be modified on controller 0

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: Tips & Tricks
« Reply #19 on: February 22, 2018, 03:44:16 pm »
Your AltUI version amd openLuup version don't match.  There have been recent security changes. you need to update to the latest openLuup development version and the latest AltUI.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: openLuup: Tips & Tricks
« Reply #20 on: March 10, 2018, 12:55:45 pm »
Using AltUI to back up your user_data.json file

The latest build of AltUI (1608) adds a 'backup' button to the Controllers page.  On Vera, this backs up your configuration to a file on your browsing machine by running a CGI file.  Under openLuup, you can make this do anything you want by writing the appropriate WSAPI CGI Lua script.

The script file should go into /etc/cmh-ludl/cgi-bin/cmh/backup.sh and here's an example which simply backs up to a file in /etc/cmh-ludl/backups/.  The filename has the format backup.openLuup-00000000-2016-05-01, so only unique once a day.  The "00000000" is replaced by whatever PK_AccessPoint you've given your machine.

Code: [Select]
#!/usr/bin/env wsapi.cgi

module(..., package.seeall)

ABOUT = {
  NAME          = "backup.sh",
  VERSION       = "2016.04.30",
  DESCRIPTION   = "user_data backup script /etc/cmh-ludl/cgi-bin/cmh/backup.sh",
  AUTHOR        = "@akbooer",
  DOCUMENTATION = "https://github.com/akbooer/openLuup/tree/master/Documentation",
}

local DIRECTORY     = "backup"      -- change this if you want to backup elsewhere

-- WSAPI Lua implementation of backup.sh
-- backup written to ./backups/backup.openLuup-00000000-2015-01-21

local userdata = require "openLuup.userdata"
local lfs = require "lfs"

local _log    -- defined from WSAPI environment as wsapi.error:write(...) in run() method.


-- global entry point called by WSAPI connector

--[[

The environment is a Lua table containing the CGI metavariables (at minimum the RFC3875 ones) plus any
server-specific metainformation. It also contains an input field, a stream for the request's data,
and an error field, a stream for the server's error log.

The input field answers to the read([n]) method, where n is the number
of bytes you want to read (or nil if you want the whole input).

The error field answers to the write(...) method.

return values: the HTTP status code, a table with headers, and the output iterator.

--]]

function run (wsapi_env)
  _log = function (...) wsapi_env.error:write(...) end      -- set up the log output, note colon syntax -- 2016.02.26
 
  lfs.mkdir (DIRECTORY)
   
  local PK = userdata.attributes.PK_AccessPoint or "XXXXXXXX"
  local DATE = os.date "%Y-%m-%d" or "0000-00-00"
  local fmt = "%s/backup.openLuup-%s-%s"
  local fname = fmt: format (DIRECTORY, PK, DATE) 
  _log ("Backing up user_data to " .. fname)
 
  local ok, msg = userdata.save (nil, fname)   -- save current luup environment
 
  local status, return_content
  if ok then
    status, return_content  = 200, "backup completed"
  else
    status, return_content  = 500, "backup failed: " .. msg
  end
 
  local headers = {["Content-Type"] = "text/plain"}
 
  local function iterator ()     -- one-shot iterator, returns content, then nil
    local x = return_content
    return_content = nil
    return x
  end

  return status, headers, iterator
end

-----

You'll also need the latest commit from the openLuup GitHub development branch to make this work.

Got the backup script to work but... how to recover the configuration from the backup?
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: Tips & Tricks
« Reply #21 on: March 10, 2018, 01:52:48 pm »
See, for example

http://forum.micasaverde.com/index.php/topic,61958.msg355170.html#msg355170

I really should provide a button for that from the backup page...
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: Tips & Tricks
« Reply #22 on: May 16, 2018, 05:44:33 am »
For those developing plugins on openLuup:

openLuup caches files it reads with a routine called:  memoize()  in loader.lua. This means that if you change a service file before attempting to install a related plugin, you must restart the openLuup engine before attempting to create the plugin with the modified service file.

Yes, this is certainly the case.  The caching significantly improves startup performance and reduces disk I/O for frequently read service and device files.   Lua files are not cached, since they're almost always uniquely read once, and in fact, are the most likely ones to be changed during development.

ALWAYS reload if you hack the device files of already-loaded devices.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.