OhThere as "donate" button on the domoticz main page


I guess $ will helps too, Domoticz is a nice product that I support where I can !! (I'am not part of the team)
Moderator: leecollings
OhThere as "donate" button on the domoticz main page
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 4 /* GPIO-4 */
// Set the Domoticz IDX from the dummy device (temp/hum) you created
#define DOM_IDX 19 /* Domoticz IDX 19 */
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.0.101:8080/json.htm?type=command¶m=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);
}
Figured it out with the french script! Everything is working now, with an update of the temp/hum every 10 minutefabry91 wrote: ↑Thursday 24 December 2020 20:36 Hello,
I'm trying to get it work but I think I'm losing something, I compiled the script as described:
I tested with the script https://easydomoticz.com/dht-11-22-rasp ... che-enfin/ running "sudo python name.py" I get the temperature/humidity.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 4 /* GPIO-4 */ // Set the Domoticz IDX from the dummy device (temp/hum) you created #define DOM_IDX 19 /* Domoticz IDX 19 */ 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.0.101:8080/json.htm?type=command¶m=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); }
When I try to run your script I get the error: What I am doing wrong?![]()
Users browsing this forum: No registered users and 0 guests