Error after updating

Moderator: leecollings

Post Reply
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

Error after updating

Post by JimmyH1969 »

Hi all,

i've been using a script for a long time, but after updating Domoticz it throws an error:

Script part:

Code: Select all

	tempfilename = "UnifiController.tmp" -- Temp JSON output file
	local f = io.popen("stat -c %Y " .. tempfilename)
	local last_modified = f:read()
	if (os.difftime (os.time(), last_modified) > 30)
	then
		-- All kind of actions are executed here.
		-- Execute url
		-- Execute url
		read_login = os.execute(url_login)
		read_open = os.execute(url_open)
		read_logout = os.execute(url_logout)
	end
The error i get is on this line: if (os.difftime (os.time(), last_modified) > 30)
Error: [string " ..."]:14: bad argument #2 to 'difftime' (number expected, got nil)

Any ideas? I know it's probably because of a change in LUA, but i cant find it.

Tnx in advance!
User avatar
waltervl
Posts: 5851
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Error after updating

Post by waltervl »

If I read the error correct the second argument of difftime (=last_modified) is empty.
So your line

Code: Select all

 local last_modified = f:read()
is not working correctly.

Perhaps the file "UnifiController.tmp" is on a different place? Other access rights?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

Re: Error after updating

Post by JimmyH1969 »

Tnx for the reply.

The file is at that location and with the same rights, but i do agree it has something to do with that.
User avatar
psubiaco
Posts: 222
Joined: Monday 20 August 2018 9:38
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Italy
Contact:

Re: Error after updating

Post by psubiaco »

If the file contains a valid number, try to use tonumber() function to convert its content to a number:

local last_modified = tonumber(f:read())
Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

Re: Error after updating

Post by JimmyH1969 »

Mhh, to test things i created a smaal script that should just get the last modified date of a file, like:

Code: Select all

commandArray = {}

	tempfilename = 'UnifiController.tmp' -- Temp JSON output file
	local f = io.popen("stat -c %Y " ..tempfilename)
	local last_modified = f:read()
	--local last_modified = tonumber(f:read())
	
	print("io.popen-1: " ..os.date("%c", last_modified))

return commandArray
The return is always the execution time of the script: LUA: io.popen-1: Wed Jun 30 12:07:00 2021
Even if i specify another file with a much older date and even if i specify a non existing file.
This is on Windows btw...

Any ideas?
User avatar
psubiaco
Posts: 222
Joined: Monday 20 August 2018 9:38
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Italy
Contact:

Re: Error after updating

Post by psubiaco »

I've checked with LUA 5.3:
it works if you remove the local keyword:
f = io.popen("stat -c %Y " ..tempfilename)
last_modified = f:read()
Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

Re: Error after updating

Post by JimmyH1969 »

No difference for me...
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest