Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/10/2007, 14:11
robandrox
 
Fecha de Ingreso: abril-2005
Mensajes: 287
Antigüedad: 19 años, 1 mes
Puntos: 0
No encuentro el error

Hola a todos,

me he bajado un ejemplo de internet que necesito hacer funcionar,pero no se donde está el error.¿Alguien me puede decir donde está??Muchas gracias


<html>
<head>
<title>Linknx</title>
</head>
<body>
<?php

function knxread($fp, $name)
{
$in = "<read><object id='$name'/></read>\n\4";

fwrite($fp, $in);

$ret = '';
$cnt = 0;
while ($cnt < 4 && $fp && !feof($fp)) {
$ret .= fgets($fp, 128);
$c = fgetc($fp);
if ($c == "\4") {
if (ereg ("<read status='success'>([^<]+)</read>", $ret,$regs))
$ret = $regs[1];
break;
}
$ret .= $c;
$cnt++;
}
return $ret;
}

function knxwrite($fp, $name, $value)
{
$in = "<write><object id='$name' value='$value'/></write>\n\4";

fwrite($fp, $in);

$ret = '';
$cnt = 0;
while ($cnt < 4 && $fp && !feof($fp)) {
$ret .= fgets($fp, 128);
$c = fgetc($fp);
if ($c == "\4") {
if (ereg ("<write status='success'", $ret))
return 1;
break;
}
$ret .= $c;
$cnt++;
}
return 0;
}

function switching($fp, $name, $gad) {
print("<tr><td>$name</td><td>");
if (knxread($fp, $gad) != 0)
print("On</td><td><a href='index.php?action=Off&gad=$gad'>Turn Off</a>");
else
print("Off</td><td><a href='index.php?action=On&gad=$gad'>Turn On</a>");
print("</td></tr>\n");
}

function switching_status($fp, $name, $gad) {
if (knxread($fp, $gad) != 0)
print("<tr><td>$name</td><td>On</td></tr>\n");
else
print("<tr><td>$name</td><td>Off</td></tr>\n");
}

function heating($fp, $name, $id) {
print("<tr><td>$name</td><td>");
$val = knxread($fp, 'heating_'.$id);
print(knxread($fp, 'temp_'.$id).'</td><td>'.$val.' ('.knxread($fp, 'setpoint_'.$id).")</td>\n");
print ("<td><a href='index.php?action=comfort&gad=heating_$id'>C</a> <a href='index.php?action=standby&gad=heating_$id'>S</a> <a href='index.php?action=night&gad=heating_$id'>N</a> <a href='index.php?action=frost&gad=heating_$id'>F</a></td></tr>\n");
}

$address = "127.0.0.1";
$port = 1028;


$fp = fsockopen($address, $port, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
}
else {

if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
$gad = $_REQUEST['gad'];
if ($action == 'On') {
knxwrite($fp, $gad, 1);
}
elseif ($action == 'Off') {
knxwrite($fp, $gad, 0);
}
elseif ($action == 'comfort') {
knxwrite($fp, $gad, $action);
}
elseif ($action == 'standby') {
knxwrite($fp, $gad, $action);
}
elseif ($action == 'night') {
knxwrite($fp, $gad, $action);
}
elseif ($action == 'frost') {
knxwrite($fp, $gad, $action);
}
}

print("<h2>Lighting</h2>\n<table border=1>\n");

switching($fp, "Living room", "light_living");
switching($fp, "Dining room", "light_dining");
switching($fp, "Bedroom 2", "light_room2");
switching($fp, "Floor", "light_floor");
switching($fp, "Stair", "light_stair");
switching($fp, "Office", "light_office");
switching($fp, "Bedroom 1", "light_room1");
switching($fp, "Toilet 1", "light_toilet1");
switching($fp, "Kitchen", "light_kitchen");
switching($fp, "Toilet 0", "light_toilet0");

print("</table>\n<h2>Heating</h2>\n<table border=1>\n");

heating($fp, "Office", "office");
heating($fp, "Living room", "living");
heating($fp, "Bedroom 1", "room1");
heating($fp, "Bedroom 2", "room2");
heating($fp, "Kitchen", "kitchen");

switching($fp, "Bathroom", "heating_bath");
switching_status($fp, "Burner status", "burner");

print("</table>\n<h2>Other</h2>\n<table border=1>\n");

switching($fp, "Warm water circulator ", "circulator");
switching($fp, "Auto heating mode", "heating_auto");
switching($fp, "Alarm clock", "wakeup_active");
switching($fp, "Alarm active", "alarm_active");
switching($fp, "Intrusion", "intrusion");

print("</table>\n");

fclose($fp);
}
?>

</body>
</html>

Un saludo

Última edición por robandrox; 19/10/2007 a las 14:21