Search the Community
Showing results for tags 'arduino'.
-
I forked a project from M. Schwartz in Adafruit about wifi controlled robot, and he uses local web server to access it. Now I wanted to the host online the server files. My only problem is this part of his php file <?php // Load JSON state $string = file_get_contents("robot_state.json"); $json_a= json_decode($string,true); // Handle GET request $json_a['speed'] = $_GET["speed"]; $json_a['direction_left'] = $_GET["directionLeft"]; $json_a['direction_right'] = $_GET["directionRight"]; $json_a['reverse'] = $_GET["reverse"]; // Save JSON file $fp = fopen('robot_state.json', 'w'); fwrite($fp, json_encode($json_a)); fclose($fp); // Create a TCP/IP socket & connect to the server $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $result = socket_connect($socket, "192.168.1.6", "8888"); // Request $in = "HEAD / HTTP/1.1\r\n"; $in .= "Content-Type: text/html\r\n"; $in .= $json_a['speed'] . "," . $json_a['direction_left'] . "," . $json_a['direction_right'] . ",". $json_a['reverse'] . ",\r\n\r\n"; $out = ''; // Send request socket_write($socket, $in, strlen($in)); // Read answer while ($out = socket_read($socket, 4096)) { echo $out; } // Close socket socket_close($socket); ?> notice Line 19: socket_connect($socket, "192.168.1.6", "8888"); This is the part where it communicates to the wifi shield of the arduino. I know this simply wouldn't work now since this is only a private address and the files are now hosted in the internet. Can you guys teach me how to implement because I know this part of code will be quite different.
-
Hey im new to this forum and to php. im look for some help as i cant seem to get my lights to light up on my Arduino Uno board using 'Serial Comunication' This is my code on the server... $serial->deviceOpen(); if ($_GET['action'] == "on") { $serial->sendMessage("N\r\n"); $file = fopen("testFile.txt","w"); fwrite($file, "1"); fclose($file); } else if ($_GET['action'] == "off") { $serial->sendMessage("0\r\n"); $file = fopen("testFile.txt","w"); fwrite($file, "0"); fclose($file); } And my code on the Arduino is listening to the serial port and is waiting for N. I know this is correct as i can test it by manually sending it an N... If you know what is wrong with my code please help me and if you need more code snippets then i will gladly post them. Thanks! Chris
- 16 replies
-
- script
- serial port
-
(and 2 more)
Tagged with: