Page 1 of 1

Get DHT value without IP

Posted: Friday 11 December 2015 3:30
by doodoovane
Hello,

First of all, be sure that I feel sorry for my bad english. I'll do my best :D
I'm trying to get my Rpi running Domoticz with a DHT22 wired on the GPIO4 without any connexion.
Let me explain: to get my values up to date in domoticz from the sensor, i've found a script that use json to send Temperature humidity values to Domoticz IP. The problem is that if the Rpi change his IP or lose the connexion the DHT isn't updated in Domoticz anymore and so are the events related.

#!/bin/sh
# Domoticz server
SERVER="192.168.0.29:8080"
# DHT IDX
# le numero de l4IDX dans la liste des dispositifs Domoticz
DHTIDX="1"
DHTIDX2="2"
DHTIDX3="3"
DHTIDX4="4"
#DHTPIN
# LE GPIO ou est connecte le DHT11
DHTPIN="4"
# si vous avez un DHT22 modifiez plus bas sur la ligne Adafruit_DHT 11 par Adafruit_DHT 22
# TMPFILE : chemin pour fichier temporaire a placer dans le RAMDRIVE pour eviter les
# ecritures sur la SD card
# sinon chemin ou sera ecrit le fichier contenant les temperature
# /tmp/temper.txt est un bon choix si pas de RAMDRIVE installe
# consultez www.easydomoticz.com pour tout savoir
TMPFILE="/var/tmp/temper.txt"
TEMP=""

until [ -n "$TEMP" ] ; do
sleep 5
sudo nice -20 Adafruit_DHT 22 $DHTPIN > $TMPFILE
TEMP=$(cat $TMPFILE|grep Temp |awk '{print $3}')
done

TEMP=$(cat $TMPFILE|grep Temp |awk '{print $3}')
HUM=$(cat $TMPFILE |grep Temp |awk '{print $7}')

# Send data
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;2"
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX2&nvalue=0&svalue=$TEMP"
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX3&nvalue=0&svalue=$HUM"
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX4&nvalue=0&svalue=$HUM"
TEMP=""
HUM=""

Is there any way for me to get this work without the need of any connexion?

Thank you for your help

Re: Get DHT value without IP

Posted: Friday 11 December 2015 6:02
by antwan
Change the server ip address to: 127.0.0.1:8080

Re: Get DHT value without IP

Posted: Tuesday 15 December 2015 15:51
by doodoovane
Thank you it works perfectly!