Go Down

Topic: Uploading Arduino data to Google drive (Read 985 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);
}

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