Onewire/Example/PHP (Deutsch)

From Ethersex Wiki

Jump to: navigation, search

Language


English – Deutsch – Nederlands – Français – Español – Italiano

<html>
 
<head>
	<title>ethersex php example</title>
</head>
 
<body>
 
<?php
 
define(IP, '192.168.10.9'); // deine ethersex ip adresse
define(PORT, 2701); // standard port im image
 
request("1w convert");
 
$response = request("1w list");
$explode = explode("\n", $response);
 
for ($i=0; $i < count($explode)-2; $i++) {
	echo "Sensor: " . trim($explode[$i]);
	echo " -- Wert: " . request("1w get " . $explode[$i]);
	echo "<br>\n";
}
 
function request($request) {
	$rs = fsockopen(IP, PORT);
 
	if (!$rs) {
		$response  = "Kann Verbindung nicht aufbauen!";
	}
	else {
		$response ="";
		$request = "!" . $request . "\r\n";
 
		fputs($rs, $request);
 
		while (!feof($rs)) {
			$response .= fgets($rs, 128);
		}
		fclose($rs);
	}
 
	return $response;
}
 
?>
 
</body>
Personal tools