Page 1 of 1

json script with curl not working

Posted: Thursday 28 April 2016 17:05
by Dwsmit
Hi, I am new to json scripts.

I have copied json script from a item to check out NAS info.

When I use the curl command on the command line it works.
When I do this in a bash script it does not work.

Can you help me to fix my problem.

#!/bin/bash
# Settings
TempIP="192.168.10.240" # NAS IP Address
DOMO_IP="192.168.10.204" # Domoticz IP Address
DOMO_PORT="8080" # Domoticz Port
PASSWORD="public" # Password
TEMP_IDX="9" # Virtual switch Temp STATUS
TEMP1_IDX="10" # Virtual temerature sensor Woonkamer
TEMP2_IDX="11" # Virtual temerature sensor Buiten
TEMP3_IDX="12" # Virtual temerature sensor Zolder
HUM_IDX="13" # Virtual temerature sensor Woonkamer
# Check if NAS in online
PINGTIME=`ping -c 1 -q $TempIP | awk -F"/" '{print $5}' | xargs`
echo $PINGTIME
# system ON
echo "System ON"
# Send data
Test=`curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$TEMP_IDX&switchcmd=On"`
echo $Test
# Temprature Woonkamer
temp=`snmpget -v2c -c $PASSWORD -Oqv $TempIP .1.3.6.1.4.1.31440.10.12.1.1.3 | cut -c 2-6`
echo $temp
# Send data
Test=`curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=device&idx=$TEMP1_IDX&nvalue=0&svalue=$temp"`

Re: json script with curl not working

Posted: Thursday 28 April 2016 17:17
by Westcott
I think that you only need -
Test=`curl "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$TEMP_IDX&switchcmd=On"`

Re: json script with curl not working

Posted: Thursday 28 April 2016 22:41
by Dwsmit
Thanks, this one now works.
But the second still is not.

# Temprature Woonkamer
temp=`snmpget -v2c -c $PASSWORD -Oqv $TempIP .1.3.6.1.4.1.31440.10.12.1.1.3 | cut -c 2-6`
echo $temp
# Send data
Test=`curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=device&idx=$TEMP1_IDX&nvalue=0&svalue=$temp"`