You are on page 1of 3

/* Arduino to Google Docs

created 2011
This example code is in the public domain.
http://www.open-electronics.org
http://www.futurashop.it
https://spreadsheets.google.com/formResponse?formkey=dDBMdUx3TmQ5Y2xvX2Z0V183UV
p2U0E6MQ &ifq&entry.0.single=Boris&entry.2.single=Landoni&submit=Submit
Original from http://goodsite.cocolog-nifty.com/uessay/2010/07/arduinogoogle-d.
html
Modified by John Missikos 11/6/11
Modified by Andrea Fainozzi 30/6/11
Modified by Boris Landoni 8/7/11
Modified by Viorel Spinu 2/2/12
*/
#include <Ethernet.h>
#include <SPI.h>
#include <Wire.h>
#include <BMP085.h>
BMP085 bmp085 = BMP085();
long temperatura = 0, presiune = 0, umiditate = 0;

char formkey[] = "dG9HWmNXWjNRdWhBWG5ITlpNeUVBU2c6MQ"; //Replace with your Key


byte mac[] = {
0x90,0xA2,0xDA,0x00,0x55,0x8D}; //Replace with your Ethernet shield MAC
byte ip[] = {
192,168,0,109}; //The Arduino device IP address
byte subnet[] = {
255,255,255,0};
byte gateway[] = {
192,168,0,1};
byte server[] = {
173,194,70,139 }; // Google IP
void setup()
{
Serial.begin(9600);
Wire.begin();
delay(1000);
bmp085.init();
delay(5000);
}
void loop(){
Ethernet.begin(mac, ip , gateway , subnet);
delay(1000);
Serial.println("connecting...");
Client client(server, 80);
bmp085.getTemperature(&temperatura);
bmp085.getPressure(&presiune);

int sensorValue = analogRead(0);


float voltage = sensorValue/1023. * 5;
// ecuatia de mai jos este obtinuta din datasheet-ul lui HIH-4030/31
float sensorRH = 161.*voltage/5 - 25.8;
float trueRH = sensorRH / (1.0546 - 0.0026 * temperatura / 10);
umiditate = (int) trueRH;

String data;
data+="";
data+="entry.2.single=";
data+=temperatura;
data+="&entry.3.single=";
data+=presiune;
data+="&entry.4.single=";
data+=umiditate;
data+="&submit=Submit";
if (client.connect()) {
Serial.println("connected");
client.print("POST /formResponse?formkey=");
client.print(formkey);
client.println("&ifq HTTP/1.1");
client.println("Host: spreadsheets.google.com");
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("POST /formResponse?formkey=");
Serial.print(formkey);
Serial.println("&ifq HTTP/1.1");
Serial.println("Host: spreadsheets.google.com");
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();
}
while (client.available()) {
char c = client.read();
Serial.print(c);
}
delay(15000);
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}

delay(5000);
}