Error opening url: http://192.168.1xx.xx/livedata.htm

Forum dédié aux problématiques concernant les scripts pour DomoticZ.
Entourez votre code et les logs avec les balises nommées code grâce au bouton <\>.
Doudy
Messages : 457
Inscription : 07 mai 2016, 17:23

Error opening url: http://192.168.1xx.xx/livedata.htm

Message par Doudy »

Bonjour,

J'ai ce message d'erreur toutes les 10' et je ne trouve pas d'ou ça vient. Déjà plusieurs heures de recherche et pas trouvé !

Code : Tout sélectionner

2024-03-12 08:07:51.396 Error: Error opening url: http://192.168.1xx.xx/livedata.htm
2024-03-12 08:07:52.041 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: HTTP/1.1 response: 56 ==>> Failure when receiving data from the peer
2024-03-12 08:07:52.059 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: Could not get (good) data from 192.168.1xx.xx
2024-03-12 08:17:52.050 Error: Error opening url: http://192.168.1xx.xx/livedata.htm
2024-03-12 08:17:52.497 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: HTTP/1.1 response: 56 ==>> Failure when receiving data from the peer
2024-03-12 08:17:52.528 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: Could not get (good) data from 192.168.1xx.xx
2024-03-12 08:27:52.696 Error: Error opening url: http://192.168.1xx.xx/livedata.htm
2024-03-12 08:27:53.317 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: HTTP/1.1 response: 56 ==>> Failure when receiving data from the peer
2024-03-12 08:27:53.337 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: Could not get (good) data from 192.168.1xx.xx
2024-03-12 08:37:53.257 Error: Error opening url: http://192.168.1xx.xx/livedata.htm
2024-03-12 08:37:53.840 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: HTTP/1.1 response: 56 ==>> Failure when receiving data from the peer
2024-03-12 08:37:53.859 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: Could not get (good) data from 192.168.1xx.xx
2024-03-12 08:39:01.105 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: An error occurred when calling event handler observer-5
2024-03-12 08:40:01.548 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: An error occurred when calling event handler observer-5
2024-03-12 08:41:01.180 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: An error occurred when calling event handler observer-5
2024-03-12 08:47:53.783 Error: Error opening url: http://192.168.1xx.xx/livedata.htm
2024-03-12 08:47:54.382 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: HTTP/1.1 response: 56 ==>> Failure when receiving data from the peer
2024-03-12 08:47:54.402 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: Could not get (good) data from 192.168.1xx.xx
2024-03-12 08:52:01.225 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: An error occurred when calling event handler observer-5
2024-03-12 08:57:54.334 Error: Error opening url: http://192.168.1xx.xx/livedata.htm
2024-03-12 08:57:54.933 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: HTTP/1.1 response: 56 ==>> Failure when receiving data from the peer
2024-03-12 08:57:54.952 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: Could not get (good) data from 192.168.1xx.xx
2024-03-12 09:07:54.925 Error: Error opening url: http://192.168.1xx.xx/livedata.htm
2024-03-12 09:07:55.531 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: HTTP/1.1 response: 56 ==>> Failure when receiving data from the peer
2024-03-12 09:07:55.551 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: Could not get (good) data from 192.168.1xx.xx
2024-03-12 09:17:55.501 Error: Error opening url: http://192.168.1xx.xx/livedata.htm
2024-03-12 09:17:56.094 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: HTTP/1.1 response: 56 ==>> Failure when receiving data from the peer
2024-03-12 09:17:56.112 Error: dzVents: Error: (3.1.8) ObserverIP_5 - 0.201911091100: Could not get (good) data from 192.168.1xx.xx
J'ai les fonctions suivantes dans mon script :

Code : Tout sélectionner

        -- this function will call the webpage
        local function getWeatherStationData()
           local url = 'http://' .. weatherStationIP .. '/livedata.htm'
           dz.openURL  ({ url = url, callback = scriptVar })
        end

Code : Tout sélectionner

        local function checkWebpageResponse()
            local deltaSeconds = dz.time.dDate - dz.data.previousRainSample
            if ( maxResponseSeconds > 0 )  and ( deltaSeconds > maxResponseSeconds ) then
                --dz.notify(scriptVar, 'weatherStation did not respond within ' .. tostring(maxResponseSeconds) .. ' seconds.')
            end
        end

Code : Tout sélectionner

       -- main 
        if item.isTimer or item.isDevice then
            checkWebpageResponse()
            getWeatherStationData()
        elseif item.ok then -- statusCode == 2xx
            updateDevices(processHTM(item.data))
        else
            dz.log('Could not get (good) data from ' .. weatherStationIP,dz.LOG_ERROR)
            dz.log(item.data,dz.LOG_DEBUG)
      end
Une idée ?
RaspberryPi - RFLink - Zwave - WH2600
Domoticz : 2020.2 | Dashticz : V3.12 Master | dzvents : 3.0.2 | Python : 3.7.3
Keros
Messages : 6638
Inscription : 23 juil. 2019, 20:57

Re: Error opening url: http://192.168.1xx.xx/livedata.htm

Message par Keros »

L'URL calculée dans le script est bien correcte ? Elle fonctionne dans un navigateur ?

J'ai déjà eu des difficultés avec la commande openurl. Quelques fois, je dois faire :

Code : Tout sélectionner

domoticz.executeShellCommand({
command = 'curl -H "Cache-Control: no-cache, no-store" "https://xxxxxxxxxxxxxxxxxxxx.yyy
callback = trigger,
timeout = 9,
})
Et pour le traitement :

Code : Tout sélectionner

local jsonValeur = domoticz.utils.fromJSON(item.data)
Comment bien utiliser le forum : Poser une question, Mettre un script, un fichier, une image ou des logs
Mes petits guides : Débuter en programmation, Le débogage, Le choix de matériel, Les sauvegardes
Ma présentation - Mes Tutos
Doudy
Messages : 457
Inscription : 07 mai 2016, 17:23

Re: Error opening url: http://192.168.1xx.xx/livedata.htm

Message par Doudy »

Keros a écrit : 12 mars 2024, 19:11 L'URL calculée dans le script est bien correcte ? Elle fonctionne dans un navigateur ?
Oui l'URL est bien correcte. Elle fonctionne dans le navigateur.
Je teste la suite.
;)
RaspberryPi - RFLink - Zwave - WH2600
Domoticz : 2020.2 | Dashticz : V3.12 Master | dzvents : 3.0.2 | Python : 3.7.3
Doudy
Messages : 457
Inscription : 07 mai 2016, 17:23

Re: Error opening url: http://192.168.1xx.xx/livedata.htm

Message par Doudy »

Hello,

Voilà, j'ai testé. Avec ceci :

Code : Tout sélectionner

        local function getWeatherStationData()
			dz.executeShellCommand({
			command = 'http://192.168.129.99/livedata.htm',
			callback = scriptVar,
			timeout = 9,
			})
		end
Pas de message d'erreur. J'ai supprimé ceci : "curl -H "Cache-Control: no-cache, no-store"" car avec ça ne donnait rien !
Par contre, dans mon "main" la commande suivante "updateDevices(processHTM(item.data))" n'est pas exécutée :

Code : Tout sélectionner

      -- main 
        if item.isTimer or item.isDevice then
            checkWebpageResponse()
            getWeatherStationData()
        elseif item.ok then -- statusCode == 2xx
            updateDevices(processHTM(item.data))
        else
            dz.log('Could not get (good) data from ' .. weatherStationIP,dz.LOG_ERROR)
            dz.log(item.data,dz.LOG_DEBUG)
        end
c'est le elseif item.ok qui bloque mais pourquoi ?

La partie getWeatherStationData() est bien executée :

Code : Tout sélectionner

2024-03-14 09:46:00.310 Status: dzVents: Info: ObserverIP_5 - 0.201911091100: ------ Start external script: observer-5.lua:, trigger: "every 2 minutes"
2024-03-14 09:46:00.311 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-Batterie-In: Text device
2024-03-14 09:46:00.313 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-Batterie-Out: Text device
2024-03-14 09:46:00.314 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-WindDir: Wind device adapter
2024-03-14 09:46:00.316 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-inTemp: Temperature device adapter
2024-03-14 09:46:00.317 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-inTempHum: Temperature+humidity device adapter
2024-03-14 09:46:00.318 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-outTemp: Temperature device adapter
2024-03-14 09:46:00.319 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-outTempHum: Temperature+humidity device adapter
2024-03-14 09:46:00.320 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-SolarRad: Solar radiation device adapter
2024-03-14 09:46:00.321 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-Uvi: UV device adapter
2024-03-14 09:46:00.323 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-Rain: Rain device
2024-03-14 09:46:00.324 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-RelPress: Barometer device adapter
2024-03-14 09:46:00.325 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-RainDaily: Custom sensor device adapter
2024-03-14 09:46:00.326 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-RainWeekly: Custom sensor device adapter
2024-03-14 09:46:00.327 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-RainMonthly: Custom sensor device adapter
2024-03-14 09:46:00.329 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-RainYearly: Custom sensor device adapter
2024-03-14 09:46:00.330 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-GustSpeed: Custom sensor device adapter
2024-03-14 09:46:00.331 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-WindSpeed: Custom sensor device adapter
2024-03-14 09:46:00.332 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-outHum: Humidty device adapter
2024-03-14 09:46:00.334 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: Processing device-adapter for LD-inHum: Humidty device adapter
2024-03-14 09:46:00.334 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: ExecuteShellCommand: command = http://192.168.129.99/livedata.htm
2024-03-14 09:46:00.334 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: ExecuteShellCommand: callback = ObserverIP_5 - 0.201911091100
2024-03-14 09:46:00.334 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: ExecuteShellCommand: timeout = 9
2024-03-14 09:46:00.334 Status: dzVents: Debug: ObserverIP_5 - 0.201911091100: ExecuteShellcommand: path = /home/pi/domoticz/scripts/dzVents/data/
2024-03-14 09:46:00.335 Status: dzVents: Info: ObserverIP_5 - 0.201911091100: ------ Finished observer-5.lua
RaspberryPi - RFLink - Zwave - WH2600
Domoticz : 2020.2 | Dashticz : V3.12 Master | dzvents : 3.0.2 | Python : 3.7.3
Keros
Messages : 6638
Inscription : 23 juil. 2019, 20:57

Re: Error opening url: http://192.168.1xx.xx/livedata.htm

Message par Keros »

On n'a pas tout ton code pour voir les triggers que tu as au départ.

Regarde ce que donne ton script si on le traduit :
Si le déclencheur est un timer ou si le déclencheur est un objet, alors

XXXXX

si non si le déclencheur est ok

XXXXX

Les conditions si le déclencheur est un timer ou si le déclencheur est un objet sont toujours vrai donc le si non ne sera jamais "regardé".

Ou alors je n'ai pas compris comment tu utilises le item.ok et sans le script complet, je ne pourrai faire que des suppositions.
Comment bien utiliser le forum : Poser une question, Mettre un script, un fichier, une image ou des logs
Mes petits guides : Débuter en programmation, Le débogage, Le choix de matériel, Les sauvegardes
Ma présentation - Mes Tutos
Doudy
Messages : 457
Inscription : 07 mai 2016, 17:23

Re: Error opening url: http://192.168.1xx.xx/livedata.htm

Message par Doudy »

Hello,

Les conditions si oui/si non j'ai bien compris. Mais c'est plutôt

Code : Tout sélectionner

item.ok then 
que je n'arrive pas à comprendre ! :oops:
C'est "item.ok" : item ?? - ok ???? que je ne comprends pas. C'est quoi cet item ?

Je mets ci-dessous le code complet :

Code : Tout sélectionner

local scriptVersion = '0.201911091100'
local scriptVar  =  'ObserverIP_5 - ' .. scriptVersion

--[[ 
this dzVents script is used to collect data from ObserverIP weatherstation with software version 4.5.7. (weatherlogger 2.2.2.)
Because there is no known API / JSON interface at the time this script was created, it uses a call to the Web Gui and interprets the returned HTML code. 
This code is likely to change when a new version is released. If you encounter an incompatibility between this version of the script and a new version of the ObserverIP  software then please report this on the domoticz forum.

Also post there if you have a requirement to expose more of the available information to domoticz (either in a device or a uservariable) 

Before activating the script:
    please read the GETTING STARTED section of the dzVents wiki. 
    change xxx.xxx.xxx.xxx in this script to the IP of your weatherStation 
    define a dummy hardware in domoticz if not already done 
    define virtual sensors in domoticz for this dummy hardware

        type           Will show 
        wind           windspeed, windgust, winddirection (numeric and string), temperature, windchill temperature
        temperature    indoor temperature
        temp/humidity  indoor temperature, indoor humidity, indoor humidity status
        temperature    outdoor temperature
        temp/humidity  outdoor temperature, outdoor humidity, outdoor humidity status
        solarRadiation solar Radiation
        UV index       UV index
        rain           Rainrate in mm/h and amount of rain.
        barometer      air pressure in HPA
        dailyRain      Daily amount of rain in mm ( define as general Custom sensor with x-as mm )
        weeklyRain     Weekly amount of rain in mm ( define as general Custom sensor with x-as mm )  
        monthlyRain    Monthly amount of rain in mm ( define as general Custom sensor with x-as mm )
        yearlyRain     Yearly amount of rain in mm ( define as general Custom sensor with x-as mm )  
        gustSpeed      Gust speed ( define as general Custom sensor with x-as m/sec )
        avgWind        Wind speed ( define as general Custom sensor with x-as m/sec )

and change the names in the device declarations between the marked lines below.
these devices will overtime keep an history of the collected data that can be viewed by pressing the log button on the device.
https://www.domoticz.com/forum/viewtopic.php?f=59&t=29187&sid=c20b8f82db6a08fe4e31041582b54ba5

History
========
20190828 Start coding
20180829 Start testing (thanks @eddieb !) based on prototype
20190901 Added comments and history 
20190904 Added option to get a notification when time since last device update is too long
20191016 Fixed wrong link between names and values
20191017 Added updates of custom sensors for daily-, weekly-, monthly- and yearly rain
20191017 Fixed typos (wrong case in table) 
20191018 Added option to add separate custom sensors for gustSpeed and average Wind 
20191030 Added option for script to be started by a device.
20191109 Replaced math.pow(x,y) with x^y (Lua 5.3 deprecated math.pow) 
 
]]--

return
{
    active = true,
	on =  
    { 
        devices = {'WH2600-2-Wind', 'WH2600-2-Solar Radiation', 'WH2600-2-Outdoor', 'WH2600-2-UV', 'WH2600-2-Rain' }, -- Script can be triggered by a device  
        timer = { 'every 2 minutes' }, -- or by a timer-rule
        -- timer = { 'every 1 minutes' }, -- 
        httpResponses = { scriptVar },  -- do not change this
    },

    logging =   
    {
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when everything works as expected
        marker = scriptVar,
    },

    data = 
    { 
        rainTotal = { initial = 0 },
        previousRainSample = { initial = 0 },
    },

    execute = function(dz, item)
        -- ********** local settings below this line *************
        -- change to IP of your weatherstation
        local weatherStationIP = '192.168.xxx.xx' 
        
        -- change to number of seconds after you want to receive a notification that the response of the website is unexpected long
        -- set to -1 if you never want to be notified
        local maxResponseSeconds = 720 

        -- Change devicenames below to reflect your names and uncomment the lines with the devices you defined.
        -- You can also use idx but if you do, then don't use the surrounding quotes.
        local internalBatteryStatus = dz.devices('LD-Batterie-In')
		dz.devices('LD-Batterie-In').updateText(dz.devices('LD-Batterie-In'))
        local outdoorBatteryStatus1 = dz.devices('LD-Batterie-Out')
		dz.devices('LD-Batterie-Out').updateText(dz.devices('LD-Batterie-Out'))
        local wind = dz.devices('LD-WindDir')
        local insideTemperature = dz.devices('LD-inTemp')
        local insideTemperatureHumidity = dz.devices('LD-inTempHum')
        local outsideTemperature = dz.devices('LD-outTemp')
        local outsideTemperatureHumidity = dz.devices('LD-outTempHum')
	local solarRadiation = dz.devices('LD-SolarRad')
	local uvIndex = dz.devices('LD-Uvi')
        local rain = dz.devices('LD-Rain')
        local barometer = dz.devices('LD-RelPress')
        local dailyRain = dz.devices('LD-RainDaily')       
        local weeklyRain = dz.devices('LD-RainWeekly')     
        local monthlyRain = dz.devices('LD-RainMonthly')   
        local yearlyRain = dz.devices('LD-RainYearly')   
        local gustSpeed = dz.devices('LD-GustSpeed')
        local avgWind = dz.devices('LD-WindSpeed')
	local outHum = dz.devices('LD-outHum')
	local inHum = dz.devices('LD-inHum')

        -- ********** No changes necessary below this line *************

        -- this function will calculate  the last time the script updated devices
        -- to check if the webpage response was within limits
        local function checkWebpageResponse()
        local deltaSeconds = dz.time.dDate - dz.data.previousRainSample
            if ( maxResponseSeconds > 0 )  and ( deltaSeconds > maxResponseSeconds ) then
                --dz.notify(scriptVar, 'weatherStation did not respond within ' .. tostring(maxResponseSeconds) .. ' seconds.')
            end
        end
        
        -- this function will call the webpage
        local function getWeatherStationData()
           local url = 'http://' .. weatherStationIP .. '/livedata.htm'
	   dz.openURL ({ url = url, method = 'GET', callback = scriptVar })
        end

--[[
        local function getWeatherStationData()
			dz.executeShellCommand({
			command =  'http://' .. weatherStationIP .. '/livedata.htm',
			callback = scriptVar,
			timeout = 9,
			})
		end
]]--		
        -- this function will process the HTML and from the relevant data it will create a table to hold the values to update the devices
        local function processHTM()
			local fieldNames = {    -- the commented fields are available in the html but not used in this script.
                                        -- CurrTime='Current time',
                                        inBattSta='internalBatteryStatus',
                                        outBattSta1='outdoorBatteryStatus1',
                                        inTemp='indoorTemperature',
                                        inHumi='indoorHumidity',
                                         AbsPress='absolutePressure',
                                        RelPress='relativePressure',
                                        outTemp='outdoorTemperature',
                                        outHumi='outdoorHumidity',
                                        windir='windDirection',
                                        avgwind='windSpeed',
                                        gustspeed='windGust',
                                        dailygust='maxDailyGust',
                                        solarrad='solarRadiation',
                                        uvi='UVI', 
                                        rainofhourly='hourlyRainRate',
                                        eventrain='eventRain',
                                        rainofdaily='dailyRain', 
                                        rainofweekly='weeklyRain',
                                        rainofmonthly='monthlyRain', 
                                        rainofyearly='yearlyRain',
                                    }

            
            -- Prepare WSData (remove quotes, nullify option value, and make fieldName )
            WSData = (item.data):gsub('"',''):gsub("'",""):gsub("option value"," xx"):gsub("input name"," fieldName") 
            
            -- fill table with keys
            local lines = {}
            local linesIndex = 1
            for keyField in string.gmatch( WSData,"[^%s, ]+" ) do -- loop over all 'words' in thedata
                if string.find(keyField,'fieldName=') then -- if 'word' is like fieldName=text
                    lines[linesIndex] = {}
                    lines[linesIndex].name =  keyField:gsub('fieldName=','') -- put text into name field 
                    linesIndex = linesIndex + 1
                end
            end

            -- fill table with values
            linesIndex = 1
            for keyField in string.gmatch( WSData,"[^%s, ]+" ) do 
                if string.find(keyField,'value=') then -- if 'word' is like value=text / number
                    if lines[linesIndex] == nil then lines[linesIndex] = {} end
                    lines[linesIndex].value =  keyField:gsub('value=','') -- put text / number into corresponding value field 
                    linesIndex = linesIndex + 1
                end
            end
            
            -- fill table usedFields only with names and values we are going to use to fill devices
            local usedFields = {}            
            for linesIndex = 1, #lines do 
                if fieldNames[lines[linesIndex].name] ~= nil then
                    usedFields[fieldNames[lines[linesIndex].name]] = lines[linesIndex].value  
                end
            end
			return usedFields
        end

        local function updateDevices(fields) -- update all ( declared ) devices. Specialized function to create required fields are local to this function
  
            local function windDirectionName(degrees) -- do not translate as domoticz web GUI depends on strings like E or S 
                if degrees ~= nil then degrees = tonumber(degrees) % 360 -- Ensure between 0 and 360
					local windDirections =
                    {
                            N={0,22.5}, -- 337,5- 360 will be catched later 
                            NE={22.5,67.5},
                            E={67.5,112.5},
                            SE={112.5,157.5},
                            S={157.5,202.5},
                            SO={202.5,247.5},
                            O={247.5,292.5},
                            NO={292.5,337.5},
                    }
               	--dz.log('>>>>>>> windDirections: ' .. tostring(windDirections),dz.LOG_FORCE)
				--dz.devices('test').updateText(tostring(fields.WindDirections))
				--test.updateText(fields.WindDirections, 'HUM_NORMAL') 
				local minDegrees = 1
                local maxDegrees = 2
                for key, value in pairs(windDirections) do
                    if degrees >= value[minDegrees] and degrees < value[maxDegrees] then return key end
                end
                return 'N'
				end
            end

            local function windChill(windSpeed, temperature) -- official KNMI function to compute windchill
                windSpeed = tonumber(windSpeed)
                temperature = tonumber(temperature)
                if windSpeed < 1.3 or windSpeed > 49 or temperature < -46 or temperature > 17 then return temperature end
                return dz.utils.round(13.12 + (0.6215 * temperature) - (13.96 * windSpeed^0.16) + (0.4867 * temperature * windSpeed^0.16), 1)
            end
--[[
            local function humidityStatus(temperature, humidity) -- as used in domoticz source
                humidity = tonumber(humidity)
                temperature = tonumber(temperature)
                if humidity <= 30 then return dz.HUM_DRY
                elseif humidity >= 70 then return dz.HUM_WET
                elseif  humidity >= 35 and humidity <= 65 and temperature >= 22 and temperature <= 26 then return dz.HUM_COMFORTABLE end
                return dz.HUM_NORMAL
            end
]]--

			local function humStatus(temperature, humidity) -- as used in domoticz source
				dz.log('>>>>>>> temperature: ' .. tostring(temperature),dz.LOG_FORCE)
				dz.log('>>>>>>> humidity: ' .. tostring(humidity),dz.LOG_FORCE)
				humidity = tonumber(humidity)
				temperature = tonumber(temperature)
				if humidity <= 30 then return dz.HUM_DRY
				elseif humidity >= 70 then return dz.HUM_WET
				elseif  humidity >= 35 and humidity <= 65 and temperature >= 22 and temperature <= 26 then return dz.HUM_COMFORTABLE
				else return dz.HUM_NORMAL 
				end
			end
			
            local function BarometerForecast(pressure) -- simplified forecast model
                if pressure == nil then return nil end -- Should not happen
                pressure = tonumber(pressure)
                if pressure < 966   then return dz.BARO_THUNDERSTORM
                elseif pressure < 993   then return dz.BARO_CLOUDY
                elseif pressure < 1007  then return dz.BARO_PARTLYCLOUDY
                elseif pressure < 1013  then return dz.BARO_UNSTABLE
                elseif pressure < 1033  then return dz.BARO_STABLE
                end
                return dz.BARO_SUNNY
            end    

            local function updateRain(rainRate) -- use time since last sample to calculate new total. Daily total is derived from total by domoticz 
                rainRate = tonumber(rainRate)
                if dz.data.previousRainSample == 0 then 
                    dz.log('Initial setting of the raindata. No update of the device yet',dz.LOG_FORCE)
                    dz.data.previousRainSample = dz.time.dDate
                    return
                end
                if rainRate > 1000 then 
                    dz.log('Obvious wrong value. This would be more then 1 meter of rain per hour',dz.LOG_ERROR)
                    return 
                end 
                local deltaSeconds = dz.time.dDate - dz.data.previousRainSample
                local rainIncrease = rainRate * ( deltaSeconds / 3600 )
                local previousRainTotal = math.max(dz.data.rainTotal,  rain.rain or 0) -- protect against reset or new device 
                dz.data.rainTotal = previousRainTotal + rainIncrease 
                rain.updateRain(rainRate * 100 , dz.utils.round(dz.data.rainTotal,1)) -- one decimal should be accurate enough
                rain.updateRain(rainRate * 100 , dz.utils.round(dz.data.rainTotal,1)) -- one decimal should be accurate enough
                dz.data.previousRainSample = dz.time.dDate
            end   

            -- update weatherDevices/ See dzVents wiki (https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting) for required parms of the update functions 
            if wind ~= nil then wind.updateWind
            (
                fields.windDirection, 
                windDirectionName(fields.windDirection), 
                fields.windSpeed, 
                fields.windGust, 
                fields.outdoorTemperature, 
                windChill(fields.windSpeed, fields.outdoorTemperature)
			--	dz.log('windChill ' .. windChill,dz.LOG_ERROR)
            ) end

            if insideTemperature ~= nil then insideTemperature.updateTemperature(fields.indoorTemperature) end

            if insideTemperatureHumidity then insideTemperatureHumidity.updateTempHum
            (
                fields.indoorTemperature, 
                fields.indoorHumidity, 
                humStatus(fields.indoorTemperature,fields.indoorHumidity)
            ) 
				inHum.updateHumidity(fields.indoorHumidity, 'HUM_NORMAL') 
				dz.log('humidity-in HHHHH: ' .. tostring(fields.indoorHumidity),dz.LOG_FORCE)
tostring(humidityStatus(fields.indoorTemperature,fields.indoorHumidity)),dz.LOG_FORCE)
			end

            if outsideTemperature ~= nil then outsideTemperature.updateTemperature(fields.outdoorTemperature) end

            if outsideTemperatureHumidity ~= nil then outsideTemperatureHumidity.updateTempHum
            (
                fields.outdoorTemperature, 
                fields.outdoorHumidity, 
                humStatus(fields.outdoorTemperature,fields.outdoorHumidity)
            ) 
				outHum.updateHumidity(fields.outdoorHumidity, 'HUM_NORMAL') 
				dz.log('humidity-out HHHHH: ' .. tostring(fields.outdoorHumidity),dz.LOG_FORCE)
ostring(humidityStatus(fields.indoorTemperature,fields.indoorHumidity)),dz.LOG_FORCE)
			end

            if solarRadiation ~= nil then solarRadiation.updateRadiation(fields.solarRadiation) end

            if uvIndex ~= nil then uvIndex.updateUV(fields.UVI) end

            if rain ~= nil then updateRain(fields.hourlyRainRate) end

            if barometer ~= nil then barometer.updateBarometer
            (
                fields.relativePressure,
                BarometerForecast(fields.relativePressure)
            ) end
            
            if _G.logLevel == dz.LOG_DEBUG then dz.utils.dumpTable(fields) end
            
            if dailyRain ~= nil then dailyRain.updateCustomSensor(fields.dailyRain) end
            if weeklyRain ~= nil then weeklyRain.updateCustomSensor(fields.weeklyRain) end
            if monthlyRain ~= nil then monthlyRain.updateCustomSensor(fields.monthlyRain) end
            if yearlyRain ~= nil then yearlyRain.updateCustomSensor(fields.yearlyRain) end
            
            if gustSpeed ~= nil then gustSpeed.updateCustomSensor(fields.windGust) end
            if avgWind ~= nil then avgWind.updateCustomSensor(fields.windSpeed) end
            
        end

       -- main 
        if item.isTimer or item.isDevice then
            checkWebpageResponse()
            getWeatherStationData()
        elseif item.ok then -- statusCode == 2xx
            updateDevices(processHTM(item.data))
        else
            dz.log('Could not get (good) data from ' .. weatherStationIP,dz.LOG_ERROR)
            dz.log(item.data,dz.LOG_DEBUG)
        end

    end
}
Voir section MAIN !

;)
RaspberryPi - RFLink - Zwave - WH2600
Domoticz : 2020.2 | Dashticz : V3.12 Master | dzvents : 3.0.2 | Python : 3.7.3
Keros
Messages : 6638
Inscription : 23 juil. 2019, 20:57

Re: Error opening url: http://192.168.1xx.xx/livedata.htm

Message par Keros »

L'item est défini par :

Code : Tout sélectionner

execute = function(dz, item)
C'est la variable qui contient le déclencheur du script.

Le item.ok sert normalement à vérifier que le déclenchement via le httpResponses est correct.
L’utilisation de item.ok seul me parait bizarre. A minima j'aurai mis :

Code : Tout sélectionner

if (item.isHTTPResponse and item.ok) then
Au moins tu sais en lisant le code que cette condition est validée lors de la réponse à un appel HTTP.
Comment bien utiliser le forum : Poser une question, Mettre un script, un fichier, une image ou des logs
Mes petits guides : Débuter en programmation, Le débogage, Le choix de matériel, Les sauvegardes
Ma présentation - Mes Tutos
Doudy
Messages : 457
Inscription : 07 mai 2016, 17:23

Re: Error opening url: http://192.168.1xx.xx/livedata.htm

Message par Doudy »

Hello,

J'ai résolu ce problème de "Error: Error opening url: http://192.168.1xx.xx/livedata.htm"
En utilisant "dz.executeShellCommand" comme proposé par Keros. Merci à lui.
Le script modifié :

Code : Tout sélectionner

local scriptVersion = '0.2024031701'
--local scriptVar  =  'Observer-IP-99' .. scriptVersion
local scriptVar  =  'Observer-IP-99'


--[[ 

this dzVents script is used to collect data from ObserverIP weatherstation with software version 4.5.7. (weatherlogger 2.2.2.)
Because there is no known API / JSON interface at the time this script was created, it uses a call to the Web Gui and interprets the returned HTML code. 
This code is likely to change when a new version is released. If you encounter an incompatibility between this version of the script and a new version of the ObserverIP  software then please report this on the domoticz forum.

Also post there if you have a requirement to expose more of the available information to domoticz (either in a device or a uservariable) 

Before activating the script:
    please read the GETTING STARTED section of the dzVents wiki. 
    change xxx.xxx.xxx.xxx in this script to the IP of your weatherStation 
    define a dummy hardware in domoticz if not already done 
    define virtual sensors in domoticz for this dummy hardware

        type           Will show 
        wind           windspeed, windgust, winddirection (numeric and string), temperature, windchill temperature
        temperature    indoor temperature
        temp/humidity  indoor temperature, indoor humidity, indoor humidity status
        temperature    outdoor temperature
        temp/humidity  outdoor temperature, outdoor humidity, outdoor humidity status
        solarRadiation solar Radiation
        UV index       UV index
        rain           Rainrate in mm/h and amount of rain.
        barometer      air pressure in HPA
        dailyRain      Daily amount of rain in mm ( define as general Custom sensor with x-as mm )
        weeklyRain     Weekly amount of rain in mm ( define as general Custom sensor with x-as mm )  
        monthlyRain    Monthly amount of rain in mm ( define as general Custom sensor with x-as mm )
        yearlyRain     Yearly amount of rain in mm ( define as general Custom sensor with x-as mm )  
        gustSpeed      Gust speed ( define as general Custom sensor with x-as m/sec )
        avgWind        Wind speed ( define as general Custom sensor with x-as m/sec )

and change the names in the device declarations between the marked lines below.
these devices will overtime keep an history of the collected data that can be viewed by pressing the log button on the device.
https://www.domoticz.com/forum/viewtopic.php?f=59&t=29187&sid=c20b8f82db6a08fe4e31041582b54ba5

History
========
20190828 Start coding
20180829 Start testing (thanks @eddieb !) based on prototype
20190901 Added comments and history 
20190904 Added option to get a notification when time since last device update is too long
20191016 Fixed wrong link between names and values
20191017 Added updates of custom sensors for daily-, weekly-, monthly- and yearly rain
20191017 Fixed typos (wrong case in table) 
20191018 Added option to add separate custom sensors for gustSpeed and average Wind 
20191030 Added option for script to be started by a device.
20191109 Replaced math.pow(x,y) with x^y (Lua 5.3 deprecated math.pow) 
20240308 Adaptation du script vers shellCommandResponses ald httpResponses suite nombreux problèmes de connection ->
20240308 dzVents: Error: (3.1.8) ObserverIP_4-0.201911091100: HTTP/1.1 response: 56 ==>> Failure when receiving data from the peer
20240308 ou
20240308 Error: Error opening url: http://192.168.129.99/livedata.htm
20240317 Fonctionne correctement
20240317 Voir https://easydomoticz.com/forum/viewtopic.php?t=13964.  Merci à Keros
]]--

return
{
    active = true,
	on =  
    { 
        devices = {'WH2600-2-Wind', 'WH2600-2-Solar Radiation', 'WH2600-2-Outdoor', 'WH2600-2-UV', 'WH2600-2-Rain' },
        timer = { 'every 5 minutes' }, -- or by a timer-rule
        -- httpResponses = { scriptVar },  -- do not change this
	shellCommandResponses = { scriptVar }
    },

    logging =   
    {
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when everything works as expected
        --level = domoticz.LOG_ERROR, -- change to LOG_ERROR when everything works as expected
        marker = scriptVar,
    },

    data = 
    { 
        rainTotal = { initial = 0 },
        previousRainSample = { initial = 0 },
    },

    execute = function(dz, item)
        -- ********** local settings below this line *************
        -- change to IP of your weatherstation
        local weatherStationIP = '192.168.xxx.xx' 
        
        -- change to number of seconds after you want to receive a notification that the response of the website is unexpected long
        -- set to -1 if you never want to be notified
        local maxResponseSeconds = 720 

        -- Change devicenames below to reflect your names and uncomment the lines with the devices you defined.
        -- You can also use idx but if you do, then don't use the surrounding quotes.
        local internalBatteryStatus = dz.devices('LD-Batterie-In')
		dz.devices('LD-Batterie-In').updateText(dz.devices('LD-Batterie-In'))
        local outdoorBatteryStatus1 = dz.devices('LD-Batterie-Out')
		dz.devices('LD-Batterie-Out').updateText(dz.devices('LD-Batterie-Out'))
        local wind = dz.devices('LD-WindDir')
        local insideTemperature = dz.devices('LD-inTemp')
        local insideTemperatureHumidity = dz.devices('LD-inTempHum')
        local outsideTemperature = dz.devices('LD-outTemp')
        local outsideTemperatureHumidity = dz.devices('LD-outTempHum')
	local solarRadiation = dz.devices('LD-SolarRad')
        --local uv = dz.devices('LD-UV')
	local uvIndex = dz.devices('LD-Uvi')
        local rain = dz.devices('LD-Rain')
        local barometer = dz.devices('LD-RelPress')
        local dailyRain = dz.devices('LD-RainDaily')       
        local weeklyRain = dz.devices('LD-RainWeekly')     
        local monthlyRain = dz.devices('LD-RainMonthly')   
        local yearlyRain = dz.devices('LD-RainYearly')   
        local gustSpeed = dz.devices('LD-GustSpeed')
        local avgWind = dz.devices('LD-WindSpeed')
	--local windDirection = windDirectionName(degrees)
	local outHum = dz.devices('LD-outHum')
	local inHum = dz.devices('LD-inHum')
	--local windDirections = dz.devices('test')

        -- ********** No changes necessary below this line *************

        -- this function will calculate  the last time the script updated devices
        -- to check if the webpage response was within limits
        local function checkWebpageResponse()
            local deltaSeconds = dz.time.dDate - dz.data.previousRainSample
            if ( maxResponseSeconds > 0 )  and ( deltaSeconds > maxResponseSeconds ) then
                --dz.notify(scriptVar, 'weatherStation did not respond within ' .. tostring(maxResponseSeconds) .. ' seconds.')
            end
        end

 --[[       
        -- this function will call the webpage
        local function getWeatherStationData()
           local url = 'http://' .. weatherStationIP .. '/livedata.htm'
           dz.openURL  ({ url = url, callback = scriptVar })
        end

]]--

        local function getWeatherStationData()
			dz.executeShellCommand({
				command = 'curl "http://' .. weatherStationIP .. '/livedata.htm"',
				callback = scriptVar,
				--connect-timeout 5,
				--max-time 10,
			})
		end

		
--[[ Testing: Test header so you see this works
https://github.com/domoticz/domoticz/issues/3191
pi@raspberrypi-185:~ $ curl -I -H "Testing: Test header so you see this works" http://192.168.129.99/livedata.htm
HTTP/1.0 200 OK
Cache-control: no-cache
Connection: Keep-Alive
Content-type: text/html
]]--
		
        -- this function will process the HTML and from the relevant data it will create a table to hold the values to update the devices
        local function processHTM()
			local fieldNames = {    -- the commented fields are available in the html but not used in this script.
                                        -- CurrTime='Current time',
                                        inBattSta='internalBatteryStatus',
                                        outBattSta1='outdoorBatteryStatus1',
                                        -- outBattSta2='outdoorBatteryStatus2',
                                        inTemp='indoorTemperature',
                                        inHumi='indoorHumidity',
                                         AbsPress='absolutePressure',
                                        RelPress='relativePressure',
                                        outTemp='outdoorTemperature',
                                        outHumi='outdoorHumidity',
					--humStatus='outsideTemperatureHumidity',
                                        windir='windDirection',
                                        avgwind='windSpeed',
                                        gustspeed='windGust',
                                        dailygust='maxDailyGust',
                                        solarrad='solarRadiation',
                                        --uv='UV',
                                        uvi='UVI', 
                                        --pm25out='PM2.5-out', 
                                        --pm25in='PM2.5-in', 
                                        rainofhourly='hourlyRainRate',
                                        eventrain='eventRain',
                                        rainofdaily='dailyRain', 
                                        rainofweekly='weeklyRain',
                                        rainofmonthly='monthlyRain', 
                                        rainofyearly='yearlyRain',
                                    }

            -- Prepare WSData (remove quotes, nullify option value, and make fieldName )
		WSData = (item.data):gsub('"',''):gsub("'",""):gsub("option value"," xx"):gsub("input name"," fieldName") 
			
            -- fill table with keys
            local lines = {}
            local linesIndex = 1
            for keyField in string.gmatch( WSData,"[^%s, ]+" ) do -- loop over all 'words' in thedata
                if string.find(keyField,'fieldName=') then -- if 'word' is like fieldName=text
                    lines[linesIndex] = {}
                    lines[linesIndex].name =  keyField:gsub('fieldName=','') -- put text into name field 
                    linesIndex = linesIndex + 1
                end
            end

            -- fill table with values
            linesIndex = 1
            for keyField in string.gmatch( WSData,"[^%s, ]+" ) do 
                if string.find(keyField,'value=') then -- if 'word' is like value=text / number
                    if lines[linesIndex] == nil then lines[linesIndex] = {} end
                    lines[linesIndex].value =  keyField:gsub('value=','') -- put text / number into corresponding value field 
                    linesIndex = linesIndex + 1
                end
            end
            
            -- fill table usedFields only with names and values we are going to use to fill devices
            local usedFields = {}            
            for linesIndex = 1, #lines do 
                if fieldNames[lines[linesIndex].name] ~= nil then
                    usedFields[fieldNames[lines[linesIndex].name]] = lines[linesIndex].value  
                end
            end
            return usedFields
        end

        local function updateDevices(fields) -- update all ( declared ) devices. Specialized function to create required fields are local to this function
            local function windDirectionName(degrees) -- do not translate as domoticz web GUI depends on strings like E or S 
                if degrees ~= nil then degrees = tonumber(degrees) % 360 -- Ensure between 0 and 360
					local windDirections =
                    {
                            N={0,22.5}, -- 337,5- 360 will be catched later 
                            NE={22.5,67.5},
                            E={67.5,112.5},
                            SE={112.5,157.5},
                            S={157.5,202.5},
                            SO={202.5,247.5},
                            O={247.5,292.5},
                            NO={292.5,337.5},
                    }
		local minDegrees = 1
                local maxDegrees = 2
                for key, value in pairs(windDirections) do
                    if degrees >= value[minDegrees] and degrees < value[maxDegrees] then return key end
                end
                return 'N'
		end
            end

            local function windChill(windSpeed, temperature) -- official KNMI function to compute windchill
                windSpeed = tonumber(windSpeed)
                temperature = tonumber(temperature)
                if windSpeed ~= nil then
		if windSpeed < 1.3 or windSpeed > 49 or temperature < -46 or temperature > 17 then return temperature end
		return dz.utils.round(13.12 + (0.6215 * temperature) - (13.96 * windSpeed^0.16) + (0.4867 * temperature * 						windSpeed^0.16), 1)
		end
            end

            local function humidityStatus(temperature, humidity) -- as used in domoticz source
                humidity = tonumber(humidity)
                temperature = tonumber(temperature)
                if humidity <= 30 then return dz.HUM_DRY
                elseif humidity >= 70 then return dz.HUM_WET
                elseif  humidity >= 35 and humidity <= 65 and temperature >= 22 and temperature <= 26 then return dz.HUM_COMFORTABLE end
                return dz.HUM_NORMAL
            end


			local function humStatus(temperature, humidity) -- as used in domoticz source
				humidity = tonumber(humidity)
				temperature = tonumber(temperature)
				if humidity ~= nil then
					if humidity <= 30 then return dz.HUM_DRY
					elseif humidity >= 70 then return dz.HUM_WET
					elseif  humidity >= 35 and humidity <= 65 and temperature >= 22 and temperature <= 26 then return dz.HUM_COMFORTABLE
					else return dz.HUM_NORMAL 
					end
				end	
			end
			
            local function BarometerForecast(pressure) -- simplified forecast model
                if pressure == nil then return nil end -- Should not happen
                pressure = tonumber(pressure)
                if pressure < 966   then return dz.BARO_THUNDERSTORM
                elseif pressure < 993   then return dz.BARO_CLOUDY
                elseif pressure < 1007  then return dz.BARO_PARTLYCLOUDY
                elseif pressure < 1013  then return dz.BARO_UNSTABLE
                elseif pressure < 1033  then return dz.BARO_STABLE
                end
                return dz.BARO_SUNNY
            end    

            local function updateRain(rainRate) -- use time since last sample to calculate new total. Daily total is derived from total by domoticz 
                if rainRate ~= nil then
					rainRate = tonumber(rainRate)
					if dz.data.previousRainSample == 0 then 
						dz.log('Initial setting of the raindata. No update of the device yet',dz.LOG_FORCE)
						dz.data.previousRainSample = dz.time.dDate
						return
					end
					if rainRate > 1000 then 
						dz.log('Obvious wrong value. This would be more then 1 meter of rain per hour',dz.LOG_ERROR)
						return 
					end 
					local deltaSeconds = dz.time.dDate - dz.data.previousRainSample
					local rainIncrease = rainRate * ( deltaSeconds / 3600 )
					local previousRainTotal = math.max(dz.data.rainTotal,  rain.rain or 0) -- protect against reset or new device 
					dz.data.rainTotal = previousRainTotal + rainIncrease 
					rain.updateRain(rainRate * 100 , dz.utils.round(dz.data.rainTotal,1)) -- one decimal should be accurate enough
					rain.updateRain(rainRate * 100 , dz.utils.round(dz.data.rainTotal,1)) -- one decimal should be accurate enough
					dz.data.previousRainSample = dz.time.dDate
				end	
            end   

            -- update weatherDevices/ See dzVents wiki (https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting) for required parms of the update functions 
            if wind ~= nil then wind.updateWind
            (
                fields.windDirection, 
                windDirectionName(fields.windDirection), 
                fields.windSpeed, 
                fields.windGust, 
                fields.outdoorTemperature, 
                windChill(fields.windSpeed, fields.outdoorTemperature)
			--	dz.log('windChill ' .. windChill,dz.LOG_ERROR)
            ) end

            if insideTemperature ~= nil then insideTemperature.updateTemperature(fields.indoorTemperature) end

            if insideTemperatureHumidity then insideTemperatureHumidity.updateTempHum
            (
                fields.indoorTemperature, 
                fields.indoorHumidity, 
                humStatus(fields.indoorTemperature,fields.indoorHumidity)
            ) 
				inHum.updateHumidity(fields.indoorHumidity, 'HUM_NORMAL') 
tostring(humidityStatus(fields.indoorTemperature,fields.indoorHumidity)),dz.LOG_FORCE)
			end

            if outsideTemperature ~= nil then outsideTemperature.updateTemperature(fields.outdoorTemperature) end

            if outsideTemperatureHumidity ~= nil then outsideTemperatureHumidity.updateTempHum
            (
                fields.outdoorTemperature, 
                fields.outdoorHumidity, 
                humStatus(fields.outdoorTemperature,fields.outdoorHumidity)
            ) 
				outHum.updateHumidity(fields.outdoorHumidity, 'HUM_NORMAL') 
tostring(humidityStatus(fields.indoorTemperature,fields.indoorHumidity)),dz.LOG_FORCE)
			end

            if solarRadiation ~= nil then solarRadiation.updateRadiation(fields.solarRadiation) end

            if uvIndex ~= nil then uvIndex.updateUV(fields.UVI) end

            if rain ~= nil then updateRain(fields.hourlyRainRate) end

            if barometer ~= nil then barometer.updateBarometer
            (
                fields.relativePressure,
                BarometerForecast(fields.relativePressure)
            ) end
           
            if _G.logLevel == dz.LOG_DEBUG then dz.utils.dumpTable(fields) end
            
            if dailyRain ~= nil then dailyRain.updateCustomSensor(fields.dailyRain) end
            if weeklyRain ~= nil then weeklyRain.updateCustomSensor(fields.weeklyRain) end
            if monthlyRain ~= nil then monthlyRain.updateCustomSensor(fields.monthlyRain) end
            if yearlyRain ~= nil then yearlyRain.updateCustomSensor(fields.yearlyRain) end
            
            if gustSpeed ~= nil then gustSpeed.updateCustomSensor(fields.windGust) end
            if avgWind ~= nil then avgWind.updateCustomSensor(fields.windSpeed) end
            
        end

     -- main 
 --[[        if item.isTimer or item.isDevice then
            checkWebpageResponse()
            getWeatherStationData()
		--elseif item.ok then
		elseif item.isHTTPResponse and item.ok then -- statusCode == 2xx
			dz.log ("!Code!: " .. item.statusCode, dz.LOG_INFO)
			dz.log ("!ok!  : " .. tostring(item.ok), dz.LOG_INFO)
			--dz.log ("!HTTP!: " .. tostring(item.isHTTPResponse), dz.LOG_INFO)
			--dz.log ("Response object: " .. item.data, dz.LOG_INFO)												   
			updateDevices(processHTM(item.data))
		--	end
        else
            dz.log('Could not get (good) data from ' .. weatherStationIP,dz.LOG_ERROR)
            dz.log(item.data,dz.LOG_DEBUG)
        end
]]--
         if item.isTimer or item.isDevice then
            checkWebpageResponse()
            getWeatherStationData()
		end	
		dz.log ("!Shell!: " .. tostring(item.isShellCommandResponse), dz.LOG_INFO)
		dz.log ("!Code!: " .. tostring(item.statusCode), dz.LOG_INFO)
		if item.isShellCommandResponse then
			dz.log('Planning program was executed.', dz.LOG_INFO)			
			if (item.statusCode==0) then
				updateDevices(processHTM(item.data))
			end
		end
    end
}
En gros, j'ai adapté :

Code : Tout sélectionner

    { 
        devices = {'WH2600-2-Wind', 'WH2600-2-Solar Radiation', 'WH2600-2-Outdoor', 'WH2600-2-UV', 'WH2600-2-Rain' },
        timer = { 'every 5 minutes' }, -- or by a timer-rule
	shellCommandResponses = { scriptVar }
    },

Code : Tout sélectionner

       local function getWeatherStationData()
			dz.executeShellCommand({
				command = 'curl "http://' .. weatherStationIP .. '/livedata.htm"',
				callback = scriptVar,
				--connect-timeout 5,
				--max-time 10,
			})
		end

Code : Tout sélectionner

		if item.isShellCommandResponse then
			dz.log('Planning program was executed.', dz.LOG_INFO)			
			if (item.statusCode==0) then
				updateDevices(processHTM(item.data))
			end
		end
Avec cela ça tourne impec ...
;)
RaspberryPi - RFLink - Zwave - WH2600
Domoticz : 2020.2 | Dashticz : V3.12 Master | dzvents : 3.0.2 | Python : 3.7.3
Répondre