Page 1 of 2

Lua is not working anymore

Posted: Tuesday 21 November 2017 21:35
by Derik
Dear al i did use a external lua script [ in map scripts...]
Now i did setup my new Domoticz hardware...
And try to make the script working in the internal lua option..
Do have:
ScreenShot068.png
ScreenShot068.png (100.57 KiB) Viewed 2408 times
Only not working anymore..
Perhaps someone see where a thing is going wrong?

Thanks for the help

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 16:58
by SweetPants
When posting code, please use the Code blocks. Nobody will type over your script

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 17:38
by emme
are you sure you have NC installed into your new hardware?

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 18:35
by Derik
emme wrote: Wednesday 22 November 2017 17:38 are you sure you have NC installed into your new hardware?

MM
NC what package???
How to install/check?

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 20:30
by emme
try to run it in a shell window...
what kind of hardware are you running?

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 20:40
by Derik
my hardware is Odriod Xu4 with dietpi
shell?

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 20:57
by Derik
Code:

Code: Select all

commandArray = {}

  --print ("D.M.: IP Port check")

  function update_portalive(name,ip,port)

  
    -- Windows https://joncraton.org/blog/46/netcat-for-windows/ untested

    s = "nc -z -w 1  " .. ip .." " .. tostring(port)
    if (os.execute(s) == nil) then
      if (otherdevices[name] == 'On') then
        commandArray[name] = 'Off'
        print (name .. " Dead")
      end 
    else
      if (otherdevices[name] == 'Off') then
        print (name .. " Is a Alive")
        commandArray[name] = 'On'
      end
    end
end


  -- Fill in your services here  NAMEOFVIRTUALDEVICE    IP   PORT

  update_portalive("Port: Schuurtje","192.168.5.98",552)
  update_portalive("Port: Solarmeter","192.168.5.99",555)
 update_portalive("Port: Dakrand","192.168.5.97",553)
  update_portalive("Port: Domoticz 1","192.168.5.75",8081)
  update_portalive("Port: Domoticz 3","192.168.5.3",8083)
  update_portalive("Port: Domoticz 2","192.168.5.147",8082)
  update_portalive("Port: Minecraft","192.168.5.147",22222)
  
return commandArray


Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 21:05
by jvdz
So what is shown in the domoticz log file? it should show at least the text: D.M.: IP Port check

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 21:11
by Derik
jvdz wrote: Wednesday 22 November 2017 21:05 So what is shown in the domoticz log file? it should show at least the text: D.M.: IP Port check
Yep there is:

Code: Select all

2017-11-22 21:10:00.074 LUA: D.M.: IP Port check
Only no switching devices

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 21:17
by jvdz
Ok, so do as emme stated: run the command from the command prompt (shell) on the domoticz server to see what the result is.

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 21:21
by Derik
when i do the script on the old way..
Set a document in the script folder.
And activate it wit./name_of_script
Also in domoticz the same log.
Only no switching devices.

So i think i mis a package...
only what is NC?

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 21:30
by jvdz
You could have done a simple google search to check that out. ;)
https://www.google.nl/search?q=Linux+nc ... nc+command

Jos

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 21:35
by Derik
yep google is always your friend...
Only i do not understand nc...?
And now i see

Code: Select all

Ongeveer 556.000 resultaten (0,80 seconden) 
So i am a bricklayer not a linux epxert...

Re: Lua is not working anymore

Posted: Wednesday 22 November 2017 21:45
by jvdz
Derik wrote: Wednesday 22 November 2017 21:35 So i am a bricklayer not a linux expert...
... but it seems you want to learn as you are participating in an English spoken Domoticz opensource community where one is expected to have an DIY approach.
I know it is easy for me to state this as I am working all my life in IT, so sorry for that, but when I started with Domoticz I had zero Raspberry knowledge and solely worked with big IBM Mainframes and any flavor of Microsoft OS. This meant for me to do a shitload of research on linux, domoticz, lua ESPEASY and took me around a year to get comfortable doing all the programming in LUA myself.

Just keep smiling and digging away and one day you get there. :D
Jos

Re: Lua is not working anymore

Posted: Thursday 23 November 2017 19:58
by Derik
I know...
I can use espeasy rpi openwrt autocad solidworks sketchup odriod domoticz minecraftserver windows office html etc..
Only lua i do not understand...
Like is say... runs for a few years..
A new setup, and not working any more...

when i run from putty:

Code: Select all

root@DietPi:/home/domoticz/scripts/lua# ./script_time_portcheck.lua
./script_time_portcheck.lua: regel 1: commandArray: opdracht niet gevonden
./script_time_portcheck.lua: regel 3: syntaxfout nabij onverwacht symbool '"D.M.: IP Port check"'
./script_time_portcheck.lua: regel 3: `  print ("D.M.: IP Port check")'
root@DietPi:/home/domoticz/scripts/lua#
So thanks for all te support...

Re: Lua is not working anymore

Posted: Thursday 23 November 2017 22:07
by jvdz
You can't run the script from the command prompt as the eventsystem tables are missing when not shelled from the eventsystem.
Just add some more debug print() statements in the script in an effort to debug the whole script.
what does this script return in the logfile?:

Code: Select all

commandArray = {}

--print ("D.M.: IP Port check")

function update_portalive(name, ip, port)

    -- Windows https://joncraton.org/blog/46/netcat-for-windows/ untested

    s = "nc -z -w 1  " .. ip .." " .. tostring(port)
    print("debug:"..s)
    if (os.execute(s) == nil) then
        print("debug:  nil returned.  status of "..name.."="otherdevices[name])
        if (otherdevices[name] == 'On') then
            commandArray[name] = 'Off'
            print(name .. " Dead")
        end
    else
        print("debug: Not nil returned.  status of "..name.."="otherdevices[name])
        if (otherdevices[name] == 'Off') then
            print(name .. " Is a Alive")
            commandArray[name] = 'On'
        end
    end
end


-- Fill in your services here  NAMEOFVIRTUALDEVICE    IP   PORT

update_portalive("Port: Schuurtje", "192.168.5.98", 552)
update_portalive("Port: Solarmeter", "192.168.5.99", 555)
update_portalive("Port: Dakrand", "192.168.5.97", 553)
update_portalive("Port: Domoticz 1", "192.168.5.75", 8081)
update_portalive("Port: Domoticz 3", "192.168.5.3", 8083)
update_portalive("Port: Domoticz 2", "192.168.5.147", 8082)
update_portalive("Port: Minecraft", "192.168.5.147", 22222)

return commandArray
Jos

Re: Lua is not working anymore

Posted: Thursday 23 November 2017 23:58
by Derik
This is all:

Code: Select all

2017-11-23 23:57:00.171 LUA: D.M.: IP Port check

Re: Lua is not working anymore

Posted: Friday 24 November 2017 9:30
by jvdz
That isn't possible with the script I posted as that line is commented out on line 3!
Do you have multiple version of the script or double check the update worked.

Jos

Re: Lua is not working anymore

Posted: Friday 24 November 2017 19:53
by Derik
sorry did not see the update..
Now this is the update:

Code: Select all

2017-11-24 19:52:00.648 Error: EventSystem: in Port test: [string "commandArray = {} ..."]:12: ')' expected near 'otherdevices'
Just a error

Re: Lua is not working anymore

Posted: Friday 24 November 2017 20:33
by jvdz
Understand as I made a typo in the print() debug lines.
This script is tested and working for me on my test domoticz setup:

Code: Select all

commandArray = {}

print ("debug: D.M.: IP Port check")

function update_portalive(name, ip, port)

    -- Windows https://joncraton.org/blog/46/netcat-for-windows/ untested

    s = "nc -z -w 1  " .. ip .." " .. tostring(port)
    print("debug:"..s)
    if (os.execute(s) == nil) then
        print("debug:  nil returned.  status of "..name.."="..otherdevices[name])
        if (otherdevices[name] == 'On') then
            commandArray[name] = 'Off'
            print(name .. " Dead")
        end
    else
        print("debug: Not nil returned.  status of "..name.."="..otherdevices[name])
        if (otherdevices[name] == 'Off') then
            print(name .. " Is a Alive")
            commandArray[name] = 'On'
        end
    end
end


-- Fill in your services here  NAMEOFVIRTUALDEVICE    IP   PORT

update_portalive("Port: Schuurtje", "192.168.5.98", 552)
--update_portalive("Port: Solarmeter", "192.168.5.99", 555)
--update_portalive("Port: Dakrand", "192.168.5.97", 553)
--update_portalive("Port: Domoticz 1", "192.168.5.75", 8081)
--update_portalive("Port: Domoticz 3", "192.168.5.3", 8083)
--update_portalive("Port: Domoticz 2", "192.168.5.147", 8082)
--update_portalive("Port: Minecraft", "192.168.5.147", 22222)

return commandArray
Hope this will work for you too.

Jos