Vera Sysmon : Looking for Lua code to do a few things

I built a hardware extender for Vera that solves a couple of problems i have with the thing. ( Realtime clock , watchdog , UPS , status display , IP address etc ) ( see my post on ‘SysMon’ in ‘general’ for more info
The hardware and firmware are running. now onto the Lua code.

i am looking for a few simple things. Instead of reinventing the wheel and spending day reading all the documentation i will ‘crowdsource’.

Qustion1 : Clock related
How can i read the current date and timefrom a LUA script and store this in a variable ?
How can i SET the current date and time from within a LUA script?

My hardware extender has a true battery backed RTC with perpetual calender. If Vera reboots and has no NNTP access i want to have a script that can read the RTC and set vera’s time/date. I will make a simple script : retrieve system timedate , retrieve RTC timedate. see who has the most recent timestamp → commit to either vera or NNTP. This script will fire once every 5 minutes or so. that way the RTC is kept up to date with NNTP ( if there is NNTP ) or vera will keep up to date with the RTC.

question2: Network related
How can i read Vera’s IP address. Sysmon has a status line. One of the things i want to do is show vera’s Ip address.

Any idea’s are welcome.

1 Like

[tt]os.time()[/tt] will get the current time in Unix timestamp format (seconds since epoch).

[tt]os.date()[/tt] will get the current time and date in human readable format.

You can set the date and time with [tt]os.execute (‘date -s “2 OCT 2006 18:00:00”’)[/tt].

[tt]cat /var/state/network[/tt] will show you network info for Vera. Here is the function to execute a command and return the output:

[code]-------------------------------------------------------------------------------------
– Execute the command and return the stdout.

local function execute (command)

local file = io.popen (command)
local data = file:read ("*a")
file:close()

-- We want to return nil instead of the empty string.
if data == "" then
    data = nil
end

return data

end[/code]

If you want only the IP address you can get it with:

local ipAddr = execute ("cat /var/state/network | grep network.wan.ipaddr") ipAddr = ipAddr:match (".*=(.*)")

1 Like