Garage Controller
\n"; /* Get the port for the service. */ $service_port = 1234; /* Get the IP address for the target host. */ // $address = '192.168.1.159'; // for now a LAN IP is all that is needed (Arduino) $address = '192.168.1.148'; // for now a LAN IP is all that is needed (WeMOS) /* Create a TCP/IP socket. */ $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n"; } else { echo "success creating socket\n\n"; } echo "Attempting to connect to '$address' on port '$service_port'...\n"; $result = socket_connect($socket, $address, $service_port); if ($result === false) { echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n"; } else { echo "OK.\n\n"; } echo "sending: $action\n"; socket_write($socket, $action, strlen($action)); socket_write($socket, "\r", 2); // signify end of action token echo "OK.\n\n"; echo "Reading response:\n"; while ($out = socket_read($socket, 2048)) { echo $out; } echo "\n\nClosing socket..."; socket_close($socket); echo "OK.\n\n"; } else { echo "Not sure why you are here...."; }