user variable not updated Topic is solved

Moderator: leecollings

Post Reply
Manudax
Posts: 3
Joined: Tuesday 21 April 2020 21:36
Target OS: Windows
Domoticz version:
Contact:

user variable not updated

Post by Manudax »

Hi there,
I spent a lot of time tryng to finalise a LUA script.
This script ping an ip address and depending of the result switch on/off a switch.
I use a user variable to validate the result after few tries arroud 5 is a good count to have a revelant test, sometime one or two pings are not sufficient.
The LUA script is activated each minute by Domoticz and make a test period of 5mn, (one ping each minute is a revelant test I think) .
The user variable Var_Ping_PC1 is not updated to zero when the count is achieved.

Code: Select all

commandArray['Variable:Var_Ping_PC1'] = '0'

Code: Select all

commandArray={}
debug=1
if(otherdevices['Ping_PC1']=='Off') then
ping_success=os.execute('ping -n 1 -w 1000 10.10.0.8')
    if ping_success then
    else
        commandArray['Variable:Var_Ping_PC1'] = tostring(uservariables["Var_Ping_PC1"] + 1)
        if uservariables["Var_Ping_PC1"] > 4 then
			commandArray['OpenURL']='https://smsapi.free-mobile.fr/sendmsg?user=MyName&pass=123456&msg=Pas%20de%20ping%20vers%20PC1'
            print(' Pas de ping vers PC1' ..uservariables["Var_Ping_PC1"])
            commandArray['Ping_PC1']='On'
            commandArray['Variable:Var_Ping_PC1'] = '0'
            print('Var_Ping_PC1 = ' ..uservariables["Var_Ping_PC1"])
        end
    
    end
end
return commandArray
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: user variable not updated

Post by waaren »

Manudax wrote: Tuesday 21 April 2020 22:15 This script ping an ip address and depending of the result switch on/off a switch.
The user variable Var_Ping_PC1 is not updated to zero when the count is achieved.
Some remarks:
  • os.execute does never return anything. ping_success will therefore always be nil
  • the option -w 1000 will potentially block the entire event system for 1000 seconds (domoticz event system is single threaded)
  • the line

    Code: Select all

    print('Var_Ping_PC1 = ' ..uservariables["Var_Ping_PC1"])
    will print what the uservar was when the script started. The update of the value of the uservar will take place when the script has finished and commandArray is processed by domoticz.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Manudax
Posts: 3
Joined: Tuesday 21 April 2020 21:36
Target OS: Windows
Domoticz version:
Contact:

Re: user variable not updated

Post by Manudax »

Hello,
thanks for your reply,
the -w is exprimed in millisecondes using the windows command line.

I need the uservariable changed during this script execution not after.

sincerely,
Manudax.
Manudax
Posts: 3
Joined: Tuesday 21 April 2020 21:36
Target OS: Windows
Domoticz version:
Contact:

Re: user variable not updated

Post by Manudax »

HI,
finally I used the internal Domticz ping function and it was ok for me.

I dont know how to close this topic.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest