Sei sulla pagina 1di 6

#include <SoftwareSerial.

h>
SoftwareSerial gprsSerial(7, 8);
void setup()
{
gprsSerial.begin(19200);
Serial.begin(19200);
Serial.println("Config SIM900...");
delay(2000);
Serial.println("Done!...");
gprsSerial.flush();
Serial.flush();
// attach or detach from GPRS service
gprsSerial.println("AT+CGATT?");
delay(100);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"epc.tmobile.com\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=1,1");
delay(2000);
toSerial();
}
void loop()
{
// initialize http service
gprsSerial.println("AT+HTTPINIT");
delay(2000);
toSerial();
// set http param value
gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://YOUR.DOMAIN.COM/rest/receiveS
ensorData?sensorval1=blah&sensorval2=blah\"");
delay(2000);
toSerial();
// set http action type 0 = GET, 1 = POST, 2 = HEAD
gprsSerial.println("AT+HTTPACTION=0");
delay(6000);
toSerial();
// read server response
gprsSerial.println("AT+HTTPREAD");
delay(1000);
toSerial();

gprsSerial.println("");
gprsSerial.println("AT+HTTPTERM");
toSerial();
delay(300);
gprsSerial.println("");
delay(10000);
}
void toSerial()
{
while(gprsSerial.available()!=0)
{
Serial.write(gprsSerial.read());
}
}

Just change "epc.tmobile.com" to the apn for your carrier and


"YOUR.DOMAIN.COM" to your server info and change the "sensorval1=blah" to
your variable and sensor data.
Let me know if you get this working or not. I can help you figure it out it's not too
hard.
Good Luck.

https://spreadsheets.google.com/formResponse?formkey=YOUR FORM KEY &ifq&


YOUR ENTRY =THE VALUE TO STORE &submit=Submit
https://spreadsheets.google.com/formResponse?
formkey=dDBMdUx3TmQ5Y2xvX2Z0V183UVp2U0E6MQ
&ifq&entry.0.single=Boris&entry.2.single=Landoni&submit=Submit

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <dht11.h>

#undef int
#undef abs
#undef double
#undef float
#undef round
dht11 DHT11;
#define DHT11PIN 3

///////////////////////////////
///

EDIT THIS STUFF

//

///////////////////////////////

byte mac[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; //Replace with your
Ethernet shield MAC
byte ip[] = {123,456,7,890};

// Your Arduino device IP address

char devid = v42FE15BC09B20df // THIS IS THE DEVICE ID FROM


PUSHINGBOX

int del=300; // Amount of seconds delay between posting to google docs.

///////////////////////////////

//

DONE EDITING

//

///////////////////////////////

char postmsg[100];
int k=0;
int temp_av = 0;
char server[] = "api.pushingbox.com";
EthernetClient client;

void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
delay(1000);
Serial.println("connecting...");
}

void loop(){

// average temp reading for 'del' time.........................................

for(int j=0; j<del;j++)


{
// Read local temp........................................
int chk = DHT11.read(DHT11PIN);
int temp = Fahrenheit(DHT11.temperature);
temp_av=temp_av+temp;
delay(1000);
}

int avtemp=temp_av/(del);
temp_av=0;

// Post to Google Form.............................................


if (client.connect(server, 80))
{
k=0;
Serial.println("connected");
sprintf(postmsg,"GET /pushingbox?devid=%c&status=%d
HTTP/1.1",devid,avtemp); // NOTE** In this line of code you can see where
the temperature value is inserted into the wed address. It follows 'status='
Change that value to whatever you want to post.
client.println(postmsg);
client.println("Host: api.pushingbox.com");
client.println("Connection: close");
client.println();

Serial.println(postmsg);

Serial.println("Host: api.pushingbox.com");
Serial.println("Connection: close");
Serial.println();

delay(1000);
client.stop();
}
delay(1000);

if (!client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
k==1;
return;
}

double Fahrenheit(double celsius) // Function to convert to Fahrenheit


{
return 1.8 * celsius + 32;
}

Potrebbero piacerti anche