I'm running this code
Code: Select all
pingRet = os.execute('ping -c 1 myIpAddress')
dz.log('ping = ' .. pingRet)
Running 2020.1 (build 11946) on Debian NUC
Thank you
Moderator: leecollings
Code: Select all
pingRet = os.execute('ping -c 1 myIpAddress')
dz.log('ping = ' .. pingRet)
there are some issues with this approach:Number8 wrote: Saturday 18 April 2020 15:16 I'm running os.execute('ping -c 1 myIpAddress') . Is the ping command wrong?
Code: Select all
local function osExecute(cmd)
local fileHandle = assert(io.popen(cmd, 'r'))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
return returnTable[3], commandOutput -- returnTable[3] contains returnCode
end
local myIpAddress = '192.168.192.109'
local pingReturnCode , pingCommandOutput = osExecute('ping -w1 -c1 ' .. myIpAddress) -- w1 = wait time max 1 second
print('pingReturnCode: ' .. pingReturnCode)
print('pingCommandOutput: ' .. pingCommandOutput)
I thing I did it in in the following scriptyou could use this
Code: Select all
-- Test Internet status w www.google.fr and give status
-- from https://www.domoticz.com/forum/viewtopic.php?f=59&t=32250&p=244194&hilit=pingReturnCode+%2C+pingCommandOutput#p244194
local DEV_STATUS = 1118 -- alert device to log the status of the ping
local PING_ADDRESS = 'www.google.fr'
return {
logging = {
level =
domoticz.LOG_ERROR, --select one to override system log level normal = LOG_ERROR
--domoticz.LOG_DEBUG,
--domoticz.LOG_INFO,
--domoticz.LOG_ERROR,
--domoticz.LOG_FORCE
},
on = {
timer = {"every minute"},
},
data = {
ERROR_NUMBER = {initial={0}},
},
execute = function(dz, device)
_G.logMarker = _G.moduleLabel -- set logmarker to scriptname
local LOG_LEVEL = dz.LOG_INFO -- normal
--local LOG_LEVEL = dz.LOG_DEBUG
--local LOG_LEVEL = dz.LOG_ERROR
--local LOG_LEVEL = dz.LOG_FORCE
local function osExecute(cmd)
local fileHandle = assert(io.popen(cmd, 'r'))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
return returnTable[3], commandOutput -- returnTable[3] contains returnCode
end
local pingReturnCode , pingCommandOutput = osExecute('ping -w1 -c1 ' .. PING_ADDRESS) -- w1 = wait time max 1 second
local pingErrorLevel
local pingStatus
dz.log('pingReturnCode: ' .. pingReturnCode, LOG_LEVEL)
dz.log('pingCommandOutput: ' .. pingCommandOutput, LOG_LEVEL)
if pingReturnCode == 0 then
dz.data.ERROR_NUMBER=0
pingStatus='OK'
else
dz.data.ERROR_NUMBER=dz.data.ERROR_NUMBER+1
pingStatus='KO ' .. dz.data.ERROR_NUMBER .. " min."
end
dz.log('ERROR_NUMBER: ' .. dz.data.ERROR_NUMBER, LOG_LEVEL)
if dz.data.ERROR_NUMBER == 0 then
pingErrorLevel=dz.ALERTLEVEL_GREEN
elseif dz.data.ERROR_NUMBER == 1 then -- every min => 1 min
pingErrorLevel=dz.ALERTLEVEL_YELLOW
elseif dz.data.ERROR_NUMBER > 2 and dz.data.ERROR_NUMBER < 10 then -- every min, 10
pingErrorLevel=dz.ALERTLEVEL_ORANGE
else pingErrorLevel=dz.ALERTLEVEL_RED
end
dz.devices(DEV_STATUS).updateAlertSensor(pingErrorLevel, pingStatus)
end
}The -w1 should cause a return after max 1 second. So either something else is causing the system to be extremely busy or ping itself does behave different then expected. If your return code is 2 it might help to catch the return message.hestia wrote: Wednesday 04 November 2020 9:43 And... when my internet is down, I get this "dzVents.lua has been running for more than 10 seconds"
I thought that this template was to avoid blocking the eventSystem.
Did I miss something in my script?
My platform is quite standard: Pi 3 B+ / Linux 5.4.51-v7+ ; so the ping should be as anybody's one
The system doesn't seem busy at all, via Monit I've got this during a test I've just done again:So either something else is causing the system to be extremely busy
Sorry, but I don't know what to do with this, my script was with LOG_DEBUGIf your return code is 2 it might help to catch the return message.
Don't know what could cause this buthestia wrote: Wednesday 04 November 2020 17:53 Sorry, but I don't know what to do with this, my script was with LOG_DEBUG
Code: Select all
data = {
ERROR_NUMBER = {initial={0}}, -- {0} is a table
},
Code: Select all
data =
{
ERROR_NUMBER =
{
initial = 0,
},
},Code: Select all
sudo /bin/pingI did this one! and it is ok, no blockagewaaren wrote: Wednesday 04 November 2020 18:31 Another thing you can try is not using the command ping butCode: Select all
sudo /bin/ping
Good that it is working now!hestia wrote: Wednesday 04 November 2020 21:49 I didn't do anything on the ERROR_NUMBER table... because it is ok like this!
Code: Select all
dz.data.ERROR_NUMBER=dz.data.ERROR_NUMBER+1 Code: Select all
dz.data.ERROR_NUMBER=0Understood, I changed it!waaren wrote: Wednesday 04 November 2020 22:26 The initial setting of ERROR_NUMBER is wrong and it will give the error
Users browsing this forum: No registered users and 1 guest