I made a simple Google Doc Form that feeds my spreadsheet, and then I make one POST request to that form to add data. It even timestamps the entry. Here is an example of a POST request. The form that this is linked to has two text boxes for collecting data. Replace <ENTER_YOUR_KEY_HERE> with the key to your spreadsheet. And replace <DATA1> and <DATA2> with the data values that you want.
entry.0.single and entry.1.single are the names of the textboxes on the form, I think the names are standardized this way. Anyway you can read the source of the form and get the names.
- Code: Select all
POST https://spreadsheets.google.com/formResponse?formkey=<ENTER_YOUR_KEY_HERE>&ifq HTTP/1.1
Host: spreadsheets.google.com
Content-Type:application/x-www-form-urlencoded
Content-Length:75
entry.0.single=<DATA1>&entry.1.single=<DATA2>&pageNumber=0&backupCache=&submit=Submit
I used the code that GregEigsti wrote in this thread for the post request:
viewtopic.php?f=15&t=86&start=10
Currently the code is sending hardcoded values, but it will be trivial to change this to some actual data.
- Code: Select all
/*
* A simple sketch that uses WiServer to PUT (via POST) to GoogleDocs
*/
#include <WiServer.h>
//Wireless configuration defines ----------------------------------------
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
#define DEBUG_PRINT
//Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,2,100}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,2,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"xxxxxx"}; // max 32 bytes
unsigned char security_type = 2; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"xxxxxx"}; // max 64 characters
// WEP 128-bit keys
prog_uchar wep_keys[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Key 3
// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------
//global state data
boolean loop_cnt = 0;
// IP Address for spreadsheets.google.com
uint8 ip[] = {74,125,67,102};
char hostName[] = "spreadsheets.google.com\nContent-Type:application/x-www-form-urlencoded";
char url[] = "/formResponse?formkey=INSERT_KEY_HERE";
// A request that POSTS data to GoogleDocs
POSTrequest postGoogleDocs(ip, 80, hostName, url, feedData);
// Function that prints data from the server
void printData(char* data, int len) {
// Print the data returned by the server
// Note that the data is not null-terminated, may be broken up into smaller packets, and
// includes the HTTP header.
#ifdef DEBUG_PRINT
while (len-- > 0) {
Serial.print(*(data++));
}
#endif //DEBUG_PRINT
}
//body data function, provides data for the POST command in comma separated values (CSV)
//currently POSTs one value but more can be added by separating with comma (no spaces)
//Your program will not want to use the hardcoded values below, rather it would read the
//sensor(s) and build the data string shown below.
void feedData()
{
char buf[] = "entry.0.single=9999&entry.1.single=9999&pageNumber=0&backupCache=&submit=Submit";
WiServer.print(buf);
}
void setup()
{
// Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages)
WiServer.init(NULL);
// Enable Serial output and ask WiServer to generate log messages (optional)
#ifdef DEBUG_PRINT
Serial.begin(9600);
//WiServer.enableVerboseMode(true);
#endif //DEBUG_PRINT
// Have the processData function called when data is returned by the server
postGoogleDocs.setReturnFunc(printData);
loop_cnt = 0;
}
void loop()
{
if(loop_cnt == 0){
postGoogleDocs.submit();
loop_cnt++;
}
// Run WiServer
WiServer.server_task();
delay(10);
}
Anyway I thought this was pretty cool, and I couldn't find anything similar. This is my first Arduino project as well, it is a fun platform. Let me know if you have any advice or criticism.