Hallo,
ich lese mit php meine Siemens-LOGO-Steuerung über TCP/IP aus und stelle dann mit php/html die Daten visuell dar. Soweit funktioniert alles, nur wenn die Temperaturen in den negativen Bereich gehen, erscheinen die Werte im Zahlenbereich von 6550.5 statt -1,2°C. Hier werden wohl die Bytes für den analogen Merker verkehrt ausgelesen oder verkehrt zusammen gebaut. Ich bin mit meinem Latein am Ende und komme nicht weiter. Vielleicht kann mir von Euch einer sagen, wo der Fehler liegt.
Anbei der Programmcode:
So sieht das Ganze dann aus:
ich lese mit php meine Siemens-LOGO-Steuerung über TCP/IP aus und stelle dann mit php/html die Daten visuell dar. Soweit funktioniert alles, nur wenn die Temperaturen in den negativen Bereich gehen, erscheinen die Werte im Zahlenbereich von 6550.5 statt -1,2°C. Hier werden wohl die Bytes für den analogen Merker verkehrt ausgelesen oder verkehrt zusammen gebaut. Ich bin mit meinem Latein am Ende und komme nicht weiter. Vielleicht kann mir von Euch einer sagen, wo der Fehler liegt.
Anbei der Programmcode:
PHP-Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Visualisierung LOGO! 0BA7</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="refresh" content="30">
<meta name="robots" content="noindex, nofollow">
<meta name="description" content="Visualisierung einer Heizungssteuerung mit einer Siemens LOGO! 0BA7.">
<meta name="keywords" content="Homepage">
<meta name="language" content="de">
<link rel="stylesheet" type="text/css" media="screen, projection" href="stylesheet.css">
<link rel="shortcut icon" href="favicon.ico">
</head>
<?php
/*Bit´s Doku
BitNr. Funktion
64 I1..I8
65 I9..I16
66 I17..I24
67 Funktionstasten
68 Q1..Q8
69 Q9..Q16
70 M1..M8
71 M9..M16
72 M17..M24
73 M25..M27 .. ??
74 Schieberegister ??
75 C1..C4 ??
79 AI1
80 AI1
81 AI2
82 AI2
83 AI3
84 AI3
85 AI4
86 AI4
87 AI5
88 AI5
89 AI6
90 AI6
91 AI7
92 AI7
93 AI8
94 AI8
95 AQ1
96 AQ1
97 AQ2
98 AQ2
16 AMQ1
100 AMQ1
101 AMQ2
102 AMQ2
103 AMQ3
104 AMQ3
105 AMQ4
106 AMQ4
107 AMQ5
108 AMQ5
109 AMQ6
110 AMQ6
111 AMQ7
112 AMQ7
113 AMQ8
114 AMQ8
115 AMQ9
116 AMQ9
117 AMQ10
118 AMQ10
119 AMQ11
120 AMQ11
121 AMQ12
122 AMQ12
123 AMQ13
124 AMQ13
125 AMQ14
126 AMQ14
127 AMQ15
128 AMQ15
129 AMQ16
130 AMQ16
131 VM Flags
132 VM DB WORD
*/
//Server-Zeit
$timestamp = time();
date_default_timezone_set('Europe/Berlin');
$datum = date("d.m.Y");
$uhrzeit = date("H:i");
$tage = array("Sonntag","Montag","Dienstag",
"Mittwoch","Donnerstag","Freitag","Samstag");
$tag = date("w");
//Besucher online
include_once('users-online/online.php');
list($online, $record) = users_online();
error_reporting(E_ALL);
/* Die IP-Adresse und Port */
$address = "qnap.xxxxxxxxxx.de";
$service_port = "10001"; #Vorgegeben!!
#$an_logo = "\x55\x18\x18\xAA";# für Start
#$an_logo = "\x55\x12\x12\xAA";# für Stop
$an_logo = "\x55\x13\x13\x00\x00\xAA";#liest Logo Daten
/* Einen TCP/IP-Socket erzeugen. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false)
{
echo "socket_create() fehlgeschlagen: Grund: " . socket_strerror(socket_last_error()) . "\n";
}
else
{
#echo " OK socket create.\n";
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
echo "socket_connect() fehlgeschlagen.\nGrund: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
}
else
{
#echo " OK socket connect.\n";
}
/* Die Anfrage senden. */
$sent = socket_write($socket, $an_logo, strlen($an_logo));
if ($sent === false)
{
echo "socket_write) fehlgeschlagen.\nGrund: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
exit;
}
else
{
#echo " OK socket write.\n";
}
sleep(1);
/* Die Daren empfangen */
$buf="";
if (false !== ($bytes = socket_recv($socket, $buf, 500, MSG_DONTWAIT)))
{
#echo "$bytes bytes von socket_recv(). Schliesse Socket...\n";
socket_close($socket);
$ausgabe=preg_split('//',$buf,-1,PREG_SPLIT_NO_EMPTY) ;
// Hier gibt es die Möglichkeit die Rohdaten zu sehen
/* for ($i=1;$i<$bytes;$i++)
{
echo $i." = ".ord($ausgabe[$i])."\n";
}
*/
# LOGO muss als erstes "6" senden als Bestätigung das das angeforderte auch kommt
if (ord($ausgabe[0])!==6)
{
// exit("keine Daten EXIT, bzw. LOGO nicht online!\n");
echo "Keine Daten, bzw. LOGO ist nicht online!\n";
goto AA;
}
}
else
{
echo "socket_recv() schlug fehl; Grund: " . socket_strerror(socket_last_error($socket)) . "\n";
exit;
}
# Das Byte für die Ausgänge wird nach binär gewandelt und in Zustände mit 1 oder 0 für $Q1-$Q16 dargestellt
$Q1_8= array_reverse(str_split(str_pad(decbin(ord($ausgabe[68])),8,0,STR_PAD_LEFT)));
$Q9_16= array_reverse(str_split(str_pad(decbin(ord($ausgabe[69])),8,0,STR_PAD_LEFT)));
for ($i=0 ;$i <= 7;++$i)
{
$Q[$i+1]=$Q1_8[$i];
}
for ($i=0 ;$i <= 7 ;++$i)
{
$Q[$i+9]=$Q9_16[$i];
}
$Q1=$Q1_8[0];
$Q2=$Q1_8[1];
$Q3=$Q1_8[2];
$Q4=$Q1_8[3];
$Q5=$Q1_8[4];
$Q6=$Q1_8[5];
$Q7=$Q1_8[6];
$Q8=$Q1_8[7];
$Q9=$Q9_16[0];
$Q10=$Q9_16[1];
$Q11=$Q9_16[2];
$Q12=$Q9_16[3];
$Q13=$Q9_16[4];
$Q14=$Q9_16[5];
$Q15=$Q9_16[6];
$Q16=$Q9_16[7];
# Das Byte für die Eingänge wird nach binär gewandelt und in Zustände mit 1 oder 0 für $I1-$I24 dargestellt
$I1_8= array_reverse(str_split(str_pad(decbin(ord($ausgabe[64])),8,0,STR_PAD_LEFT)));
$I9_16= array_reverse(str_split(str_pad(decbin(ord($ausgabe[65])),8,0,STR_PAD_LEFT)));
$I17_24= array_reverse(str_split(str_pad(decbin(ord($ausgabe[66])),8,0,STR_PAD_LEFT)));
for ($i=0 ;$i <= 7;++$i)
{
$I[$i+1]=$I1_8[$i];
}
for ($i=0 ;$i <= 7 ;++$i)
{
$I[$i+9]=$I9_16[$i];
}
for ($i=0 ;$i <= 7 ;++$i)
{
$I[$i+17]=$I17_24[$i];
}
$I1=$I1_8[0];
$I2=$I1_8[1];
$I3=$I1_8[2];
$I4=$I1_8[3];
$I5=$I1_8[4];
$I6=$I1_8[5];
$I7=$I1_8[6];
$I8=$I1_8[7];
$I9=$I9_16[0];
$I10=$I9_16[1];
$I11=$I9_16[2];
$I12=$I9_16[3];
$I13=$I9_16[4];
$I14=$I9_16[5];
$I15=$I9_16[6];
$I16=$I9_16[7];
$I17=$I17_24[0];
$I18=$I17_24[1];
$I19=$I17_24[2];
$I20=$I17_24[3];
$I21=$I17_24[4];
$I22=$I17_24[5];
$I23=$I17_24[6];
$I24=$I17_24[7];
# Das Byte für die Merker wird nach binär gewandelt und in Zustände mit 1 oder 0 für $M1-$M24 dargestellt
$M1_8= array_reverse(str_split(str_pad(decbin(ord($ausgabe[70])),8,0,STR_PAD_LEFT)));
$M9_16= array_reverse(str_split(str_pad(decbin(ord($ausgabe[71])),8,0,STR_PAD_LEFT)));
$M17_24= array_reverse(str_split(str_pad(decbin(ord($ausgabe[72])),8,0,STR_PAD_LEFT)));
for ($i=0 ;$i <= 7;++$i)
{
$M[$i+1]=$M1_8[$i];
}
for ($i=0 ;$i <= 7 ;++$i)
{
$M[$i+9]=$M9_16[$i];
}
for ($i=0 ;$i <= 7 ;++$i)
{
$M[$i+17]=$M17_24[$i];
}
$M1=$M1_8[0];
$M2=$M1_8[1];
$M3=$M1_8[2];
$M4=$M1_8[3];
$M5=$M1_8[4];
$M6=$M1_8[5];
$M7=$M1_8[6];
$M8=$M1_8[7];
$M9=$M9_16[0];
$M10=$M9_16[1];
$M11=$M9_16[2];
$M12=$M9_16[3];
$M13=$M9_16[4];
$M14=$M9_16[5];
$M15=$M9_16[6];
$M16=$M9_16[7];
$M17=$M17_24[0];
$M18=$M17_24[1];
$M19=$M17_24[2];
$M20=$M17_24[3];
$M21=$M17_24[4];
$M22=$M17_24[5];
$M23=$M17_24[6];
$M24=$M17_24[7];
# Das Byte für die Funktionstastenr wird nach binär gewandelt und in Zustände mit 1 oder 0 für $F1-$F4 dargestellt
$F1_8= array_reverse(str_split(str_pad(decbin(ord($ausgabe[67])),8,0,STR_PAD_LEFT)));
for ($i=0 ;$i <= 7;++$i)
{
$F[$i+1]=$F1_8[$i];
}
$F1=$F1_8[0];
$F2=$F1_8[1];
$F3=$F1_8[2];
$F4=$F1_8[3];
# Das Byte für die Cursertasten wird nach binär gewandelt und in Zustände mit 1 oder 0 für $C1-$C4 dargestellt
$C1_8= array_reverse(str_split(str_pad(decbin(ord($ausgabe[75])),8,0,STR_PAD_LEFT)));
for ($i=0 ;$i <= 7;++$i)
{
$C[$i+1]=$C1_8[$i];
}
$C1=$C1_8[0];
$C2=$C1_8[1];
$C3=$C1_8[2];
$C4=$C1_8[3];
# Zwei Bytes werden für die Analog Ausgang gewandelt und in Zustände mit 0 bis 1000 für $AQ1 und $AQ2
for ($i=1 ;$i <= 2;++$i)
{
$AQ[$i]= (( ord($ausgabe[95+$i]) *256) + ord($ausgabe[94+$i]));
}
$AQ1=(( ord($ausgabe[99+1]) *256) + ord($ausgabe[98+1]));
$AQ2=(( ord($ausgabe[99+2]) *256) + ord($ausgabe[98+2]));
# Zwei Bytes werden für die Analog Merker Ausgang gewandelt und in Zustände mit 0 bis 1000 für $AMQ1 und $AMQ16
for ($i=1 ;$i <= 29;++$i)
{
$AMQ[$i]= (( ord($ausgabe[99+$i]) *256) + ord($ausgabe[98+$i]));
}
$AMQ1=((( ord($ausgabe[99+1]) *256) + ord($ausgabe[98+1]))/10);
$AMQ2=(( ord($ausgabe[99+2]) *256) + ord($ausgabe[98+2]));
$AMQ3=((( ord($ausgabe[99+3]) *256) + ord($ausgabe[98+3]))/10);
$AMQ4=(( ord($ausgabe[99+4]) *256) + ord($ausgabe[98+4]));
$AMQ5=(( ord($ausgabe[99+5]) *256) + ord($ausgabe[98+5]));
$AMQ6=(( ord($ausgabe[99+6]) *256) + ord($ausgabe[98+6]));
$AMQ7=(( ord($ausgabe[99+7]) *256) + ord($ausgabe[98+7]));
$AMQ8=(( ord($ausgabe[99+8]) *256) + ord($ausgabe[98+8]));
$AMQ9=(( ord($ausgabe[99+9]) *256) + ord($ausgabe[98+9]));
$AMQ10=(( ord($ausgabe[99+10]) *256) + ord($ausgabe[98+10]));
$AMQ11=((( ord($ausgabe[99+11]) *256) + ord($ausgabe[98+11]))/10);
$AMQ12=(( ord($ausgabe[99+12]) *256) + ord($ausgabe[98+12]));
$AMQ13=((( ord($ausgabe[99+13]) *256) + ord($ausgabe[98+13]))/100);
$AMQ14=(( ord($ausgabe[99+14]) *256) + ord($ausgabe[98+14]));
$AMQ15=(( ord($ausgabe[99+15]) *256) + ord($ausgabe[98+15]));
$AMQ16=(( ord($ausgabe[99+16]) *256) + ord($ausgabe[98+16]));
$AMQ17=(( ord($ausgabe[99+17]) *256) + ord($ausgabe[98+17]));
$AMQ18=(( ord($ausgabe[99+18]) *256) + ord($ausgabe[98+18]));
$AMQ19=(( ord($ausgabe[99+19]) *256) + ord($ausgabe[98+19]));
$AMQ20=(( ord($ausgabe[99+20]) *256) + ord($ausgabe[98+20]));
$AMQ21=(( ord($ausgabe[99+21]) *256) + ord($ausgabe[98+21]));
$AMQ22=(( ord($ausgabe[99+22]) *256) + ord($ausgabe[98+22]));
$AMQ23=((( ord($ausgabe[99+23]) *256) + ord($ausgabe[98+23]))/10);
$AMQ24=((( ord($ausgabe[99+24]) *256) + ord($ausgabe[98+24]))/10);
$AMQ25=((( ord($ausgabe[99+25]) *256) + ord($ausgabe[98+25]))/10);
$AMQ26=((( ord($ausgabe[99+26]) *256) + ord($ausgabe[98+26]))/10);
$AMQ27=((( ord($ausgabe[99+27]) *256) + ord($ausgabe[98+27]))/10);
$AMQ28=((( ord($ausgabe[99+28]) *256) + ord($ausgabe[98+28]))/10);
$AMQ29=((( ord($ausgabe[99+29]) *256) + ord($ausgabe[98+29]))/10);
# Zwei Bytes werden für die Analog Eingang gewandelt und in Zustände mit 0 bis 1000 für $AI1 und $AI8
for ($i=1 ;$i <= 8;++$i)
{
$AI[$i]= (( ord($ausgabe[79+$i]) *256) + ord($ausgabe[78+$i]));
}
$AI1= (( ord($ausgabe[79+1]) *256) + ord($ausgabe[78+1]));
$AI2= (( ord($ausgabe[79+2]) *256) + ord($ausgabe[78+2]));
$AI3= (( ord($ausgabe[79+3]) *256) + ord($ausgabe[78+3]));
$AI4= (( ord($ausgabe[79+4]) *256) + ord($ausgabe[78+4]));
$AI5= (( ord($ausgabe[79+5]) *256) + ord($ausgabe[78+5]));
$AI6= (( ord($ausgabe[79+6]) *256) + ord($ausgabe[78+6]));
$AI7= (( ord($ausgabe[79+7]) *256) + ord($ausgabe[78+7]));
$AI8= (( ord($ausgabe[79+8]) *256) + ord($ausgabe[78+8]));
//Mailversand bei Störung/Alarm der Heizung
//$M4 = 0;
//Status der Variable $versandt wird ausgelesen
$dateiname = "email.txt";
$dateihandle = fopen($dateiname ,"r+");
$versandt = fgets($dateihandle , 2);
// echo "Datei-Lesen: " ,$versandt;
// echo "<br>";
fclose($dateihandle);
if ($versandt==1) goto AH;
if ($M4==1) #Alarm-Ausgang HIGH
{
// echo Schleife;
// echo "<br>";
$versandt==$versandt++;
$priority = "X-Priority: 1 (Highest)\n" . "Importance: High\r\n";
$empfaenger = "xxxxxxxxxx@xxx.de";
$absendername = "LOGO Heizung";
$absendermail = "Heizung@xxxxxxxxx.de";
$header = "From: $absendername <$absendermail>\n";
$header .= $priority;
$link = "http://xxxxxxxxxx.de/logo.php";
$betreff = "Probleme Heizung/Oelbrenner/Steuerung/Sensoren/Alarm";
$text = "Heizungssteuerung meldet Probleme!\nBitte auf $link\nnachschauen!\n\nMit freundlichem Gruss\n\nEure Heizung";
mail($empfaenger, $betreff, $text, $header);
//Mailversand wird bei Störung nach versandter Mail auf 1 gesetzt und in Datei geschrieben
$dateihandle = fopen($dateiname ,"r+");
fwrite($dateihandle , $versandt);
fclose($dateihandle);
}
AH:
//Mailversand wird bei beseitigter Störung auf 0 gesetzt und in Datei geschrieben
if ($M4==0)
{
$versandt=0;
// echo "Datei-Mitte: ",$versandt;
// echo "<br>";
}
$dateihandle = fopen($dateiname ,"r+");
fwrite($dateihandle , $versandt);
fclose($dateihandle);
// echo "Datei-Ende: ",$versandt;
// echo "<br>";
// echo "Datei M4: ",$M4;
// echo "<br>";
AA:
?>
<!--<table border="8" cellspacing="3" cellpadding="3" background="/0BA7.PNG" >//-->
<table border="8" cellspacing="3" cellpadding="3">
<tr>
<th colspan="8"; align="center"><?php echo "<span style=\"font-size: 18pt\"> HERR Heizungssteuerung </span>";?></th>
</tr>
<tr>
<td colspan="8"; align="center"><img src="/0BA7.PNG" width="850" height="350" /></td>
</tr>
<tr>
<th>Ausgaenge</th>
<th>Q1 - Q4</th>
<th>Eingaenge</th>
<th>I1 - I4</th>
<th>analoge Merker</th>
<th>AM1 - AM8</th>
<th>analoge Eingaenge</th>
<th>AI1 - AI4</th>
</tr>
<tr>
<td>Oelbrenner:</td>
<?php
If($Q1 >= 1){
echo '<td bgcolor="#FF0000">';
echo $Q1;
echo '</td>';
}else{
echo '<td bgcolor="#00FF00">';
echo $Q1;
echo '</td>';
}
?>
<td>Brauchwasser:</td>
<?php
If($I1 >= 1){
echo '<td bgcolor="#FF0000">';
echo $I1;
echo '</td>';
}else{
echo '<td bgcolor="#00FF00">';
echo $I1;
echo '</td>';
}
?>
<td>Kesseltemperatur:</td>
<td><?php print "$AMQ1 °C";?> </td>
<td>AI1:</td>
<td><?php print($AI1);?> </td>
</tr>
<tr>
<td>Mischer:</td>
<?php
If($Q2 >= 1){
echo '<td bgcolor="#FF0000">';
echo $Q2;
echo '</td>';
}else{
echo '<td bgcolor="#00FF00">';
echo $Q2;
echo '</td>';
}
?>
<td>frei:</td>
<?php
If($I2 >= 1){
echo '<td bgcolor="#FF0000">';
echo $I2;
echo '</td>';
}else{
echo '<td bgcolor="#00FF00">';
echo $I2;
echo '</td>';
}
?>
<td>Aussentemperatur:</td>
<td><?php print "$AMQ3 °C";?> </td>
<td>AI2:</td>
<td><?php print($AI3);?> </td>
</tr>
<tr>
<td>frei</td>
<?php
If($Q3 >= 1){
echo '<td bgcolor="#FF0000">';
echo $Q3;
echo '</td>';
}else{
echo '<td bgcolor="#00FF00">';
echo $Q3;
echo '</td>';
}
?>
<td>Oelbrenner OK:</td>
<?php
If($I3 >= 1){
echo '<td bgcolor="#FF0000">';
echo $I3;
echo '</td>';
}else{
echo '<td bgcolor="#00FF00">';
echo $I3;
echo '</td>';
}
?>
<td>Heizoel-Verbrauch:</td>
<td><?php print "$AMQ5 Liter";?> </td>
<td>AI3:</td>
<td><?php print($AI5);?> </td>
</tr>
<tr>
<td>Alarm:</td>
<?php
If($Q4 >= 1){
echo '<td bgcolor="#FF0000">';
echo $Q4;
echo '</td>';
}else{
echo '<td bgcolor="#00FF00">';
echo $Q4;
echo '</td>';
}
?>
<td>Oelbrenner Stoerung:</td>
<?php
If($I4 >= 1){
echo '<td bgcolor="#FF0000">';
echo $I4;
echo '</td>';
}else{
echo '<td bgcolor="#00FF00">';
echo $I4;
echo '</td>';
}
?>
<td>Heizoel-Rest:</td>
<td><?php print "$AMQ7 Liter";?> </td>
<td>AI4:</td>
<td><?php print($AI7);?> </td>
</tr>
<tr>
<th>Merker</th>
<th>M4</th>
<th>Funktionstasten</th>
<th>F3 - F4 </th>
<td>Tank-Fuellstand:</td>
<td><?php print "$AMQ9 %";?> </td>
<td></td>
<td></td>
</tr>
<tr>
<td>Alarm-eMail:</td>
<?php
If($M4 >= 1){
echo '<td bgcolor="#FF0000">';
echo $M4;
echo '</td>';
}else{
echo '<td bgcolor="#00FF00">';
echo $M4;
echo '</td>';
}
?>
<td>Schornsteinfeger:</td>
<td><?php print($F3);?> </td>
<td>Messabstand (von oben):</td>
<td><?php print"$AMQ11 cm";?> </td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td>Service-Menue:</td>
<td><?php print($F4);?> </td>
<td>Tank-Sensor:</td>
<td><?php print "$AMQ13 mA";?> </td>
<th>Laufzeit gesamt/h:</th>
<th><?php print($AMQ19);?></th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Tank-Sensor Leitungsbruch:</td>
<td><?php print($AMQ15);?> </td>
<th>Laufzeit heute/min:</th>
<th><?php print($AMQ21);?></th>
</tr>
<tr>
<th colspan="4"; align="center"><?php echo "Aussentemperatur Heute:";?></th>
<th colspan="4"; align="center"><?php echo "Aussentemperatur Jahr 2014:";?></th>
</tr>
<tr>
<td colspan="2"; align="center"><?php echo "Max: ",$AMQ23," °C";?></td>
<td colspan="2"; align="center"><?php echo "Min: ",$AMQ25," °C";?></td>
<td colspan="2"; align="center"><?php echo "Max: ",$AMQ27," °C";?></td>
<td colspan="2"; align="center"><?php echo "Min: ",$AMQ29," °C";?></td>
</tr>
<tr>
<th colspan="5"; align="left"><?php echo "Letzte Aktualisierung: ",$tage[$tag],", den ",$datum," um ",$uhrzeit," Uhr ";?></th>
<th colspan="3"; align="right"><?php echo "" ,$online," Besucher online";?></th>
</tr>
</table>
Kommentar