Lua is not working anymore

Moderator: leecollings

Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Lua is not working anymore

Post 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 2404 times
Only not working anymore..
Perhaps someone see where a thing is going wrong?

Thanks for the help
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
SweetPants

Re: Lua is not working anymore

Post by SweetPants »

When posting code, please use the Code blocks. Nobody will type over your script
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Lua is not working anymore

Post by emme »

are you sure you have NC installed into your new hardware?
The most dangerous phrase in any language is:
"We always done this way"
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua is not working anymore

Post 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?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Lua is not working anymore

Post by emme »

try to run it in a shell window...
what kind of hardware are you running?
The most dangerous phrase in any language is:
"We always done this way"
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua is not working anymore

Post by Derik »

my hardware is Odriod Xu4 with dietpi
shell?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua is not working anymore

Post 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

Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua is not working anymore

Post by jvdz »

So what is shown in the domoticz log file? it should show at least the text: D.M.: IP Port check
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua is not working anymore

Post 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
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua is not working anymore

Post 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.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua is not working anymore

Post 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?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua is not working anymore

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua is not working anymore

Post 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...
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua is not working anymore

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua is not working anymore

Post 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...
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua is not working anymore

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua is not working anymore

Post by Derik »

This is all:

Code: Select all

2017-11-23 23:57:00.171 LUA: D.M.: IP Port check
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua is not working anymore

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua is not working anymore

Post 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
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua is not working anymore

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest