<?php
//================ Config ===========================
//Replace your DS18B20 serial here!
$SENSORID = "28-041635d60cff";

//Set the emoncms API Key, the Hostname or IP and the  internal Sensor ID (Numeric only)
$EmonCMSApiKey = "*********************************";
$EmonCMSHost = "192.168.178.41";//<a href="/wp-content/uploads/2014/12/temperatur.php_.txt">temperatur.php</a>
$ecmsSENSORID = "1";
//==================================================

//BuildSensor Path
$SensorPath = '/sys/bus/w1/devices/'. $SENSORID .'/w1_slave';

// Open resource file for thermometer
$thermometer = fopen($SensorPath, "r");

// Get the contents of the resource
$thermometerReadings = fread($thermometer, filesize($SensorPath));

//print $thermometerReadings;
// Close resource file for thermometer
fclose($thermometer);
// We're only interested in the 2nd line, and the value after the t= on the 2nd line
preg_match("/t=(.+)/", preg_split("/\n/", $thermometerReadings)[1], $matches);
//print $matches[1];
$temperature = $matches[1];
//print $temperature;

//Write to emoncms - Example
// You may want to add other parsed values
$http = 'http://';

$url = $http . $EmonCMSHost . '/emoncms/input/post?node=' . $ecmsSENSORID . '&csv=' . $temperature .'&apikey=' . $EmonCMSApiKey;
print $url;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch);
?>
1 Like