Page 1 of 1

dzvents and json [solved]

Posted: Tuesday 08 August 2023 18:13
by dlube
Hi
How can I construct the url to create a device with the API/json
This one
generate the error below
2023-08-08 18:06:07.772 Error: Error parsing http request address: ::ffff:127.0.0.1
2023-08-08 18:06:07.773 Error: Error opening url: http://127.0.0.1:8080/json.htm?type=com ... me=Blagnac (Indoor)-Extérieur&sensortype=82
If I use the IP of domoticz I get the same error
2023-08-08 17:56:08.782 Error: Error parsing http request address: ::ffff:192.168.1.45
2023-08-08 17:56:08.784 Error: Error opening url: http://192.168.1.45:8080/json.htm?type= ... me=Blagnac (Indoor)-Extérieur&sensortype=82
encodeURL change nothing
If I copy the url in a browser, it work...

Re: dzvents and json

Posted: Tuesday 08 August 2023 19:11
by jvdz
How did you do the urlencode in the script?

Re: dzvents and json

Posted: Tuesday 08 August 2023 19:22
by dlube
Dz.utils.urlEncode
But thé problem is not there.
If I copy a non encode URL in the browser, it create the device

Re: dzvents and json

Posted: Tuesday 08 August 2023 19:23
by willemd
I first assign the json to a string and then use domotiz.openURL
or call domoticz.openURL directly if I don't need to process the response.

It looks like you sensor name contains spaces. Maybe that is why it fails?

If you want to create a device with spaces (or other special characters) in the name, probably you have to preceed these spaces with a \ in Dzvents to make sure Dzvents takes those spaces as-is.


Example 1 (part extracted from script):

Code: Select all

            local urlString = 'http://xxx.xxx.xxx.xxx:8080/json.htm?type=graph&sensor=counter&idx=105&range=month'
            domoticz.openURL({
                url = urlString,
                method = 'GET',
                callback = 'monthlyData'
                })
Example 2:

Code: Select all

domoticz.openURL('http://127.0.0.1:8080/json.htm?type=command&param=sendopenthermcommand&idx=8&cmnd=TC=0')

Re: dzvents and json

Posted: Tuesday 08 August 2023 19:28
by dlube
Unfortunately, if I replace the sensor name by 'Test' I still have the error

Re: dzvents and json

Posted: Tuesday 08 August 2023 22:16
by willemd
dlube wrote: Tuesday 08 August 2023 19:28 Unfortunately, if I replace the sensor name by 'Test' I still have the error
Show us some code. Maybe we can help more.

Re: dzvents and json

Posted: Tuesday 08 August 2023 22:48
by waltervl
Are your security settings correct?
Do you have 127.0.0.1 and or the local server IP in your trusted network settings? Is "Allow API authorization for HTTP" switched on? This probably has no influence but you never know...

Is it the urlencode due to French characters? What happens if you remove those special characters in your script?

Re: dzvents and json [solved]

Posted: Tuesday 08 August 2023 23:16
by dlube
I named a variable 'module' which is maybe a reserved word.
I renamed this variable and moved urlEncode on the device name only => all is working...