Muggins Posted March 16, 2014 Share Posted March 16, 2014 Hi Out of my depth here: I have some automation running on a hacked livebox. I want to socket connect, then send an instruction. Problem is the response is constantly changing and I need to somehow requery and parse the result at intervals like 5 seconds. Just beginning to learn PHP so be kind if there is an easy answer. Here is some cut down script. <?php switch ($_REQUEST['btn_submit']) { case "Liv Boost": $response = send("boost liv 1"); break; case "Liv OFF": $response = send("boost liv 0"); break; case "Requery": $response = send(""); } function send($sendstring) { $fp = fsockopen("xx.xx.xx.xx", 9996, $errno, $errstr, 10); fwrite($fp, $sendstring); sleep(2); return fread($fp, 2056); fclose($fp); } function parse($RD,$par1,$par2,$par3) { $pos=strpos($RD,$par1); If ($pos > 0){return substr($RD, $pos + $par2 , $par3);} } ?> <html> <head id="Head1" runat="server"> <title>Home Automation</title> </head> <form method="POST"> <input type="submit" name="btn_submit" value="Liv Boost" /> <input type="submit" name="btn_submit" value="Liv OFF" /> <input type="textbox" name="rowID" value="<?php echo parse($response,"livboostcounter",46,5); ?>" /></br> <input type="submit" name="btn_submit" value="Requery" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/287014-some-help-with-client-socket/ Share on other sites More sharing options...
trq Posted March 16, 2014 Share Posted March 16, 2014 Do you have a question? Quote Link to comment https://forums.phpfreaks.com/topic/287014-some-help-with-client-socket/#findComment-1472817 Share on other sites More sharing options...
Muggins Posted March 17, 2014 Author Share Posted March 17, 2014 My question was how do I send the requery at intervals, or perhaps there is a better way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/287014-some-help-with-client-socket/#findComment-1472863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.