DHT22 sensor value's into Domoticz

Moderator: leecollings

User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

DHT22 sensor value's into Domoticz

Post by ILoveIOT »

Read temperature and humidity from DHT11 or DHT22 sensor on a Orange/Raspberry PI and put the value's into Domoticz every 3 minutes.

* Customize the DHT_PIN and Domoticz IDX below, make a dummy temp/hum in Domoticz.
* Console output is default off, silent in console output, enable below.
* Its seems normal that you see "Data not good, skip" a few times, if enabled below.
* IP address is set to 127.0.0.1 change below.


* For compiling use : cd /root/scripts/gpio/ ; gcc -Wall -o dht dht.c -lwiringPi
* For console use : /root/scripts/gpio/dht
* For background use : /root/scripts/gpio/dht &

Code: Select all

/*
 * dht.c:
 * Read temperature and humidity from DHT11 or DHT22 sensor on a Orange/Raspberry PI and put the value's into Domoticz every 3 minutes.
 *
 * Customize the DHT_PIN and Domoticz IDX below, make a dummy temp/hum in Domoticz.
 * Console output is default off, silent in console output, enable below.
 * Its seems normal that you see "Data not good, skip" a few times, if enabled below.
 * IP address is set to 127.0.0.1 change below.
 *
 *
 * For compiling use   : cd /root/scripts/gpio/ ; gcc -Wall -o dht dht.c -lwiringPi
 * For console use     : /root/scripts/gpio/dht
 * For background use  : /root/scripts/gpio/dht &
 * 
 * More info : http://www.uugear.com/portfolio/read-dht1122-temperature-humidity-sensor-from-raspberry-pi/
 *
 * Updated : 04-03-2019 by ILoveIoT.
 * 
 */

#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#define MAX_TIMINGS	85



// gpio readall BCM10 |  wPi24 |  GPIO.24 | ALT3 | 0 | Physical 35 |
#define DHT_PIN 24	/* GPIO-24 */

// Set the Domoticz IDX from the dummy device (temp/hum) you created
#define DOM_IDX 196	/* Domoticz IDX 196 */



int data[5] = { 0, 0, 0, 0, 0 };

void read_dht_data()
{
	uint8_t laststate	= HIGH;
	uint8_t counter		= 0;
	uint8_t j			= 0, i;

	data[0] = data[1] = data[2] = data[3] = data[4] = 0;

	/* pull pin down for 18 milliseconds */
	pinMode( DHT_PIN, OUTPUT );
	digitalWrite( DHT_PIN, LOW );
	delay( 30 );

	/* prepare to read the pin */
	pinMode( DHT_PIN, INPUT );

	/* detect change and read data */
	for ( i = 0; i < MAX_TIMINGS; i++ )
	{
		counter = 0;
		while ( digitalRead( DHT_PIN ) == laststate )
		{
			counter++;
			delayMicroseconds( 2 );
			if ( counter == 255 )
			{
				break;
			}
		}
		laststate = digitalRead( DHT_PIN );

		if ( counter == 255 )
			break;

		/* ignore first 3 transitions */
		if ( (i >= 4) && (i % 2 == 0) )
		{
			/* shove each bit into the storage bytes */
			data[j / 8] <<= 1;
			if ( counter > 16 )
				data[j / 8] |= 1;
			j++;
		}
	}

	/*
	 * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte
	 * print it out if data is good
	 */
	if ( (j >= 40) &&
	     (data[4] == ( (data[0] + data[1] + data[2] + data[3]) & 0xFF) ) )
	{
		float h = (float)((data[0] << 8) + data[1]) / 10;
		if ( h > 100 )
		{
			h = data[0];	// for DHT11
		}
		float c = (float)(((data[2] & 0x7F) << 8) + data[3]) / 10;
		if ( c > 125 )
		{
			c = data[2];	// for DHT11
		}
		if ( data[2] & 0x80 )
		{
			c = -c;
		}
		
		// For console temp & hum readings uncomment these 2 lines
		//float f = c * 1.8f + 32;
		//printf( "Humidity = %.1f %% Temperature = %.1f *C (%.1f *F)\n", h, c, f );

	
		// Making the string with sensor data for Domoticz
		char str1[] = "/bin/bash -c 'curl -i -s \"http://192.168.8.189:8080/json.htm?type=command&param=udevice&idx=";
		
		// Put variable c (Value celsius) into a string
		char str2[25]; //size of the number
		sprintf(str2, "%g", c);
		
		// Some comma separated value's in between
		char str3[] = ";";
		
		// Put variable h (Value humidity) into a string
		char str4[25]; //size of the number
		sprintf(str4, "%g", h);
		
		// And the final end string
		char str5[] = ";0\"' > /dev/null 2>&1";
		
		// Setting the domoticz IDX var from above
		char str6[25]; //size of the number
		sprintf(str6, "%i", DOM_IDX);
		char str7[] = "&";
		char str8[] = "nvalue=0&svalue=";

		// Concentrate all the str1/str8 and resulting in 1 string is stored in str1.
		strcat(str6,str7);
		strcat(str6,str8);
		strcat(str1,str6);
		strcat(str2,str3);
		strcat(str2,str4);
		strcat(str2,str5);
		strcat(str1,str2);	
		
		// If you wanna view the output of the Domoticz string on console
		//puts(str1);  
	
		// Case of invalid celsius temps, ignore more then +80 or -40 or 0, and recheck in 3sec
		if ( c > -40 && c < 80 && c != 0 )
		{		
			// Send the string/data to Domoticz server
			system(str1);
			
			//delay( 2000 ); /* wait 2 seconds before next read */
			//delay( 300000 ); /* wait 5 minutes before next read */
			delay( 180000 ); /* wait 3 minutes before next read */
			
		} else {
			delay( 3000 ); /* wait 3 seconds before next try */
		}

		
		
	} else {
		// Uncomment this line below if you dont see any data coming
		//printf( "Data not good, skip\n" );
	}
}

int main( void )
{
	//printf( "Orange/Raspberry PI DHT11/DHT22 temperature/humidity test\n" );

	if ( wiringPiSetup() == -1 )
		exit( 1 );

	while ( 1 )
	{
		read_dht_data();
		delay( 5000 ); /* wait 5 seconds before next try */
	}

	return(0);
}

Last edited by ILoveIOT on Wednesday 07 October 2020 18:01, edited 1 time in total.
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
User avatar
Teknor
Posts: 30
Joined: Monday 08 February 2016 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.48
Location: Norway
Contact:

Re: DHT22 sensor value's into Domoticz

Post by Teknor »

ILoveIOT wrote: Thursday 28 March 2019 21:45

* For compiling use : cd /root/scripts/gpio/ ; gcc -Wall -o dht dht.c -lwiringPi
* For console use : /root/scripts/gpio/dht
* For background use : /root/scripts/gpio/dht &

Can you please elaborate on this section? Where can I store the script and how can I make it run in the background?

(I am using RPI 3 and raspian Buster OS)
Raspberry Pi 3 | EasyESP NodeMCU v3 | RFXTRX433e | Mysensors NRF24L01 | MotionEYE | PikrellCam
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: DHT22 sensor value's into Domoticz

Post by ILoveIOT »

Waar kan ik het script opslaan
Ik gebruik dus

Code: Select all

/root/scripts/gpio
maar dat mag je zelf weten, maar zo kan je wel alles in het script aanhouden.
en hoe kan ik het op de achtergrond laten draaien?
Voor achtergrondgebruik:

Code: Select all

/root/scripts/gpio/dht &
dus dit commando gebruik je om het in de achtergrond te laten verdwijnen, dus het script/programma heet dus dht, bij meerdere dht1, dht2 etc.

Code: Select all

* For compiling use   : cd /root/scripts/gpio/ ; gcc -Wall -o dht dht.c -lwiringPi
* For console use     : /root/scripts/gpio/dht
* For background use  : /root/scripts/gpio/dht &
Laat maar weten waar je tegenaan loopt ;) eerst even "/root/scripts/gpio/dht" draaien zodat je wat output op de console ziet, als dat werkt en komt in Domoticz, dan op achtergrond gaan.
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
Freelance
Posts: 10
Joined: Wednesday 07 October 2020 12:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DHT22 sensor value's into Domoticz

Post by Freelance »

Hi,
i'm new here and trying to setup AM2302/DHT22 with Domoticz.
I can get correct sensor values with python code according to this guide https://pimylifeup.com/raspberry-pi-hum ... sor-dht22/
I use pin 18 for the DHT 22
On pin 4 i have a ds18b20 which was easy to set up in the devices.

Going back to your guide here, i compiled the code and changed the pin to 18 and IDX to 3
The folder used is ~/domoticz/scripts , contents of the folder are:
buienradar_rain_example.pl dht dht.c domoticz.conf _domoticz_main _domoticz_main.bat download_update.sh dzVents install.sh logrotate lua lua_parsers python readme.txt restart_domoticz templates update_domoticz

So there is both dht.c and dht files

the output of the gcc -Wall -o dht dht.c -lwiringPi was OK

running dht command does not do anything = -bash: dht: command not found

opening http://192.168.1.209:8080/json.htm?type ... vice&idx=3 gives ERR

I'm doing something wrong and missing something.

Could you please guide a newbie in this?

I'm trying to get the 5V relay to start the heater in my greenhouse and that's the next challenge after i get the DHT22 working.
The ds18b20 is working but i want to use that one for external temperature and that should not start the relay.
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: DHT22 sensor value's into Domoticz

Post by ILoveIOT »

running dht command does not do anything = -bash: dht: command not foun
Run full path like /domoticz/scripts/dht ?

Also you comment something out first in the script to get full output just for the console, later,..uncomment.
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
Freelance
Posts: 10
Joined: Wednesday 07 October 2020 12:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DHT22 sensor value's into Domoticz

Post by Freelance »

Thanks, sorry for my lack of skills :)

I managed to get it working with a python script according to instruction in another thread here
https://domoticz.com/forum/viewtopic.ph ... 22#p252615

Coping the linked french script and changing to correct parameters (same as i tried in the dht.c) i managed to get the sensor working in Domoticz.
I can now see both temperature and humidity from the AM2302 and the separate temperature from the ds18b20

On to the relay now, will keep on reading and researching how to control the relay with the AM2302 temperature levels.


Thanks! Great forum!
Freelance
Posts: 10
Joined: Wednesday 07 October 2020 12:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DHT22 sensor value's into Domoticz

Post by Freelance »

Hmm, i can now run the dht command with full pathbut nothing happens. Below is the copy from dht.c that i used to compile the dht
IDX=3 and i use GPIO18

Code: Select all

  
/*
 * dht.c:
 * Read temperature and humidity from DHT11 or DHT22 sensor on a Orange/Raspberry PI and put the value's into Domoticz every 3 minutes.
 *
 * Customize the DHT_PIN and Domoticz IDX below, make a dummy temp/hum in Domoticz.
 * Console output is default off, silent in console output, enable below.
 * Its seems normal that you see "Data not good, skip" a few times, if enabled below.
 * IP address is set to 127.0.0.1 change below.
 *
 *
 * For compiling use   : cd /root/scripts/gpio/ ; gcc -Wall -o dht dht.c -lwiringPi
 * For console use     : /root/scripts/gpio/dht
 * For background use  : /root/scripts/gpio/dht &
 *
 * More info : http://www.uugear.com/portfolio/read-dht1122-temperature-humidity-sensor-from-raspberry-pi/
 *
 * Updated : 04-03-2019 by ILoveIoT.
 *
 */

#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#define MAX_TIMINGS     85



// gpio readall BCM10 |  wPi24 |  GPIO.18 | ALT3 | 0 | Physical 35 |
#define DHT_PIN 18      /* GPIO-18 */

// Set the Domoticz IDX from the dummy device (temp/hum) you created
#define DOM_IDX 3       /* Domoticz IDX 3 */



int data[5] = { 0, 0, 0, 0, 0 };

void read_dht_data()
{
        uint8_t laststate       = HIGH;
        uint8_t counter         = 0;
        uint8_t j                       = 0, i;

        data[0] = data[1] = data[2] = data[3] = data[4] = 0;

        /* pull pin down for 18 milliseconds */
        pinMode( DHT_PIN, OUTPUT );
        digitalWrite( DHT_PIN, LOW );
        delay( 30 );

        /* prepare to read the pin */
        pinMode( DHT_PIN, INPUT );

        /* detect change and read data */
        for ( i = 0; i < MAX_TIMINGS; i++ )
        {
                counter = 0;
                while ( digitalRead( DHT_PIN ) == laststate )
                {
                        counter++;
                        delayMicroseconds( 2 );
                        if ( counter == 255 )
                        {
                                break;
                        }
                }
                laststate = digitalRead( DHT_PIN );

                if ( counter == 255 )
                        break;

                /* ignore first 3 transitions */
                if ( (i >= 4) && (i % 2 == 0) )
                {
                        /* shove each bit into the storage bytes */
                        data[j / 8] <<= 1;
                        if ( counter > 16 )
                                data[j / 8] |= 1;
                        j++;
            }
        }

        /*
         * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte
         * print it out if data is good
         */
        if ( (j >= 40) &&
             (data[4] == ( (data[0] + data[1] + data[2] + data[3]) & 0xFF) ) )
        {
                float h = (float)((data[0] << 8) + data[1]) / 10;
                if ( h > 100 )
                {
                        h = data[0];    // for DHT11
                }
                float c = (float)(((data[2] & 0x7F) << 8) + data[3]) / 10;
                if ( c > 125 )
                {
                        c = data[2];    // for DHT11
                }
                if ( data[2] & 0x80 )
                {
                        c = -c;
                }

                // For console temp & hum readings uncomment these 2 lines
                //float f = c * 1.8f + 32;
                //printf( "Humidity = %.1f %% Temperature = %.1f *C (%.1f *F)\n", h, c, f );


                // Making the string with sensor data for Domoticz
                char str1[] = "/bin/bash -c 'curl -i -s \"http://192.168.1.209:8080/json.htm?type=command&param=udevice&idx=3";

                // Put variable c (Value celsius) into a string
                char str2[25]; //size of the number
                sprintf(str2, "%g", c);

                // Some comma separated value's in between
                char str3[] = ";";

                // Put variable h (Value humidity) into a string
 }

        /*
         * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte
         * print it out if data is good
         */
        if ( (j >= 40) &&
             (data[4] == ( (data[0] + data[1] + data[2] + data[3]) & 0xFF) ) )
        {
                float h = (float)((data[0] << 8) + data[1]) / 10;
                if ( h > 100 )
                {
                        h = data[0];    // for DHT11
                }
                float c = (float)(((data[2] & 0x7F) << 8) + data[3]) / 10;
                if ( c > 125 )
                {
                        c = data[2];    // for DHT11
                }
                if ( data[2] & 0x80 )
                {
                        c = -c;
                }

                // For console temp & hum readings uncomment these 2 lines
                //float f = c * 1.8f + 32;
                //printf( "Humidity = %.1f %% Temperature = %.1f *C (%.1f *F)\n", h, c, f );


                // Making the string with sensor data for Domoticz
                char str1[] = "/bin/bash -c 'curl -i -s \"http://192.168.1.209:8080/json.htm?type=command&param=udevice&idx=3";

                // Put variable c (Value celsius) into a string
                char str2[25]; //size of the number
                sprintf(str2, "%g", c);

                // Some comma separated value's in between
                char str3[] = ";";

                // Put variable h (Value humidity) into a string
                char str4[25]; //size of the number
                sprintf(str4, "%g", h);

                // And the final end string
                char str5[] = ";0\"' > /dev/null 2>&1";

                // Setting the domoticz IDX var from above
                char str6[25]; //size of the number
                sprintf(str6, "%i", DOM_IDX);
                char str7[] = "&";
                char str8[] = "nvalue=0&svalue=";

                // Concentrate all the str1/str8 and resulting in 1 string is stored in str1.
                strcat(str6,str7);
                strcat(str6,str8);
                strcat(str1,str6);
                strcat(str2,str3);
                strcat(str2,str4);
                strcat(str2,str5);
                strcat(str1,str2);

                // If you wanna view the output of the Domoticz string on console
                //puts(str1);

                // Case of invalid celsius temps, ignore more then +80 or -40 or 0, and recheck in 3sec
                if ( c > -40 && c < 80 && c != 0 )
                {
                        // Send the string/data to Domoticz server
                        system(str1);

                        //delay( 2000 ); /* wait 2 seconds before next read */
                        //delay( 300000 ); /* wait 5 minutes before next read */
                        delay( 180000 ); /* wait 3 minutes before next read */

                } else {
                        delay( 3000 ); /* wait 3 seconds before next try */
                }



        } else {

              sprintf(str4, "%g", h);

                // And the final end string
                char str5[] = ";0\"' > /dev/null 2>&1";

                // Setting the domoticz IDX var from above
                char str6[25]; //size of the number
                sprintf(str6, "%i", DOM_IDX);
                char str7[] = "&";
                char str8[] = "nvalue=0&svalue=";

                // Concentrate all the str1/str8 and resulting in 1 string is stored in str1.
                strcat(str6,str7);
                strcat(str6,str8);
                strcat(str1,str6);
                strcat(str2,str3);
                strcat(str2,str4);
                strcat(str2,str5);
                strcat(str1,str2);

                // If you wanna view the output of the Domoticz string on console
                //puts(str1);

                // Case of invalid celsius temps, ignore more then +80 or -40 or 0, and recheck in 3sec
                if ( c > -40 && c < 80 && c != 0 )
                {
                        // Send the string/data to Domoticz server
                        system(str1);

                        //delay( 2000 ); /* wait 2 seconds before next read */
                        //delay( 300000 ); /* wait 5 minutes before next read */
                        delay( 180000 ); /* wait 3 minutes before next read */

                } else {
                        delay( 3000 ); /* wait 3 seconds before next try */
                }



        } else {
                // Uncomment this line below if you dont see any data coming
                //printf( "Data not good, skip\n" );
        }
}

int main( void )
{
        //printf( "Orange/Raspberry PI DHT11/DHT22 temperature/humidity test\n" );

        if ( wiringPiSetup() == -1 )
                exit( 1 );

        while ( 1 )
        {
                read_dht_data();
                delay( 5000 ); /* wait 5 seconds before next try */
        }

        return(0);
}
What have i done wrongly?

When i run the python code i can get the reading only once and that is instantly shown in webinterface of Domoticz, but the script stops and the temperature is not updating anymore.
How can i loop the python code?
this is the python code that works only once

Code: Select all

#!/usr/bin/python
# -*- coding: latin-1 -*-

# basé sur le script Adafruit et adapté pour Domoticz



# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
import sys
import Adafruit_DHT
from requests.auth import HTTPBasicAuth
import requests


############# Parametres #################################

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# les parametres de Domoticz
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

domoticz_ip='192.168.1.209'
domoticz_port='8080'
user=''
password=''
domoticz_idx=3


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# les parametres du DHT
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#sensor est 11,22,ou 2302
# pin est le numero d la pin que vous avez cablée

sensor=22
pin=18

############# Fin des parametres #################################


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# le fomat pour la temp hum est celui ci
#/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT


def maj_widget(val_url):
    requete='http://'+domoticz_ip+':'+domoticz_port+val_url
    #print requete
    r=requests.get(requete,auth=HTTPBasicAuth(user,password))
    if  r.status_code != 200:
          print "Erreur API Domoticz"



humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

if humidity is not None and temperature is not None:

    print('Temp={0:0.1f}*  Humidity={1:0.1f}%'.format(temperature, humidity))
    # l URL Domoticz pour le widget virtuel
domoticz_ip='192.168.1.209'
domoticz_port='8080'
user=''
password=''
domoticz_idx=3


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# les parametres du DHT
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#sensor est 11,22,ou 2302
# pin est le numero d la pin que vous avez cablée

sensor=22
pin=18

############# Fin des parametres #################################


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# le fomat pour la temp hum est celui ci
#/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT


def maj_widget(val_url):
    requete='http://'+domoticz_ip+':'+domoticz_port+val_url
    #print requete
    r=requests.get(requete,auth=HTTPBasicAuth(user,password))
    if  r.status_code != 200:
          print "Erreur API Domoticz"



humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

if humidity is not None and temperature is not None:

    print('Temp={0:0.1f}*  Humidity={1:0.1f}%'.format(temperature, humidity))
    # l URL Domoticz pour le widget virtuel
    url='/json.htm?type=command&param=udevice&idx='+str(domoticz_idx)
    url+='&nvalue=0&svalue='
    url+=str('{0:0.1f};{1:0.1f};2').format(temperature, humidity)
    #print url
    maj_widget(url)

else:
    print('Probleme avec la lecture du DHT. Try again!')
    sys.exit(1)
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: DHT22 sensor value's into Domoticz

Post by ILoveIOT »

// For console temp & hum readings uncomment these 2 lines
float f = c * 1.8f + 32;
printf( "Humidity = %.1f %% Temperature = %.1f *C (%.1f *F)\n", h, c, f );

// Uncomment this line below if you dont see any data coming
printf( "Data not good, skip\n" );

// If you wanna view the output of the Domoticz string on console
puts(str1);

printf( "Orange/Raspberry PI DHT11/DHT22 temperature/humidity test\n" );

Did you do ?
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
Freelance
Posts: 10
Joined: Wednesday 07 October 2020 12:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DHT22 sensor value's into Domoticz

Post by Freelance »

Thanks for taking your time to help me.
I did uncomment now and i can run the script but get no temperature data, only results shown is "Orange/Raspberry PI DHT11/DHT22 temperature/humidity test"
The sensor is working with the py script

this is what i use from your code:

Code: Select all

/*
 * dht.c:
 * Read temperature and humidity from DHT11 or DHT22 sensor on a Orange/Raspberry PI and put the value's into Domoticz every 3 minutes.
 *
 * Customize the DHT_PIN and Domoticz IDX below, make a dummy temp/hum in Domoticz.
 * Console output is default off, silent in console output, enable below.
 * Its seems normal that you see "Data not good, skip" a few times, if enabled below.
 * IP address is set to 127.0.0.1 change below.
 *
 *
 * For compiling use   : cd /root/scripts/gpio/ ; gcc -Wall -o dht dht.c -lwiringPi
 * For console use     : /root/scripts/gpio/dht
 * For background use  : /root/scripts/gpio/dht &
 *
 * More info : http://www.uugear.com/portfolio/read-dht1122-temperature-humidity-sensor-from-raspberry-pi/
 *
 * Updated : 04-03-2019 by ILoveIoT.
 *
 */

#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#define MAX_TIMINGS     85



//gpio readall BCM10 |  wPi24 |  GPIO.18 | ALT3 | 0 | Physical 35 |
#define DHT_PIN 18      /* GPIO-18 */

// Set the Domoticz IDX from the dummy device (temp/hum) you created
#define DOM_IDX 3       /* Domoticz IDX 3 */



int data[5] = { 0, 0, 0, 0, 0 };

void read_dht_data()
{
        uint8_t laststate       = HIGH;
        uint8_t counter         = 0;
        uint8_t j                       = 0, i;

        data[0] = data[1] = data[2] = data[3] = data[4] = 0;

        /* pull pin down for 18 milliseconds */
        pinMode( DHT_PIN, OUTPUT );
        digitalWrite( DHT_PIN, LOW );
        delay( 30 );

        /* prepare to read the pin */
        pinMode( DHT_PIN, INPUT );

        /* detect change and read data */
        for ( i = 0; i < MAX_TIMINGS; i++ )
        {
                counter = 0;
                while ( digitalRead( DHT_PIN ) == laststate )
                {
                        counter++;
                        delayMicroseconds( 2 );
                        if ( counter == 255 )
                        {
                                break;
                        }
                }
                laststate = digitalRead( DHT_PIN );

                if ( counter == 255 )
                        break;

                /* ignore first 3 transitions */
                if ( (i >= 4) && (i % 2 == 0) )
                {
                        /* shove each bit into the storage bytes */
                        data[j / 8] <<= 1;
                        if ( counter > 16 )
                                data[j / 8] |= 1;
                        j++;
 uint8_t laststate       = HIGH;
        uint8_t counter         = 0;
        uint8_t j                       = 0, i;

        data[0] = data[1] = data[2] = data[3] = data[4] = 0;

        /* pull pin down for 18 milliseconds */
        pinMode( DHT_PIN, OUTPUT );
        digitalWrite( DHT_PIN, LOW );
        delay( 30 );

        /* prepare to read the pin */
        pinMode( DHT_PIN, INPUT );

        /* detect change and read data */
        for ( i = 0; i < MAX_TIMINGS; i++ )
        {
                counter = 0;
                while ( digitalRead( DHT_PIN ) == laststate )
                {
                        counter++;
                        delayMicroseconds( 2 );
                        if ( counter == 255 )
                        {
                                break;
                        }
                }
                laststate = digitalRead( DHT_PIN );

                if ( counter == 255 )
                        break;

                /* ignore first 3 transitions */
                if ( (i >= 4) && (i % 2 == 0) )
                {
                        /* shove each bit into the storage bytes */
                        data[j / 8] <<= 1;
                        if ( counter > 16 )
                                data[j / 8] |= 1;
                        j++;
                }
        }

        /*
         * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte
         * print it out if data is good
         */
        if ( (j >= 40) &&
             (data[4] == ( (data[0] + data[1] + data[2] + data[3]) & 0xFF) ) )
        {
                float h = (float)((data[0] << 8) + data[1]) / 10;
                if ( h > 100 )
                {
                        h = data[0];    // for DHT11
                }
                float c = (float)(((data[2] & 0x7F) << 8) + data[3]) / 10;
                if ( c > 125 )
                {
                        c = data[2];    // for DHT11
                }
                if ( data[2] & 0x80 )
                {
                        c = -c;
                }

                // For console temp & hum readings uncomment these 2 lines
                float f = c * 1.8f + 32;
                printf( "Humidity = %.1f %% Temperature = %.1f *C (%.1f *F)\n", h, c, f );


                // Making the string with sensor data for Domoticz
                char str1[] = "/bin/bash -c 'curl -i -s \"http://192.168.1.209:8080/json.htm?type=command&param=udevice&idx=3";

                // Put variable c (Value celsius) into a string
                char str2[25]; //size of the number
                sprintf(str2, "%g", c);

                // Some comma separated value's in between
                char str3[] = ";";

                // Put variable h (Value humidity) into a string

}

        /*
         * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte
         * print it out if data is good
         */
        if ( (j >= 40) &&
             (data[4] == ( (data[0] + data[1] + data[2] + data[3]) & 0xFF) ) )
        {
                float h = (float)((data[0] << 8) + data[1]) / 10;
                if ( h > 100 )
                {
                        h = data[0];    // for DHT11
                }
                float c = (float)(((data[2] & 0x7F) << 8) + data[3]) / 10;
                if ( c > 125 )
                {
                        c = data[2];    // for DHT11
                }
                if ( data[2] & 0x80 )
                {
                        c = -c;
                }

                // For console temp & hum readings uncomment these 2 lines
                float f = c * 1.8f + 32;
                printf( "Humidity = %.1f %% Temperature = %.1f *C (%.1f *F)\n", h, c, f );


                // Making the string with sensor data for Domoticz
                char str1[] = "/bin/bash -c 'curl -i -s \"http://192.168.1.209:8080/json.htm?type=command&param=udevice&idx=3";

                // Put variable c (Value celsius) into a string
                char str2[25]; //size of the number
                sprintf(str2, "%g", c);

                // Some comma separated value's in between
                char str3[] = ";";

                // Put variable h (Value humidity) into a string
                char str4[25]; //size of the number
                sprintf(str4, "%g", h);

                // And the final end string
                char str5[] = ";0\"' > /dev/null 2>&1";

                // Setting the domoticz IDX var from above
                char str6[25]; //size of the number
                sprintf(str6, "%i", DOM_IDX);
                char str7[] = "&";
                char str8[] = "nvalue=0&svalue=";

                // Concentrate all the str1/str8 and resulting in 1 string is stored in str1.
                strcat(str6,str7);
                strcat(str6,str8);
                strcat(str1,str6);
                strcat(str2,str3);
                strcat(str2,str4);
                strcat(str2,str5);
                strcat(str1,str2);

                // If you wanna view the output of the Domoticz string on console
                puts(str1);

                // Case of invalid celsius temps, ignore more then +80 or -40 or 0, and recheck in 3sec
                if ( c > -40 && c < 80 && c != 0 )
                {
                        // Send the string/data to Domoticz server
                        system(str1);

                        //delay( 2000 ); /* wait 2 seconds before next read */
                        //delay( 300000 ); /* wait 5 minutes before next read */
                        delay( 180000 ); /* wait 3 minutes before next read */

                } else {
                        delay( 3000 ); /* wait 3 seconds before next try */
                }



        } else {
              sprintf(str4, "%g", h);

                // And the final end string
                char str5[] = ";0\"' > /dev/null 2>&1";

                // Setting the domoticz IDX var from above
                char str6[25]; //size of the number
                sprintf(str6, "%i", DOM_IDX);
                char str7[] = "&";
                char str8[] = "nvalue=0&svalue=";

                // Concentrate all the str1/str8 and resulting in 1 string is stored in str1.
                strcat(str6,str7);
                strcat(str6,str8);
                strcat(str1,str6);
                strcat(str2,str3);
                strcat(str2,str4);
                strcat(str2,str5);
                strcat(str1,str2);

                // If you wanna view the output of the Domoticz string on console
                puts(str1);

                // Case of invalid celsius temps, ignore more then +80 or -40 or 0, and recheck in 3sec
                if ( c > -40 && c < 80 && c != 0 )
                {
                        // Send the string/data to Domoticz server
                        system(str1);

                        //delay( 2000 ); /* wait 2 seconds before next read */
                        //delay( 300000 ); /* wait 5 minutes before next read */
                        delay( 180000 ); /* wait 3 minutes before next read */

                } else {
                        delay( 3000 ); /* wait 3 seconds before next try */
                }



        } else {
                // Uncomment this line below if you dont see any data coming
                //printf( "Data not good, skip\n" );
        }
}

int main( void )
{
        printf( "Orange/Raspberry PI DHT11/DHT22 temperature/humidity test\n" );

        if ( wiringPiSetup() == -1 )
                exit( 1 );

        while ( 1 )
        {
                read_dht_data();
                delay( 5000 ); /* wait 5 seconds before next try */
        }

        return(0);
}
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: DHT22 sensor value's into Domoticz

Post by ILoveIOT »

//printf( "Data not good, skip\n" );

But you're data is not good I guess, you sure you're using a GPIO port ? the right port ?

what show's ? : gpio readall

Mine

Code: Select all

gpio readall
 +-----+-----+----------+------+---+-Orange Pi+---+---+------+---------+-----+--+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 |     |     |     3.3v |      |   |  1 || 2  |   |      | 5v       |     |     |
 |  12 |   8 |    SDA.0 | ALT5 | 0 |  3 || 4  |   |      | 5V       |     |     |
 |  11 |   9 |    SCL.0 | ALT5 | 0 |  5 || 6  |   |      | 0v       |     |     |
 |   6 |   7 |   GPIO.7 | ALT3 | 0 |  7 || 8  | 0 | ALT3 | TxD3     | 15  | 13  |
 |     |     |       0v |      |   |  9 || 10 | 0 | ALT3 | RxD3     | 16  | 14  |
 |   1 |   0 |     RxD2 | ALT3 | 0 | 11 || 12 | 1 | IN   | GPIO.1   | 1   | 110 |
 |   0 |   2 |     TxD2 | ALT3 | 0 | 13 || 14 |   |      | 0v       |     |     |
 |   3 |   3 |     CTS2 | ALT3 | 0 | 15 || 16 | 0 | ALT3 | GPIO.4   | 4   | 68  |
 |     |     |     3.3v |      |   | 17 || 18 | 0 | ALT3 | GPIO.5   | 5   | 71  |
 |  64 |  12 |     MOSI | ALT3 | 0 | 19 || 20 |   |      | 0v       |     |     |
 |  65 |  13 |     MISO | ALT3 | 0 | 21 || 22 | 0 | ALT3 | RTS2     | 6   | 2   |
 |  66 |  14 |     SCLK | ALT3 | 0 | 23 || 24 | 0 | ALT3 | CE0      | 10  | 67  |
 |     |     |       0v |      |   | 25 || 26 | 1 | ALT2 | GPIO.11  | 11  | 21  |
 |  19 |  30 |    SDA.1 | ALT4 | 0 | 27 || 28 | 0 | ALT4 | SCL.1    | 31  | 18  |
 |   7 |  21 |  GPIO.21 | ALT2 | 1 | 29 || 30 |   |      | 0v       |     |     |
 |   8 |  22 |  GPIO.22 |  OUT | 0 | 31 || 32 | 0 | ALT3 | RTS1     | 26  | 200 |
 |   9 |  23 |  GPIO.23 |   IN | 1 | 33 || 34 |   |      | 0v       |     |     |
 |  10 |  24 |  GPIO.24 |   IN | 1 | 35 || 36 | 0 | ALT3 | CTS1     | 27  | 201 |
 |  20 |  25 |  GPIO.25 |   IN | 1 | 37 || 38 | 0 | ALT3 | TxD1     | 28  | 198 |
 |     |     |       0v |      |   | 39 || 40 | 0 | ALT3 | RxD1     | 29  | 199 |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+-Orange Pi+---+------+----------+-----+-----+
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: DHT22 sensor value's into Domoticz

Post by ILoveIOT »

Some readings are not working, its normal, now he tries 3sec later, maybe the first 3-4 readings are wrong, then you get the value's
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
Freelance
Posts: 10
Joined: Wednesday 07 October 2020 12:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DHT22 sensor value's into Domoticz

Post by Freelance »

Thanks, below the results from the gpio readall

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ gpio readall
 +-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 0 | IN   | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | IN   | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 1 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+
I use GPIO 18 which is Pin 12

The below code from python gives correct readings so the sensor is working, i can get Domoticz to read below code but it only does so once, it does not update constantly

Code: Select all

#!/usr/bin/python
# -*- coding: latin-1 -*-

# basé sur le script Adafruit et adapté pour Domoticz



# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
import sys
import Adafruit_DHT
from requests.auth import HTTPBasicAuth
import requests


############# Parametres #################################

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# les parametres de Domoticz
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

domoticz_ip='192.168.1.209'
domoticz_port='8080'
user=''
password=''
domoticz_idx=3


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# les parametres du DHT
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#sensor est 11,22,ou 2302
# pin est le numero d la pin que vous avez cablée

sensor=22
pin=18

############# Fin des parametres #################################


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# le fomat pour la temp hum est celui ci
#/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT


def maj_widget(val_url):
    requete='http://'+domoticz_ip+':'+domoticz_port+val_url
    #print requete
    r=requests.get(requete,auth=HTTPBasicAuth(user,password))
    if  r.status_code != 200:
          print "Erreur API Domoticz"



humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

if humidity is not None and temperature is not None:

    print('Temp={0:0.1f}*  Humidity={1:0.1f}%'.format(temperature, humidity))
    # l URL Domoticz pour le widget virtuel
domoticz_ip='192.168.1.209'
domoticz_port='8080'
user=''
password=''
domoticz_idx=3


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# les parametres du DHT
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#sensor est 11,22,ou 2302
# pin est le numero d la pin que vous avez cablée

sensor=22
pin=18

############# Fin des parametres #################################


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# le fomat pour la temp hum est celui ci
#/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT


def maj_widget(val_url):
    requete='http://'+domoticz_ip+':'+domoticz_port+val_url
    #print requete
    r=requests.get(requete,auth=HTTPBasicAuth(user,password))
    if  r.status_code != 200:
          print "Erreur API Domoticz"



humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

if humidity is not None and temperature is not None:

    print('Temp={0:0.1f}*  Humidity={1:0.1f}%'.format(temperature, humidity))
    # l URL Domoticz pour le widget virtuel
    url='/json.htm?type=command&param=udevice&idx='+str(domoticz_idx)
    url+='&nvalue=0&svalue='
    url+=str('{0:0.1f};{1:0.1f};2').format(temperature, humidity)
    #print url
    maj_widget(url)

else:
    print('Probleme avec la lecture du DHT. Try again!')
    sys.exit(1)
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: DHT22 sensor value's into Domoticz

Post by ILoveIOT »

For me

//gpio readall BCM10 | wPi24 | GPIO.18 | ALT3 | 0 | Physical 35 |
#define DHT_PIN 18 /* GPIO-18 */

For you

Physical | V | Mode | Name | wPi | BCM |
| 12 | 1 | IN | GPIO. 1 | 1 | 18 |

#define DHT_PIN 1 /* GPIO-1 */

So 1 ?

Pls don't post Python code here ;)
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
Freelance
Posts: 10
Joined: Wednesday 07 October 2020 12:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DHT22 sensor value's into Domoticz

Post by Freelance »

Thank you so much and apologize for the python stuff.

I got the readings but I'm missing the link to Domoticz, see below.
my IDX = 3
is there something wrong on the json line?

Orange/Raspberry PI DHT11/DHT22 temperature/humidity test
Humidity = 84.6 % Temperature = 16.6 *C (61.9 *F)
/bin/bash -c 'curl -i -s "http://192.168.1.209:8080/json.htm?type ... 6.6;84.6;0"' > /dev/null 2>&1
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: DHT22 sensor value's into Domoticz

Post by ILoveIOT »

Hehe, no worries (just hate python) I see IDX 33 in the link ? ;)
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: DHT22 sensor value's into Domoticz

Post by ILoveIOT »

you got

:8080/json.htm?type=command&param=udevice&idx=3

should be

:8080/json.htm?type=command&param=udevice&idx=
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
Freelance
Posts: 10
Joined: Wednesday 07 October 2020 12:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DHT22 sensor value's into Domoticz

Post by Freelance »

ILoveIOT wrote: Wednesday 07 October 2020 17:20 Hehe, no worries (just hate python) I see IDX 33 in the link ? ;)
OMG i was defining the IDX = 3 and also adding the 3 in the URL line not understanding that the first 3 will be added there... :oops: :oops: :oops:


Confirming, all works perfectly, I've learned a lot so i hope not to do the same mistakes again.
Thanks for your great support! I'll be making a small donation when i get the relay operating by the sensor.
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: DHT22 sensor value's into Domoticz

Post by ILoveIOT »

I've learned a lot so i hope not to do the same mistakes again.
Hehe you're welcome, now you are a C programmer :lol:
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: DHT22 sensor value's into Domoticz

Post by ILoveIOT »

Code: Select all

I'll be making a small donation when i get the relay operating by the sensor.
Lol,..whut..what, somebody get paid for this ? :lol: :lol:
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
Freelance
Posts: 10
Joined: Wednesday 07 October 2020 12:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DHT22 sensor value's into Domoticz

Post by Freelance »

There as "donate" button on the domoticz main page :)
Once i get everything working "for free" it's only fair to donate some symbolic amount to the developers, i was hoping you are part of the team :)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests