Add php example stream script (closes #2687)
Co-authored-by: AutomGuy <AutomGuy@users.noreply.github.com>
This commit is contained in:
parent
2e7052e377
commit
abb0bc7bae
2 changed files with 85 additions and 2 deletions
|
@ -19,7 +19,7 @@ Restart=always
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
RemainAfterExit=no
|
RemainAfterExit=no
|
||||||
User=root
|
User=root
|
||||||
ExecStart=/bin/sh -c "/usr/bin/rtl_433 -f 433920000 -f 433920000 -H 120 -F syslog:127.0.0.1:1433"
|
ExecStart=/bin/sh -c "/usr/bin/rtl_433 -f 433.92M -F syslog:127.0.0.1:1433"
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
@ -105,4 +105,3 @@ for (;;)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
84
examples/rtl_433_http_stream.php
Normal file
84
examples/rtl_433_http_stream.php
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Short example of an TCP client written in PHP for rtl_433.
|
||||||
|
|
||||||
|
You need to have `php_cli` installed.
|
||||||
|
|
||||||
|
To run this as service use these systemd service files for
|
||||||
|
ubuntu, lubuntu, xubuntu, debian, ubuntu core and so on.
|
||||||
|
|
||||||
|
## Service file to start the rtl_433 process
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=rtl433 tcp service
|
||||||
|
After=network.target
|
||||||
|
[Service]
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
RemainAfterExit=no
|
||||||
|
User=root
|
||||||
|
ExecStart=/bin/sh -c "/usr/bin/rtl_433 -f 433.92M -F http:127.0.0.1:8433"
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
## Service file to start the php udp server
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=http 433 tcp service
|
||||||
|
After=network.target
|
||||||
|
StartLimitIntervalSec=0
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=always
|
||||||
|
RestartSec=1
|
||||||
|
User=root
|
||||||
|
ExecStart=/usr/bin/php /home/user/rtl_433/examples/rtl_433_http_stream.php
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//Function to check $haystack if
|
||||||
|
//$needle in $haystack
|
||||||
|
function str__contains($haystack,$needle)
|
||||||
|
{
|
||||||
|
return (strpos($haystack, $needle) !== false)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//main
|
||||||
|
$adr = "127.0.0.1";
|
||||||
|
$port = "8433";
|
||||||
|
$url = $sdr . ":" . $port . "/stream";
|
||||||
|
|
||||||
|
$fp = stream_socket_client("tcp://" . $url , $errno, $errstr, 70);
|
||||||
|
if (!$fp) {
|
||||||
|
//optional error output
|
||||||
|
//echo "$errstr ($errno)<br />\n";
|
||||||
|
} else {
|
||||||
|
fwrite($fp, "GET / HTTP/1.0\r\nHost: " . $adr . "\r\nAccept: */*\r\n\r\n");
|
||||||
|
while (!feof($fp)) {
|
||||||
|
$line = fgets($fp, 1024);
|
||||||
|
//time is available in all received records, that is the filter word
|
||||||
|
//for sensor data
|
||||||
|
if(str__contains($line,"time"))
|
||||||
|
{
|
||||||
|
//raw output of json
|
||||||
|
print_r($line);
|
||||||
|
/*
|
||||||
|
do something with content of $line
|
||||||
|
for example decode $line into an array
|
||||||
|
$arr = json_decode($line,true);
|
||||||
|
|
||||||
|
do something with that array and
|
||||||
|
output into a file as json
|
||||||
|
file_put_contents('test.json', json_encode($arr, JSON_PRETTY_PRINT);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
?>
|
Loading…
Add table
Reference in a new issue