loading
I have a Netduino+ hooked up on the Internet with data logging  via Google docs.
Before i found this i was collecting the data via a SD card, on the Netduino.

I read almost every day Hackaday here i stumbled up at http://hackaday.com/2012/05/31/data-logging-directly-to-google-docs-google-drive/

But this didn't work for me, but i knew i was on the right trail.

After a lot of googleling  it worked for me, this (story) is how i did it.

I have tried to simply the whole thing in only text, with links to more relevant documents.
Please ask in the comments and i will try to answer these.

If something relevant is asked i maybe will change this instructable to clarify some streps, so please read first then ask.

This way of collecting is also useful with writing software with a database, you don't need a server with SQL or other language.

Step 1: Filling a Spreadsheet

Filling a spreadsheet in google docs goes always via a form:
After hitting the Submit button on this form the URL is send to Google docs:
https://docs.google.com/spreadsheet/formResponse?formkey=Here_goes_the_formkey&ifq&entry.0.single=opeens&entry.1.single=nu&pageNumber=0&backupCache=&submit=insturen

When you change the URL with the right values then you can send your data from a micro-controller or software to the spreadsheet.

Step 2: Use Google Docs to Collect Data of a Micro Controller.

To use Google docs you need an account, if you make your project for somebody else then make for that project a new account.
Login and go in  google docs to new-->form
Very importantvVia this form the data is collected and put in the spreadsheet.
No form, No spreadsheet.

For every parameter you will follow, make a field.
(# means a number
 : means "this will be" "in the URL")

Standard HTML:
Text field : entry.#.single
textarea    : entry.#.single
radio     : entry.#.group  // Same group number belongs to the same group.
checkbox   : entry.#.group  // Same group number belongs to the same group. entry.3.group=value1&entry.3.group=value2
option/select : entry.#.single

Special:
scale     : based on type radio on a row
grid     : based on type radio in a grid

The most used fields would be a text field for values and radio button for boolean.

Step 3: How to Implement This?

To try it out as a URL in the browser follow these steps:

In the form editor click in the bottom of the page on view in real, open here the source of the HTML.

Search for FORM action=""
In here is the link to the spreadsheet.
Something like:
https://docs.google.com/spreadsheet/formResponse?formkey=Your_formkey&ifq

After this text comes the parameters.
Search for name=" here you find as example:entry.1.single

use the & symbol with each entry.

example:
&entry.1.single=value

&entry.2.group=value1 // this way by checkbox
&entry.2.group=value2 // this way by checkbox

&entry.3.group= value of row 1 // this way by a grid every row is a separated entry.#.group=value
&entry.4.group= value of row 2 // A grid with four rows with 3 columns each row entry got the name of the column(There is only one possibility per row. )
&entry.5.group= value of row 3
&entry.6.group= value of row 4

so go on to the last parameter.
Close the string with :
&pageNumber=0&backupCache=&submit=Submit

Important:
For a space in a URL use %20, this is the symbol for space in HTML FORM.

Important:
If you need extra parameters then you must change the form with the google form editor.
You can't append more "entry.#....", google won't know these, it only knows the structure of the form you make the first time.

Step 4: The (simplified) Code

const string FormKey = "Here comes the form key"; // Important DON't use the spreadsheet key. this is different key
        static string GoogleIP = "spreadsheets.google.com";     // Google adress
        static Int32 GooglePort = 80;                   // Port Number 443=https 80=http
   
    Fill the parameters:
                formdata = "&entry.0.single=" + value.ToString();
                formdata += "&entry.1.single=" + value.ToString();
               
                formdata += "&entry.2.single=" + value.ToString();
                formdata += "&entry.3.single=" + value.ToString();
               
                formdata += "&pageNumber=0&backupCache=&submit=insturen"; // close with this these are hidden on the form
               
               
    Send parameters to Google Doc(formdata are your parameters)
   
      request = "POST /formResponse?formkey=";
            request +=  FormKey;
            request += "&ifq HTTP/1.1\r\n";
            request += "Host: ";
            request += GoogleIP+"\r\n";
            request += "Content-Type: application/x-www-form-urlencoded\r\n";
            request += "Connection: close\r\n";
            request += "Content-Length: " + formdata.Length + "\r\n";
           
            request += "\r\n";
            request += formdata;
           
            request += "\r\n";
           
   
How to send your data is for each program language different.

Step 5: Now You Can Use the Spreadsheet As a Database

Document for using a spreadsheet as a database:
https://developers.google.com/chart/interactive/docs/querylanguage#Setting_the_Query_in_the_Data_Source_URL

Database examples:
https://spreadsheets.google.com/tq?tqx=out:html&tq=select*%20format%20A%20%27dd-MMMM-yyyy%20hh:mm%27&key=Spreadsheet key
here is:
    tqx=out:html (or csv|json) Maybe other outpu formats?
    tq=select*%20format%20A%20%27dd-MMMM-yyyy%20hh:mm%27
    (* means all)
           Select all columns but use a format on column A --> dd-MMMM-yyyy hh:mm somthing like 03-august-2012 12:23

https://spreadsheets.google.com/tq?tqx=out:html&tq=select+A,+B,+C,+D,+E&key=Spreadsheet key
here is:
    tq=select+A,+B,+C,+D,+E
      Select all data of column A,B,C,D,E,F
     
With select you can use calculations or other simple query's. See the document for examples.

With this URL you can get the data in your program, and manipulate it.

Step 6: Ready

I wrote this as is. So please ask and i will try to answer.
This step for step instructables i have made is for my self so i can not forget it,
but i have put it in the public because it is a nice way to collect your data and like to share with you.



Google docs will soon be Google drive, i hope this will work then to.
I have tried it 03-07-2013 and it still works:
spreadsheets.google.com/formResponse?formkey=Here comes your formkey&ifq&entry.0.single=10&entry.1.single=20&entry.2.single=30&entry.3.single=40&pageNumber=0&backupCache=&submit=insturen

Greetings,
<p>This won't work with plain old http anymore. Google requires TLS access now. Your board needs to support 'https' or use a middleman like Temboo, pushingbox (custom URL method) to make 'https' requests to google.</p>
<p>Hello,</p><p>I believe the format for the URL's for google's forms has changed. There is no longer a formkey, or it is not specified as it used to be. Does anyone know how to identify the formkey in the new URL format?</p><p>Thanks</p>
<p>Hi <a href="https://www.instructables.com/member/igagnon" rel="nofollow">igagnon</a>,</p><p>Did you find an answer? I am also after this.</p><p>Thanks </p>
<p>is it possible to create the link you created and run it in browser itself?</p><p>or can it be used in a html webpage as submittion button?</p>
As in step 2 and 3 you see it is a conversion from HTML to C.<br>In step 6 you see the link itself created from de HTML Form tag.
<p>is it possible to create the link you created and run it in browser itself?</p><p>or can it be used in a html webpage as submittion button?</p>
<p>Hi,</p><p>I am trying to send arduino data (of a sensor) to google spreadsheets using WiFi shield. But the data is not been saved in the spreadsheet. Here is my code:</p><p>#include &lt;WiFi.h&gt;</p><p>int SensorIn1 = 1;</p><p>int led_pin = 13;</p><p>char ssid[] = &quot;**********&quot;;//Network name</p><p>char pass[] = &quot;*********&quot;;// Network Password</p><p>int status = WL_IDLE_STATUS;</p><p>WiFiServer server(80);</p><p>void setup() {</p><p> Serial.begin (9600);</p><p> while ( status != WL_CONNECTED) {</p><p> Serial.print(&quot;Attempting to connect to WPA SSID: &quot;);</p><p> Serial.println(ssid);</p><p> // Connect to WPA/WPA2 network: </p><p> status = WiFi.begin(ssid, pass);</p><p> // wait 10 seconds for connection:</p><p> delay(1000);</p><p> }</p><p> Serial.print(&quot;You're connected to the network&quot;);</p><p> server.begin(); // initialise the server</p><p> // print out your network data</p><p> printCurrentNet();</p><p> printWifiData();</p><p>}</p><p>void loop() {</p><p> WiFiClient client = server.available(); </p><p> int val;</p><p> val = analogRead(SensorIn1);</p><p> Serial.println(val);</p><p> delay (100);</p><p> if (client) {</p><p> Serial.println(&quot;new client&quot;);</p><p> boolean currentLineIsBlank = true;</p><p> while (client.connected()) {</p><p> if (client.available()) {</p><p> char c = client.read();</p><p> Serial.write(c);</p><p> //if (client.connected()) {</p><p> Serial.println(&quot;connected&quot;);</p><p> // send a standard http response header</p><p> String data = &quot;&amp;entry.1515954247=&quot;;</p><p> data = data + val;</p><p> data = data + &quot;&amp;submit=Submit&quot;;</p><p> client.print(&quot;POST /forms/d/1tUMKnf1HYY5tCuG_lG93N9kJhd4voQ1elRmTXYzLm/formResponse?&quot;);</p><p> client.println(&quot;ifq HTTP/1.1\r\n&quot;);</p><p> client.println(&quot;Host: docs.google.com&quot;);</p><p> client.println(&quot;User-Agent: Arduino/1.0&quot;);</p><p> client.println(&quot;Content-Type: application/x-www-form-urlencoded&quot;);</p><p> client.println(&quot;Connection: close&quot;);</p><p> client.println(&quot;Refresh: 1&quot;); </p><p> client.print(data);</p><p> //client.print(&quot;Content-Length: &quot;);</p><p> //client.println(data.length());</p><p> //client.println();</p><p> //client.print(val);</p><p> client.println();</p><p> }</p><p> }</p><p> delay (100);</p><p> client.stop();</p><p> Serial.println(&quot;client disconnected&quot;);</p><p> }</p><p>}</p><p>void printWifiData() {</p><p> // print your WiFi shield's IP address:</p><p> IPAddress ip = WiFi.localIP();</p><p> Serial.print(&quot;IP Address: &quot;);</p><p> Serial.println(ip); </p><p> // print your MAC address:</p><p> byte mac[6]; </p><p> WiFi.macAddress(mac);</p><p> Serial.print(&quot;MAC address: &quot;);</p><p> Serial.print(mac[5],HEX);</p><p> Serial.print(&quot;:&quot;);</p><p> Serial.print(mac[4],HEX);</p><p> Serial.print(&quot;:&quot;);</p><p> Serial.print(mac[3],HEX);</p><p> Serial.print(&quot;:&quot;);</p><p> Serial.print(mac[2],HEX);</p><p> Serial.print(&quot;:&quot;);</p><p> Serial.print(mac[1],HEX);</p><p> Serial.print(&quot;:&quot;);</p><p> Serial.println(mac[0],HEX);</p><p>}</p><p>void printCurrentNet() {</p><p> // print the SSID of the network you're attached to:</p><p> Serial.print(&quot;SSID: &quot;);</p><p> Serial.println(WiFi.SSID());</p><p> // print the received signal strength:</p><p> long rssi = WiFi.RSSI();</p><p> Serial.print(&quot;signal strength (RSSI):&quot;);</p><p> Serial.println(rssi);</p><p> // print the encryption type:</p><p> byte encryption = WiFi.encryptionType();</p><p> Serial.print(&quot;Encryption Type:&quot;);</p><p> Serial.println(encryption,HEX);</p><p> Serial.println();</p><p>}</p><p>Can anyone help me in debugging this. I have seen many references from google but nothing is working out.</p>
<p>You send your values to docs.google.com instead of spreadsheets.google.com</p><p>maybe this is what goes wrong.</p>
<p>I tried with docs.google.com as well but the problem is still the same. I can give you the spreadsheet key and the form key separately if that helps.</p>
<p>per 04 januari 2015:</p><p>spreadsheets.google.com/formResponse?formkey=</p><p>Here comes the form key</p><p>&amp;ifq&amp;entry.0.single=10&amp;entry.1.single=20&amp;entry.2.single=30&amp;entry.3.single=40&amp;pageNumber=0&amp;backupCache=&amp;submit=insturen</p><p>This still works</p><p>It is important that you replicate the exact structure in your code like in Step 4 there are a few variable you missed.</p><p>Write out your code as a URL and put it in your browser navigation then you can see what goes wrong.</p><p>Step 4:</p><p>const string FormKey = &quot;Here comes the form key&quot;; // Important DON't use the spreadsheet key. this is a different key<br> <br> static string GoogleIP = &quot;spreadsheets.google.com&quot;; // Google adress<br> <br> static Int32 GooglePort = 80; // Port Number 443=https 80=http<br> <br> <br> <br> Fill the parameters:<br> <br> formdata = &quot;&amp;entry.0.single=&quot; + value.ToString();<br> <br> formdata += &quot;&amp;entry.1.single=&quot; + value.ToString();<br> <br> <br> <br> formdata += &quot;&amp;entry.2.single=&quot; + value.ToString();<br> <br> formdata += &quot;&amp;entry.3.single=&quot; + value.ToString();<br> <br> <br> <br> formdata += <br>&quot;&amp;pageNumber=0&amp;backupCache=&amp;submit=insturen&quot;; // close with <br>this these are hidden on the form</p><p>Also important is last line with the pagenumber=0 variable it is for me a few years ago it worked for me on the moment i'am not using it anymore maybe googledocs has changed dramatic. the trick is to replicate the HTML form data in your C code.</p>
<p>Hi, I am getting trouble in executing client.connect(server, 80)</p><p>The console in not getting inside this block since client.connect(server, 80) returns false in my case. The issue you are addressing might be there after establishing a connection. But there is no connection established in this case. Find attached a simple code here with pushingbox as the intermediate way to the server. This is the output I get with the code attached.</p><p>connecting...</p><p>794</p><p>disconnecting.</p><p>878</p><p>disconnecting.</p><p>614</p><p>disconnecting.</p><p>556</p>
<p>I'am sending the data directly to google and not via an intermediate as pushingbox.</p><p>In your example code you are trying to login by pushingbox and not directly by google. All the error codes are from pushinbox and not from google i think.</p><p>I have seen somewhere on internet a example via pushingbox, i didn't want to make a account on the pushingbox site so i didn't dig deeply into that. I have not read the articles about pushingbox, mayby has the pushingbox site the right answer for you.</p><p>It is important that your code behave as a webbrowser the only check i now have, is via an URL and that is still working, my Netduino is not anymore connected to internet so i'am not 100% sure that my code still works.I'am only sure the URL typed in the webbrowser is working.</p>
<p>In reply to myself: this is maybe the answer it seems google is using port 443 ssl connection, arduino based boards are not powerfull enough for this kind of connections:</p><p><a href="https://productforums.google.com/forum/#!topic/docs/f4hJKF1OQOw" rel="nofollow">https://productforums.google.com/forum/#!topic/doc...</a></p><p>found via:<br></p><p><a href="https://www.google.nl/?gws_rd=ssl#q=pushingbox+arduino+google+drive" rel="nofollow">https://www.google.nl/?gws_rd=ssl#q=pushingbox+ard...</a></p>
Thanks for the great description :-) Does this still work with Google Drive? Thanks!
Hi cwalger, <br>i have tried it with my code and it still works: <br>spreadsheets.google.com/formResponse?formkey=Here comes your formkey&amp;ifq&amp;entry.0.single=10&amp;entry.1.single=20&amp;entry.2.single=30&amp;entry.3.single=40&amp;pageNumber=0&amp;backupCache=&amp;submit=insturen
Does this still work as of September 2013? I'm trying to follow, but not finding instances to &quot;entry.#.single&quot; in the source coding for the form.
Hi Spaceman, <br>I have looked at it and have make a new form to test i think the idea from above instructable stil works. <br>Look at the form source code find the tag of your field here you find the parameter name=&quot;entry.#&quot; <br># mean a randomnumber(?) generated by googledocs/drive <br>See step 2 of my instructable. I hope i have answered your question?
does it regularly update the data? If so is there a set time for the update?
You decide when to update. <br>When you send data to the spreadsheet it is updated immediately. <br>I hope i answered your question? <br> <br>The netduino in this example sends every minute the data to the spreadsheet. <br>

About This Instructable

36,185views

37favorites

License:

More by morthole:How to use Google docs for data logging Making garden stakes from wine bottle capsules Reuse paper tea bag holders 
Add instructable to: