Page 1 of 1

Get data from PHP page

Posted: Monday 08 February 2021 15:29
by jberinga
Is it possible to get data from a PHP page into Domozticz?

I have been playing around with a script that pulls XML data from a DSL modem, but I can't get this working with data from the PHP page:
Spoiler: show

Code: Select all

local scriptVar = 'getWSG'

return
{
    on =
    {
        timer =
        {
            'every minute',
        },

        httpResponses = 
        {
            scriptVar,
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)
        if item.isTimer then
            dz.openURL(
            {
                url = "https://www.weerstation-grootegast.nl/weather28/ws_realtime.php",
                method = 'GET',
                callback = scriptVar,
            })
        elseif item.ok then -- statusCode == 2xx
            local wsg =  dz.utils.stringSplit(data,',')

            dz.utils.dumpTable(wsg)
            local weer = wsg.temp.weer._attr

            -- get one value
            dz.log('Temperatuur: ' .. weer.temp,dz.LOG_DEBUG)

            -- get all values
            for key, value in pairs(weer) do
                dz.log(key .. ': '.. value,dz.LOG_DEBUG)
            end
        else
            dz.log('problem retrieving data from WSG',dz.LOG_ERROR)
            dz.log(item.data,dz.LOG_ERROR) --
        end
    end
}
Hopefully someone can help me with this or let me know that what I want to do is not possible.

Re: Get data from PHP page

Posted: Monday 08 February 2021 16:43
by waaren
jberinga wrote: Monday 08 February 2021 15:29 Is it possible to get data from a PHP page into Domozticz?
Hopefully someone can help me with this or let me know that what I want to do is not possible.
Yes it's possible.

Try this one

Code: Select all

local scriptVar = 'getWSG'

return
{
    on =
    {
        timer =
        {
            'every minute',
        },

        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)
        if item.isTimer then
            dz.openURL(
            {
                url = "https://www.weerstation-grootegast.nl/weather28/ws_realtime.php",
                method = 'GET',
                callback = scriptVar,
            })
        elseif item.ok and item.json then -- statusCode == 2xx

            -- Show all Key value pairs
            dz.utils.dumpTable(item.json)

            -- Pick one
            dz.log('Temperatuur: ' .. item.json.tempTL,dz.LOG_DEBUG)

        else
            dz.log('problem retrieving data from WSG',dz.LOG_ERROR)
            dz.log(item.data,dz.LOG_ERROR) --
        end
    end
}

Re: Get data from PHP page  [Solved]

Posted: Monday 08 February 2021 17:24
by jberinga
Thanks waaren! Your suggestion works.