Page 1 of 1

Script Error 512

Posted: Tuesday 07 February 2017 12:07
by emme
Ciao,

I'm struggling with a script that won't run....

I use to run speedtest as a device Event triggered by a virtual pushOn button...
that's the script:

Code: Select all

debugger    = tonumber(uservariables['SpeedTest_Debug'])
JSON        = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()             -- File per la decodifica del tracciato JSON restituito dallo speedtest
cTime       = os.date("*t")     
scName      = '/home/pi/domoticz/scripts/speedtest-json.sh'
runScript   = false                                                             -- Semaforo per esecuzione Procedura
prxPrint    = '>>> [ST] >>> '                                                   -- Prefisso per stringhe di debug 
idxPing     = 146
idxDl       = 147
idxUp       = 148

commandArray = {}

-- Speedtest NET_SpeedTest Button Pushed
    if devicechanged['RUNSpeedTest'] and otherdevices['RUNSpeedTest'] == 'On' then
        runScript = true
    end

-- Script Principale
    if runScript == true then
        
        print(prxPrint..'Esecuzione SpeedTest')
        
        os.execute(scName) 
    
        file = io.open("/home/pi/domoticz/scripts/speed-test.json", "r") 
        print(file)
        json_text = file:read()
        speeds = JSON:decode(json_text)
        
        print(prxPrint..'['..cTime.hour..':'..cTime.min..'] >>> Dl/Ul/Pg: '..speeds.Download_Mbit..'/'..speeds.Upload_Mbit..'/'..speeds.Ping_ms)
    
        commandArray[1]={['UpdateDevice']=tostring(idxDl)..'|0|'..speeds.Download_Mbit}
        commandArray[2]={['UpdateDevice']=tostring(idxUp)..'|0|'..speeds.Upload_Mbit}
        commandArray[3]={['UpdateDevice']=tostring(idxPing)..'|0|'..speeds.Ping_ms}
    
        os.execute("rm /home/pi/domoticz/scripts/speed-test.json")
    end

return commandArray
it works fine.... but I'm willing to move from the event table and use as an external script.
to do this I've copied the script into script_RUNSpeedTest.lua and stored in /home/pi/domoticz/script/
I've also removed the section

Code: Select all

-- Speedtest NET_SpeedTest Button Pushed
    if devicechanged['RUNSpeedTest'] and otherdevices['RUNSpeedTest'] == 'On' then
        runScript = true
    end
which is not needed anymore (the script runs ONLY when the button is pushed)
forsec runScript = true (to skip the removed block and have the rest running)

I've also added # !/usr/bin/lua on top and give the file 0777 rights (rwxrwxrwx)

trigger the OnAction on my pushbutton as: script://script_RUNSpeedTest.lua
...and got this ugly error :o :cry:
2017-02-07 11:59:55.920 Error: Error executing script command (/home/pi/domoticz/scripts/script_RUNSpeedTest.lua). returned: 512
Cannot really figured out what's wrong.... :(
did anyone saw this before and came out from it?! :P
thanks
ciao
M

Re: Script Error 512

Posted: Tuesday 07 February 2017 21:03
by SweetPants
If you run a script outside domoticz event system, you can't use CommandArray or any Domoticz specific commands

Re: Script Error 512

Posted: Wednesday 08 February 2017 8:21
by emme
That's finally clear...

Could it be an idea to explain it crealry on the Wiki also? :P
ciao
M

Re: Script Error 512

Posted: Wednesday 08 February 2017 8:52
by jannl
It always was clear to me from the wiki.
LUA scripts run in specified names (time/device/variable).
Running otherscripts from a switch need the full path (among other things)

Re: Script Error 512

Posted: Wednesday 08 February 2017 8:58
by emme
I do not want to be controversial.. and won't get into it
jannl wrote:Running otherscripts from a switch need the full path (among other things)
This is clear in the wiki
what is not clear is that you don't have domoticz table and specific commands available
well.. you can assume it because in the event trigger section it's well explained...

Have a great day!
ciao
M