AdaFruit CC3000 tutorial connection error

Hi,

I am not getting my Arduino + CC3000 to talk to my localhost php files.

The Apache access log returns:
192.168.1.78 - - [14/Jul/2014:01:03:34 +0200] "GET /~Peder/wifi-weather-station/sensor.php?temp=29 HTTP/1.0" 500 -

Error log:
[Mon Jul 14 01:02:55 2014] [error] [client 192.168.1.78] PHP Parse error: parse error in /Users/Peder/Sites/wifi-weather-station/sensor.php on line 7

phpinfo() returns the following address:
/~Peder/wifi-weather-station/test.php

The Arduino get request is as follows (only posting snippets - directly taken from AdaFruit tutorial):

// Send request
String request = "GET /~Peder/wifi-weather-station/sensor.php?temp=" + temperature + " HTTP/1.0\n";
send_request(request);

// Function to send a TCP request and get the result as a string
void send_request (String request) {

// Connect
Serial.println("Starting connection to server...");
Adafruit_CC3000_Client client = cc3000.connectTCP(ip, port);

// Send request
if (client.connected()) {
client.print(request);
client.println(F(""));
Serial.println("Connected & Data sent");
}
else {
Serial.println(F("Connection failed"));
}

sensor.php code:

<?php // Store data if ($_GET["temp"]) { $myFile = “/~Peder/wifi-weather-station/temp_data.txt"; $fh = fopen($myFile, ‘w’); fwrite($fh, $_GET["temp"]); fclose($fh); } ?>

Any help appreciated!

Regards,

Peder

Note: modified original header and added "connection"

I'm not sure but I would suggest trying it without the '/' before '~Peder'. I think that filename doesn't parse correctly.

thanks for the quick reply johnwasser,

when I remove the first / i instead get the following error:
[Mon Jul 14 07:37:58 2014] [error] [client 192.168.1.78] Invalid URI in request GET ~Peder/wifi-weather-station/sensor.php?temp=25 HTTP/1.0

and I haven't been able to find any information regarding invalid URI that brings me further towards a solution.

The server is reporting a PHP parse error, not a connection error. This is line 7 in that file.

$myFile = “/~Peder/wifi-weather-station/temp_data.txt";

The file location is probably not correct. Use the local directory path, not the Apache path.

edit: I did not notice the leading double quote is not correct until I posted line 7 here. Do you notice it is different than the trailing double quote? They should look the same.

You did not post the entire Apache access log, but I will presume the status code returned was "500 - Internal Server Error".

Success!

These are the code snippets that did it (if there are others with the same issue - for learning :slight_smile: )

Arduino:
String request = "GET http://localhost/~Peder/wifi-weather-station/sensor.php?temp=" + temperature + "&hum=" + humidity + " HTTP/1.0\n";

sensor.php (original file from adafruit)

<?php // Store data if ($_GET["temp"] && $_GET["hum"]) { $myFile = "temp_data.txt"; $fh = fopen($myFile, 'w'); fwrite($fh, $_GET["temp"]); fclose($fh); $myFile = "hum_data.txt"; $fh = fopen($myFile, 'w'); fwrite($fh, $_GET["hum"]); fclose($fh); } ?>

It turned out to be partly having the right local address (used http://localhost...) and wrong double quotation marks, not quite sue why that was an issue I only used the ones I have but they seemed to come up in italics... so I ended up cutting and pasting the original doubles.

thanks johnwasser and SurferTim for leading me to the answer