1515 * Analog sensor attached to analog in 0
1616 * Wifi shield attached to pins 10, 11, 12, 13
1717
18- created 4 March 2012
18+ created 9 March 2012
1919 by Tom Igoe
2020
2121 This code is in the public domain.
2222
2323 */
24-
2524#include < SPI.h>
2625#include < WiFi.h>
2726
28-
2927#define APIKEY " YOUR API KEY GOES HERE" // replace your pachube api key here
30- #define FEEDID 00000 // replace your feed ID
31- #define USERAGENT " My Project" // user agent is the project name
28+ #define FEEDID 00000 // replace your feed ID
29+ #define USERAGENT " My Project" // user agent is the project name
3230
33- char ssid[] = " yourNetwork" ; // your network SSID (name)
31+ char ssid[] = " yourNetwork" ; // your network SSID (name)
3432char pass[] = " secretPassword" ; // your network password
3533int status = WL_IDLE_STATUS;
3634
3735// initialize the library instance:
3836WiFiClient client;
37+ IPAddress server (216 ,52 ,233 ,122 );
38+ // char server[] = "api.pachube.com";
3939
40- long lastConnectionTime = 0 ; // last time you connected to the server, in milliseconds
41- boolean lastConnected = false ; // state of the connection last time through the main loop
42- const int postingInterval = 10000 ; // delay between updates to Pachube.com
40+ unsigned long lastConnectionTime = 0 ; // last time you connected to the server, in milliseconds
41+ boolean lastConnected = false ; // state of the connection last time through the main loop
42+ const unsigned long postingInterval = 10 * 1000 ; // delay between updates to Pachube.com
4343
4444void setup () {
4545 Serial.begin (9600 );
@@ -93,7 +93,7 @@ void loop() {
9393// this method makes a HTTP connection to the server:
9494void sendData (int thisData) {
9595 // if there's a successful connection:
96- if (client.connect (" www.pachube.com " , 80 )) {
96+ if (client.connect (server , 80 )) {
9797 Serial.println (" connecting..." );
9898 // send the HTTP PUT request:
9999 client.print (" PUT /v2/feeds/" );
@@ -119,8 +119,6 @@ void sendData(int thisData) {
119119 client.print (" sensor1," );
120120 client.println (thisData);
121121
122- // note the time that the connection was made:
123- lastConnectionTime = millis ();
124122 }
125123 else {
126124 // if you couldn't make a connection:
@@ -129,6 +127,8 @@ void sendData(int thisData) {
129127 Serial.println (" disconnecting." );
130128 client.stop ();
131129 }
130+ // note the time that the connection was made:
131+ lastConnectionTime = millis ();
132132 lastConnected = client.connected ();
133133}
134134
@@ -160,7 +160,7 @@ void printWifiStatus() {
160160
161161 // print your WiFi shield's IP address:
162162 IPAddress ip = WiFi.localIP ();
163- Serial.print (" IP Address: " );
163+ Serial.print (" IP Address: " );
164164 Serial.println (ip);
165165
166166 // print the received signal strength:
@@ -169,8 +169,3 @@ void printWifiStatus() {
169169 Serial.print (rssi);
170170 Serial.println (" dBm" );
171171}
172-
173-
174-
175-
176-
0 commit comments