Go Down

Topic: Uploading Arduino data to Google drive (Read 2354 times) previous topic - next topic

prachi

Hello!
I want to upload sensor data from the Arduino Uno R3 to a Google Docs spreadsheet froma Google Docs form. For this, I need to make an HTTP POST request using the following URL:

https://docs.google.com/forms/d/****************************-***************/formResponse?ifq&entry.********=Night&entry.********=30&entry.********=27&submit=Submit

(**** represent formkey and entry numbers)

When I type this URL in my browser, an entry is added into the spreadsheet successfully. So I guess, there is no problem with the URL as such. There could be a problem in the Arduino code I am using for this URL. I am getting a HTTP/1.0 400 Bad Request error.

Any help would be appreciated.  The code is as follows:

Code:
#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <Pstring.h>
#include <stdlib.h>

byte mac[] = { 0x**,0x**,0x**,0x**,0x**,0x**};  //Ethernet shield MAC
IPAddress server(74,125,232,128);// Make it char server[]= "www.google.com" if DNS is available
IPAddress ip = (,,,);  //IP address to be added
IPAddress subnet = (,,,); //Subnet Mask to be added
IPAddress gateway = (,,,); //Gateway to be added
IPAddress DNS = (,,,); //DNS to be added

EthernetClient client;

void setup()
{
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip,gateway,subnet);//Make it Ethernet.begin(mac,ip,DNS,gateway,subnet); if DNS is available
  }
  delay(1000);
  Serial.println("connecting...");
 
  String data;
  data+="";
  data+="entry.********=Night&entry.********=30&entry.********=27&submit=Submit";

  if (client.connect(server,80)) {
    Serial.println("connected");

    client.print("POST /forms/d/****************************-***************/formResponse?ifq HTTP/1.0");
    client.println("Host: docs.google.com");
    client.println("User-Agent: Arduino/1.0");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println("Connection: close");
    client.print("Content-Length: ");
    client.println(data.length());
    client.println();
    client.print(data);
    client.println();

    Serial.print("forms/d/****************************-***************/formResponse?ifq HTTP/1.0");
    Serial.println("Host: docs.google.com");
    Serial.println("User-Agent: Arduino/1.0");
    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();
}

}
void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
    }
   
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
 
  delay(1000);
}

RobJW

Hello

I'm trying to do something similar.  Did you manage to solve your problem?

Cheers

Rob

cguesty

If the submission works in your browser it may be simpler to use a GET request

Code: [Select]


    client.print("GET/formResponse?ifq&entry.********=Night&entry.********=30&entry.********=27&submit=Submit  HTTP/1.1");
    client.println("Host: docs.google.com");
    client.println("User-Agent: Arduino/1.0");
    client.println("Connection: close");
    client.println();



If you want to stick to POST, possible issues are (at a guess) your data.length() isnt returning the correct number of bytes, or it could be that you should be using POST ... HTTP/1.1 (not 1.0) as Connection: close was defined in 1.1. Possibly remove the User-Agent header, maybe google doenst like it..

rw950431


Might also be that https:// is a problem.  Last time I checked arduino library's didnt have the crypto required to do SSL.

It would be worth checking that plain old http:// works OK in your browser and doesnt get redirected automatically to the https:// version.

tarata

I have the same problem... solve it?

Byork

If https is indeed the issue here, you can create an app in google appengine, send your http request to the app and have it forward the request to your intended url.

tarata


tarata

I find ithttps://cloud.google.com/appengine/docs/java/modules/routing

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy