Thread Kontinuierlich Net-Stream anzeigen
(29 answers)
Opened by
kami
at 2011-11-09 13:05
User since 2010-03-17
92
Artikel
BenutzerIn
Hi Leute,
so ich bin nun etwas weiter mit meinem Skript. Das verbinden klappt alles super und ich kriege die Daten immer wieder in da File test geschrieben. Da ich es noch nicht geschafft habe die Umwandlung zu portieren, muss ich mit dem PHP-Skript alwindow.php auf das File test zu greifen und bei Bedarf eine Auswertung machen. Ich habe nun noch folgende 2 Probleme:
1. Wenn das Skript pler.pl läuft dann benötigt es sehr viel Rechenleistung. Kann man das irgendwie optimieren oder verschlanken?
2. Kann man die Entschlüsselung irgendwie in Perl portieren? Mit der Version von topeg, gab es dort leider nur Fehler.
Vielen Dank.
Gruß kami
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use strict;
use warnings;
use IO::Socket;
my $host = "192.168.0.36";
my $port = "80";
while(1)
{
my $handle = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => $host,
PeerPort => $port
) // die("ERROR open Socket $host:$port ($!)\n");
$handle->blocking(0);
binmode($handle);
my $finished = 0;
my $buffer='';
while($finished==0)
{
my $line='';
$handle->read($line,4096);
$finished=1 if(index($buffer,'L:')!=-1);
$buffer.=$line if(length($line));
}
$handle->close();
if(!$finished)
{
print "No Connection\n";
next;
}
open(STATION, ">/home/kami/scripts/test");
foreach my $v (split("\r",$buffer))
{
print STATION $v."\n";
}
close (STATION);
sleep(3);
system("./alwindow.php", "windowsstatus");
print $?;
}
alwindow.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
#!/usr/bin/php -q <?php
#print_r($argv); $finished = 0; $jetzt = time();
$handle = @fopen('/home/kami/scripts/test', "r"); if ($handle) { while (!feof($handle)) { $arr[] = fgets($handle, 4096); } fclose($handle); } ob_start(); foreach ($arr as $v) {
if (substr($v,0,2) == "M:") { $arr2 = explode(',',$v); $str = base64_decode($arr2[2]); $pos = 0; $readlen = 1; $data["meta"]["?1"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen; $readlen = 1; $data["meta"]["?2"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen; $readlen = 1; $data["meta"]["RoomCount"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen;
for($j = 1 ; $j <= $data["meta"]["RoomCount"] ; $j++) { $readlen = 1; $RoomID = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen; $readlen = 1; $data["rooms"][$RoomID]["RoomNameLength"] = htmlentities(ord(substr($str,$pos,1))).""; $pos += $readlen; $readlen = $data["rooms"][$RoomID]["RoomNameLength"]; for($i = $pos; $i < $readlen+$pos ; $i++) $data["rooms"][$RoomID]["RoomName"] .= htmlentities(substr($str,$i,1)).""; $pos += $readlen; $readlen = 3; for($i = $pos; $i < $readlen+$pos ; $i++) $data["rooms"][$RoomID]["RFAdress(?)"] .= str_pad(dechex(ord(substr($str,$i,1))),2,"0",STR_PAD_LEFT).""; $pos += $readlen; }
$readlen = 1; $data["meta"]["DevCount"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen;
}
if (substr($v,0,2) == "L:") { $v = substr($v,2,strlen($v)); $str = base64_decode($v); $pos = 0;
for($j = 1 ; $j <= $data["meta"]["DevCount"]; $j++) { unset($hilf); $readlen = 1; $hilf["ReadLength"] = htmlentities(ord(substr($str,$pos,1))).""; $pos += $readlen; $readlen = 3; for($i = $pos; $i < $readlen+$pos ; $i++) $hilf["RFAdress"] .= str_pad(dechex(ord(substr($str,$i,1))),2,"0",STR_PAD_LEFT).""; $pos += $readlen; $readlen = 1; $hilf["?1"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen; $readlen = 1; $hilf["Data1"] .= str_pad(decbin(ord(substr($str,$pos,1))),8,"0",STR_PAD_LEFT).""; $pos += $readlen; $readlen = 1; $hilf["Data2"] .= str_pad(decbin(ord(substr($str,$pos,1))),8,"0",STR_PAD_LEFT).""; $pos += $readlen;
if($hilf["ReadLength"] == 11) { $readlen = 1; $hilf["?2"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen; $readlen = 1; $hilf["Temperature"] = (ord(substr($str,$pos,1))/2).""; $pos += $readlen; $readlen = 2; for($i = $pos; $i < $readlen+$pos ; $i++) $hilf["DateUntil"] .= str_pad(decbin(ord(substr($str,$i,1))),8,"0",STR_PAD_LEFT).""; $pos += $readlen; $readlen = 1; $hilf["TimeUntil"] = (ord(substr($str,$pos,1))*0.5).""; $pos += $readlen; }
if($hilf["ReadLength"] == 11) {
$deviceconf[$hilf["RFAdress"]]["Temperature"] = $hilf["Temperature"]; }
$deviceconf[$hilf["RFAdress"]]["LowBatt"] = substr($hilf["Data2"],0,1);
switch (substr($hilf["Data2"],6,2)) { case "00" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "auto"; break; case "01" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "manu"; break; case "10" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "vacation"; break; case "11" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "boost"; break; }
} //echo $v; } }
$ob = ob_get_contents(); ob_end_clean(); switch ($argv[1]) { case "windowsstatus" : if ($deviceconf['005bfb']['Mode']=="auto" && $deviceconf['004bb8']['Mode'] =="auto" ) echo "2\n"; else echo "1\n"; break; case "tempkueche" : echo $deviceconf['008f02']["Temperature"]; break; case "tempwohn" : echo $deviceconf['010863']["Temperature"]; break; case "batwohn" : echo $deviceconf['010863']["LowBatt"]; break; case "batkueche" : echo $deviceconf['008f02']["LowBatt"]; break; case "modekueche" : echo $deviceconf['008f02']["Mode"]; break; case "modewohn" : echo $deviceconf['010863']["Mode"]; break; }
?>
View full thread Kontinuierlich Net-Stream anzeigen
|