0

I got an error when i run the bash script below.

pi@raspberrypi:~/dev-domoticz/scripts $ ./dht_22.sh
21.2
48.2
HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: SID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT
<html><head><title>Unauthorized</title></head><body><h1>

This script reads the DHT22 chip for temp and humidity dht_22.sh and communicate with the Domoticz server with json. So i can see the current temp/humi on my Domoticz server:

#!/bin/sh
# Domoticz server
SERVER="10.0.0.110:8080"
# DHT IDX
DHTIDX="4"

# DHTPIN
DHTPIN="4"

# TEMP FILE
TMPFILE="/var/tmp/temp.txt"

cpt=0
while [ $cpt -lt 6 ]
do
TEMP=""

sleep 5

sudo nice -20 /home/pi/dev-domoticz/scripts/Adafruit_Python_DHT/examples/AdafruitDHT.py 22 $DHTPIN > /var/tmp/temp.t$
#TEMP=$(cat /var/tmp/temp.txt | grep "Temp" | awk '{ print $3 }')
#TEMP=$(cat /var/tmp/temp.txt | grep "Temp")

TEMP=$(awk ' /Temp/ {print substr ($0,6,4)}' /var/tmp/temp.txt)
HUM=$(awk ' /Humidity/ {print substr ($0,22,4)}' /var/tmp/temp.txt)
echo $TEMP
echo $HUM

# Send data
curl  -s -i -H "Accept: application/json" "http://10.0.0.110:8080/json.htm?type=command&param=udevice&idx=$DHTIDX&nv$

TEMP=""
HUM=""

exit 0
cpt=$(($cpt+1))
done
exit 1

When i just run the json line in a browser, i also receive a 401 Unauthorized error. I gues i have to enter some login information, so i also tryed something like this:

http://10.0.0.110:8080/json.htm?username=test=&password=test=&type=command&param=udevice&idx=4&nvalue=0&svalue=21;40;2

But still the 401 error.

Can some one help me out?

Matthijs
  • 29
  • 1
  • 6
  • Use `--user` key for auth with curl, like that: `curl -s -i -H "Accept: application/json" --user username:password "http://10.0.0.110:8080/json.htm?type=command&param=udevice&idx=$DHTIDX&nv$` – Viktor Khilin Feb 02 '18 at 12:19
  • Thanks for you responce so quickly. I tryed and received the next new error: `pi@raspberrypi:~/dev-domoticz/scripts $ ./dht_22.sh 20.9 48.7 HTTP/1.1 200 OK Content-Length: 24 Content-Type: application/json;charset=UTF-8 Cache-Control: no-cache Pragma: no-cache Access-Control-Allow-Origin: * Set-Cookie: SID=b80e45b9a41be91ac32b43308b391cff_OWI3Y2ZkNTMtNTFmNi00NjlhLWFjZmQtY2NhZmI1Y2Y0YzNj.1517574810; HttpOnly; path=/; Expires=Fri, 02 Feb 2018 12:33:30 GMT { "status" : "ERR" }` – Matthijs Feb 02 '18 at 12:25
  • You have authorized successfully (HTTP/1.1 200 OK), at least. `{ "status" : "ERR" }` don't belongs to `curl`, I'm not sure I'll be able to help here :( – Viktor Khilin Feb 02 '18 at 12:25
  • Ahh great, then I'll figure it out. Thanks m8. – Matthijs Feb 02 '18 at 12:28

1 Answers1

0

Well, cost me some time but it work now. Your solution was correct Viktor Khilin but my Domoticz software gave me some problems.

The solution was this:

curl -s -i -H "Accept: application/json" "http://10.0.0.110:8080/json.htm?&username=test=&password=test=&type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;2"

Thanks for helping me out.

Matthijs
  • 29
  • 1
  • 6