Page 1 of 1

http command

Posted: Wednesday 12 June 2019 10:08
by Sagitarius
As you can add multipple devices to a scene, would be great to have also the option to add multipple http commands

Re: http command

Posted: Wednesday 12 June 2019 10:48
by Egregius
Put them in a script and execute that script.

dzvents openURL command domoticz

Posted: Monday 10 May 2021 14:24
by Sagitarius
Hi All,
I'm trying to get PV information from Benning device via dzvents into domoticz.
The IE http command like "http://<IP PV>/getentry.cgi?&oid=10" works fine.
Result e.g.
[
{
"oid" : 10,
"label" : "UserConfig.Inverter.Info.SystemName", "type" : "S",
"val" : "PVINV110",
"uitext" : "System name", "savetype" : 1,
"factor" : 1.000000, "unit" : "", "portal" : 1,
"AutoZero" : 0,
"fb" : 1
},

but to be honest, I have no clue how the dzvents "openURL" command should look like :(

Anyone out there to help ?

Many thanks
Rgds
Sagitarius

Re: http command

Posted: Monday 10 May 2021 14:53
by erem

Re: http command

Posted: Tuesday 11 May 2021 17:08
by Sagitarius
Hi Rob,
thanks, I had a view on this but the 2nd part, looks like, is a bit complex for me yet.
That's what I have so far

Code: Select all

return {
    on = {
    timer = {'every 1 minutes'},
    httpResponses = { 'oid' }
    },

    execute = function(dz, item)
        
    if (item.isTimer) then  
	    dz.openURL({
	    url =  'http://192.168.178.20/getentry.cgi?&oid=10',
	    method = 'GET',
	    callback = 'oid',
	    })
	end

    if (item.isHTTPResponse) then
        if (item.ok) then
            local pv_data = dz.utils.toJSON(item.data)
          	dz.log('PVSW30 ' .. pv_data, dz.LOG_ERROR)
        else
            dz.log('PVSW30 not OK', dz.LOG_ERROR)
        end
    end

    end
}
Log:

Code: Select all

2021-05-11 16:57:00.621 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-05-11 16:57:01.082 Status: dzVents: Info: Handling httpResponse-events for: "oid
2021-05-11 16:57:01.082 Status: dzVents: Info: ------ Start internal script: PVSW30 dz: HTTPResponse: "oid"
2021-05-11 16:57:01.086 Status: dzVents: Error (2.4.19): PVSW30 "-1"
2021-05-11 16:57:01.086 Status: dzVents: Info: ------ Finished PVSW30 dz 
Original :

Code: Select all

http://192.168.178.20/getentry.cgi?&oid=10
{ "oid" : 10, "label" : "UserConfig.Inverter.Info.SystemName", "type" : "S", "val" : "PVSW30", "uitext" : "System name", "savetype" : 1, "factor" : 1.000000, "unit" : "", "portal" : 1, "AutoZero" : 0, "fb" : 1 }
Any further detailed information is really appreciated

Many thanks

Rgds
Paul

Re: http command

Posted: Tuesday 11 May 2021 19:49
by waaren
Sagitarius wrote: Tuesday 11 May 2021 17:08 thanks, I had a view on this but the 2nd part, looks like, is a bit complex for me yet.
Any further detailed information is really appreciated
Can you try this one? It is not complete but should point you in the right direction

Code: Select all

local scriptVar = 'oid'

return
{
    on =
    {
        timer =
        {
            'every 1 minutes'
        },
        httpResponses =
        {
            scriptVar,
        },
    },

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

    execute = function(dz, item)

        if item.isTimer then
            dz.openURL(
            {
                url =  'http://192.168.178.20/getentry.cgi?&oid=10',
                method = 'GET',
                callback = scriptVar,
            })
        elseif item.isHTTPResponse and item.ok then
            dz.log('item.data: ' .. item.data, dz.LOG_FORCE)

            dz.utils.dumpTable(item) -- only during debug

            local pv_data = dz.utils.fromJSON(item.data) -- you want to convert a JSON to a Lua table
            dz.utils.dumpTable(pv_data) -- only during debug
        else
            dz.log('PVSW30 not OK', dz.LOG_ERROR)
        end

    end
}

Re: http command

Posted: Thursday 13 May 2021 10:35
by Sagitarius
Thanks Waaren, will spend some time over the weekend

Re: http command

Posted: Friday 14 May 2021 11:58
by Sagitarius
Hi Waaren

that's what I get, but I'm not sure what kind of information would help.
The http command via IE works fine. It collects data from a XML database where I do not have the name from.
But anything I tried so far, the result via openURL would be -1, which means wrong oid no. and the JSON object
is not shown.

2021-05-14 11:38:01.038 Status: dzVents: Info: oid: ------ Start internal script: Script #2: HTTPResponse: "oid"
2021-05-14 11:38:01.038 Status: dzVents: !Info: oid: item.data: -1
2021-05-14 11:38:01.038 Status: dzVents: > isHTTPResponse: true
2021-05-14 11:38:01.038 Status: dzVents: > _contentType: text/html
2021-05-14 11:38:01.038 Status: dzVents: > isGroup: false
2021-05-14 11:38:01.038 Status: dzVents: > isJSON: false
2021-05-14 11:38:01.038 Status: dzVents: > ok: true
2021-05-14 11:38:01.038 Status: dzVents: > statusText: OK
2021-05-14 11:38:01.038 Status: dzVents: > trigger: oid
2021-05-14 11:38:01.038 Status: dzVents: > callback: oid
2021-05-14 11:38:01.038 Status: dzVents: > protocol: HTTP/1.1
2021-05-14 11:38:01.038 Status: dzVents: > isSecurity: false
2021-05-14 11:38:01.038 Status: dzVents: > isTimer: false
2021-05-14 11:38:01.038 Status: dzVents: > data: -1
2021-05-14 11:38:01.038 Status: dzVents: > headers:
2021-05-14 11:38:01.038 Status: dzVents: > Server: Benning Web Server
2021-05-14 11:38:01.038 Status: dzVents: > Content-Type: text/html
2021-05-14 11:38:01.038 Status: dzVents: > Connection: close
2021-05-14 11:38:01.038 Status: dzVents: > isVariable: false
2021-05-14 11:38:01.038 Status: dzVents: > statusCode: 200
2021-05-14 11:38:01.039 Status: dzVents: > isDevice: false
2021-05-14 11:38:01.039 Status: dzVents: > isScene: false
2021-05-14 11:38:01.039 Status: dzVents: > baseType: httpResponse
2021-05-14 11:38:01.042 Status: dzVents: Error (2.4.19): oid: An error occured when calling event handler Script #2
2021-05-14 11:38:01.043 Status: dzVents: Error (2.4.19): oid: /home/pi/domoticz/dzVents/runtime/Utils.lua:182: bad argument #1 to 'pairs' (table expected, got number)
2021-05-14 11:38:01.043 Status: dzVents: Info: oid: ------ Finished Script #2

I could not find a hint in regards to bad argument .......

Re: http command

Posted: Friday 14 May 2021 14:05
by waaren
Sagitarius wrote: Friday 14 May 2021 11:58 that's what I get, but I'm not sure what kind of information would help.
The call only returns -1 so not much to work with. It should return the same information as what comes back if you enter this http in your browser. Can you try to do this from an incognito browser page and post the result?

Re: http command

Posted: Saturday 15 May 2021 13:05
by Sagitarius
I tested Chrome and Firefox in private mode, Firefox has no problem but Chrome
has problem with oid's below 10000, they are not working but above some.
I did the same test with Domoticz and got the same result like with Chrome.