4

Im try to send a Message from PHP Website via TCP/IP to an Arduino.

With following code i'm able to send a message from php website

<?php 
$errno = NULL;
$error = NULL;

if (!$handle = @fsockopen("192.168.188.24", "49419", $errno, $error, 10))
{
   die("Fehler (".$errno."): ".$error);
}

fwrite($handle, "ON\r\n");
fclose($handle);
?>

The problem is, when calling the website for the first time, the message doesnt get delivered immediatly. Just after some refreshes of the website, the message arrives, but logical so many times like amount of website refreshes.

Already tried to limit the messagelength to 2bytes, but without any success.

3
  • Is the Arduino setup to listen for TCP messages properly? evothings.com/doc/examples/arduino-led-onoff-tcp.html Commented Feb 3, 2016 at 13:52
  • yes, it is. like already said, it's able to receive messages. Got displayed the the content on console. There isnt a certain number of refreshes, until the message/s arrive/s. When calling the website for first time, it just should send the message immediatly, and it does not. Commented Feb 3, 2016 at 14:00
  • 1
    Well, i tried the same with addison controller. seems like arduino has to be setup again, because addison received messages immediatly! Conclusion: PHP is fine and works like this! Thx alot! Commented Feb 3, 2016 at 19:49

1 Answer 1

1

Try adding inside a try - catch block.

    try {

    } catch (Exception $e) {
     echo $e->getMessage();
    }

To see what exception you may get.

Sign up to request clarification or add additional context in comments.

1 Comment

Please do not use answers to ask clarification questions. It's not hard to earn enough rep to make comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.