dzvents and json [solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
dlube
Posts: 29
Joined: Tuesday 31 March 2020 19:29
Target OS: -
Domoticz version:
Location: France

dzvents and json [solved]

Post 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...
Last edited by dlube on Tuesday 08 August 2023 23:33, edited 1 time in total.
Raspbian Buster on Raspberry pi 3 B+ Domoticz Version: 2023.2 (build 15474)
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dzvents and json

Post by jvdz »

How did you do the urlencode in the script?
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
dlube
Posts: 29
Joined: Tuesday 31 March 2020 19:29
Target OS: -
Domoticz version:
Location: France

Re: dzvents and json

Post 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
Raspbian Buster on Raspberry pi 3 B+ Domoticz Version: 2023.2 (build 15474)
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: dzvents and json

Post 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')
dlube
Posts: 29
Joined: Tuesday 31 March 2020 19:29
Target OS: -
Domoticz version:
Location: France

Re: dzvents and json

Post by dlube »

Unfortunately, if I replace the sensor name by 'Test' I still have the error
Raspbian Buster on Raspberry pi 3 B+ Domoticz Version: 2023.2 (build 15474)
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: dzvents and json

Post 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.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: dzvents and json

Post 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?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
dlube
Posts: 29
Joined: Tuesday 31 March 2020 19:29
Target OS: -
Domoticz version:
Location: France

Re: dzvents and json [solved]

Post 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...
Raspbian Buster on Raspberry pi 3 B+ Domoticz Version: 2023.2 (build 15474)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest