Reputation: 805
I'm using WiFi CC3000 shield and Adafruit_CC3000.h library. I'm able to connect to my wifi network and all examples work. But my sketch doesn't :(
Here is my loop()
function:
void loop()
{
Serial.println("In-loop");
unsigned long ip;
cc3000.getHostByName("docs.google.com", &ip);
client = cc3000.connectTCP(ip, 80);
if (client.connected())
{
Serial.println("Connected!!!");
String data = "entry.1820200471=46";
data += "&submit=Submit";
client.println(F("POST docs.google.com/forms/d/1YABi7F1ViEqVknN74dQhNLLJqq0RJLRr1QjohRk0qhc/formResponse"));
// client.println(F("HTTP/1.1\r\n"));
client.println(F("Host: docs.google.com\r\n"));
client.println(F("Accept: */*\r\n"));
client.println(F("Accept-Encoding: gzip, deflate\r\n"));
client.println(F("User-Agent: runscope/0.1\r\n"));
client.println(F("Content-Type: application/x-www-form-urlencoded\r\n"));
client.println(F("Connection: close\r\n"));
client.print(F("Content-Length: \r\n"));
client.println(data.length());
client.println();
client.print(data);
client.println();
Serial.println("POST docs.google.com/forms/d/1YABi7F1ViEqVknN74dQhNLLJqq0RJLRr1QjohRk0qhc/formResponse");
// Serial.println("HTTP/1.1");
Serial.println("Host: docs.google.com");
Serial.println("Accept: */*");
Serial.println("Accept-Encoding: gzip, deflate");
Serial.println("User-Agent: runscope/0.1");
Serial.println("Content-Type: application/x-www-form-urlencoded");
Serial.println("Connection: close");
Serial.print("Content-Length: ");
Serial.println(data.length());
Serial.println();
Serial.print(data);
Serial.println();
Serial.println("----------");
unsigned long lastRead = millis();
while(client.connected() && (millis() - lastRead < 3000)) {
while (client.available()) {
char c = client.read();
Serial.print(c);
lastRead = millis();
}
}
Serial.println("----------");
} else {
Serial.println("Not connected");
}
delay(15000L);
}
And the output I get is follow:
In-loop
Connected!!!
POST docs.google.com/forms/d/1YABi7F1ViEqVknN74dQhNLLJqq0RJLRr1QjohRk0qhc/formResponse
Host: docs.google.com
Accept: */*
Accept-Encoding: gzip, deflate
User-Agent: runscope/0.1
Content-Type: application/x-www-form-urlencoded
Connection: close
Content-Length: 33
entry.1820200471=46&submit=Submit
----------
----------
I've tried my request here and it works (actually some headers I took from there).
Could anyone help me?
Upvotes: 0
Views: 1702
Reputation: 624
I have tried this various times but I have not found a good way to use POST directly. I have read that it is because google requires https for all communication.
To make it work a relay service like pushinhbox.com is required.
Here is a good guide: http://m.instructables.com/id/Post-to-Google-Docs-with-Arduino/
Arduino can't because it doesn't have the programming space or the ram to run SSL easily or in a usable way. Here is a good quick discussion about it: Arduino Due HTTPS Support
You could us another platform like the Intel Galileo which is a Linux board that runs arduino code http://arduino.cc/en/ArduinoCertified/IntelGalileo
Or another like raspberry pi or beaglebone black.
Upvotes: 1