@WereCatf Ok it works more or less now xd But now it says "Unable to read sensor, check the wiring, pin number!"
Code:
<?php
$result = get_dht_values(6, "DHT22"); // change the pin number and DHT type accordingly
$message = $result[0];
$temp = $result[1];
$humidity = $result[2];
if( $message == "success" ) {
// if successful, happy days let's spill the data out
echo "<p>The current temperature is <b>" . $temp . "Ā°C</b> and the humidity is . <b>" . $humidity . "%</b>" ;
} else {
echo "Error: " . $message;
}
function get_dht_values($pin, $dht_type) {
if( ( $dht_type != "DHT22" ) && ( $dht_type != "DHT22" ) ) {
return array("Invalid DHT Type", 0, 0);
}
// Run the command using the exec() function, delivers the output in $output
exec("/root/checkHumidity/bin/checkHumidity $pin $dht_type 2>&1", $output, $return);
// -255 = bad
if( $output[0] == "-255.000000" ) {
return array("Unable to read sensor, check the wiring, pin number!", 0, 0);
}
// must be all good, lets return the data
$output[0] = number_format( (float)$output[0], 2, '.', '' ); // temp
$output[1] = number_format( (float)$output[1], 2, '.', '' ); // hum
return array( "success", $output[0], $output[1] );
}
The Sensor is connected to PIN 6 on the OMEGA 2