curl (bash) and JSON  [Solved]

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

Moderator: leecollings

Post Reply
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

curl (bash) and JSON

Post by Number8 »

Hello,
i'm trying to use curl on bash, as a mean to send to Domoticz via customerevents a JSON data string. I having problems with [] in bash.
The following code is sent to Domoticz, fires up the related custom event and is recognized as a valid JSON data structure

Code: Select all

data='\{"sensor":\{"port":2,"output":1,"power":1.13619548\},"status":"success"\}'
url=$DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=customevent&event=mFI&data='$data
curl --silent $url > /dev/null
With data variable including a table in the JSON string, it does not even fireup custom event

Code: Select all

data='\{"sensors":[\{"port":2,"output":1,"power":1.13619548\}],"status":"success"\}'
I guess it is a matter of escaping [], I searched a lot with no success so far
dzvents 3.04
Debian buster on NUC and three RPi with buster.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: curl (bash) and JSON  [Solved]

Post by waaren »

Number8 wrote: Tuesday 05 May 2020 15:54 i'm trying to use curl on bash, as a mean to send to Domoticz via customerevents a JSON data string. I having problems with [] in bash.
I guess it is a matter of escaping [], I searched a lot with no success so far
If you use the -g or --globoff option of curl you can leave out the escapes.

try:
data='{"sensors":[{"port":2,"output":1,"power":1.13619548}],"status":"success"}'
url="$DOMOTICZSERVER:$DOMOTICZPORT/json.htm?type=command&param=customevent&event=mFI&data=$data"
curl --globoff --silent $url > /dev/null
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: curl (bash) and JSON

Post by Number8 »

sooooooooooooo easy. Thanks @waaren I sweat on this one
Debian buster on NUC and three RPi with buster.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest