diff --git a/examples/rtl_433_custom.php b/examples/rtl_433_custom.php index 1c298c37..bcd0a035 100755 --- a/examples/rtl_433_custom.php +++ b/examples/rtl_433_custom.php @@ -19,7 +19,7 @@ Restart=always RestartSec=5 RemainAfterExit=no 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] WantedBy=multi-user.target @@ -105,4 +105,3 @@ for (;;) } } ?> - diff --git a/examples/rtl_433_http_stream.php b/examples/rtl_433_http_stream.php new file mode 100644 index 00000000..b62db9fc --- /dev/null +++ b/examples/rtl_433_http_stream.php @@ -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); +} +?>