json script with curl not working

Moderator: leecollings

Post Reply
Dwsmit
Posts: 3
Joined: Wednesday 20 April 2016 7:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

json script with curl not working

Post 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"`
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: json script with curl not working

Post 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"`
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
Dwsmit
Posts: 3
Joined: Wednesday 20 April 2016 7:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: json script with curl not working

Post 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"`
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest