this is the code for an ARDUINO UNO with the Ethernet Shield.
Binary sketch size: 25,866 bytes (of a 32,256 byte maximum)
This code werks flawless and sends data as expected continuously
/*
Web client
This sketch connects to a website (http://www.rtupdate.wunderground.com)
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen
**
**
**modified By the drunkin programer
*/
#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <DHT.h>
#include <Adafruit_BMP085.h>
#include <RTClib.h>
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//IPAddress server(38,102,137,157); // numeric IP for wunderground.com
char server[] = "rtupdate.wunderground.com"; // name address for pachube API
char WEBSITE [] = "rtupdate.wunderground.com";// RapidFire Server
//char WEBSITE [] = "weatherstation.wunderground.com";//standard server
char WEBPAGE [] = "GET /weatherstation/updateweatherstation.php?";
char ID [] = "KFLFORTM63";
char PASSWORD [] = "XXXXXXXXXXXX";
const float pi = 3.14159265; // pi, not apple, not pumpkin, not pizza, not even related to Raspberry Pi. http://www.raspberrypi.org/ This is the REAL PI for RPM/Wind speed calculations
float speedwind = 0/ 0.445 ; // Wind speed (m/s)
//Pins
int rainTip = 3; // Notification of SENDING DATA
int winDir = 2; // pin A2 Wind direction
int anemometer = 2; // D2 Wind speed
int DHTPIN = A0;
// Radius from vertical anemometer axis to a cup center (mm)
int radio = 60;
// (changing "Wait")changes the windspeed calculation "period" automaticly
const unsigned long Wait = 1500; // Amount of Time to wait till Re-connecting, Changing this also
const unsigned long period = Wait * 2; // Measurement period (miliseconds)
const unsigned long IDLE_TIMEOUT_MS = 500;
unsigned int counter = 0; // pulse count for wind sensor
unsigned int RPM = 0; // Revolutions per minute
unsigned int Sample = 0; // Sample number
unsigned int connections = 0; // number of connections
unsigned int winddir = 0; // Wind direction
unsigned int rainCount = 0; // counter for Rain
DHT dht(DHTPIN, DHTTYPE); // DHT 22 (AM2302)
Adafruit_BMP085 bmp; // BMP Sensor
RTC_DS1307 rtc;
//---DEWPOINT
double dewPoint(double tempf, double Humi)
{
double A0= 373.15/(273.15 + tempf);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * Humi;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}//---DEWPOINT
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(192,168,1,109);
// initialize the library instance:
EthernetClient client;
void setup(void)
{
Serial.begin(115200);
attachInterrupt(1, addrain, RISING); // Read the Rain tips constantly
//Wire.begin();
rtc.begin();
rtc.adjust(DateTime(__DATE__, __TIME__));
bmp.begin();
pinMode(anemometer, INPUT);
digitalWrite(anemometer, HIGH);
pinMode(rainTip, INPUT);
digitalWrite(rainTip, HIGH);
Serial.println(F(" Wunderground Test!\n"));
dht.begin();// Connect the DHT22 sensor
Serial.println(F("\nInitializing..."));
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// DHCP failed, so use a fixed IP address:
Ethernet.begin(mac, ip);
}
Serial.println("Ready!");
}
void loop(void)
{
DateTime now = rtc.now();
Serial.print(now.year());
Serial.print('/');
Serial.print(now.month());
Serial.print('/');
Serial.print(now.day());
Serial.print(' ');
Serial.print(now.hour());
Serial.print(':');
Serial.print(now.minute());
Serial.print(':');
Serial.print(now.second());
Serial.println();
//rain();
Sample ++;
windvelocity();
RPMcalc();
WindSpeed();
Heading();
float tempf = dht.readTemperature(2); //Calc *F
float Humi = dht.readHumidity();
float baromin = bmp.readPressure()* 0.0002953;// Calc for inHg
float maxwind = 0 / 0.445; //Calc for MPH
float Dew = (dewPoint(dht.readTemperature(2), dht.readHumidity()));
if (speedwind > maxwind) {
maxwind = speedwind;
}
if (client.connect(server, 80)) {
Serial.println("Sending DATA ");
client.print("GET /weatherstation/updateweatherstation.php?");
client.print("ID=");
client.print(ID);
client.print("&PASSWORD=");
client.print(PASSWORD);
client.print("&dateutc=");
client.print(now.year());
client.print("-");
client.print(now.month());
client.print("-");
client.print(now.day());
client.print("+");
client.print(now.hour()+ 5);
client.print("%3A");
client.print(now.minute()+ 2);
client.print("%3A");
client.print(now.second());
client.print("&winddir=");
client.print(winddir);
client.print("&windspeedmph=");
client.print(speedwind);
client.print("&windgustmph=");
client.print(maxwind);
client.print("&rainin=");
client.print(rainCount / 2 / 100.0);
client.print("&tempf=");
client.print(tempf);
client.print("&baromin=");
client.print(baromin);
client.print("&dewptf=");
client.print(Dew);
client.print("&humidity=");
client.print(Humi);
//client.print("&action=updateraw");//Standard update
client.print("&action=updateraw&realtime=1&rtfreq=2.5");//Rapid Fire
client.println();
/* Serial.println();
Serial.print("Posting Sample # ");
Serial.print(Sample);
Serial.print(" TO: HTTP://");
Serial.println(WEBSITE);
Serial.print("ID=");
Serial.print(ID);
Serial.print("&PASSWORD= ");
Serial.println(PASSWORD);
Serial.print("wind dir= ");
Serial.print("wind dir= ");
Serial.println(winddir);
Serial.print("windspeed mph= ");
Serial.println(speedwind);
Serial.print("windgust mph= ");
Serial.println(maxwind);
Serial.print("rain in= ");
Serial.println(rainCount / 2 / 100.0);
Serial.print("tempf= ");
Serial.println(tempf);
Serial.print("baro= ");
Serial.println(baromin);
Serial.print("dew point= ");
Serial.println(Dew);
Serial.print("humidity= ");
Serial.println(Humi);
Serial.println();
*/
}
else {
Serial.println(F("Connection failed"));
return;
}
Serial.println("-------------------------------------");
Serial.println("Server Responce!");
unsigned long lastRead = millis();
while (client.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
while (client.available()) {
char c = client.read();
Serial.print(c);
lastRead = millis();
}
}
client.stop();
Serial.println();
Serial.print("Waiting ");
Serial.print(Wait*2/1000.0);
Serial.println(" seconds.");
delay(Wait);// 30sec
Serial.println();
Serial.println("-------------------------------------");
}
void windvelocity(){
speedwind = 0;
counter = 0;
attachInterrupt(0, addcount, CHANGE);//anemometer
unsigned long millis();
long startTime = millis();
while(millis() < startTime + period) {
}
detachInterrupt(0);
}
void RPMcalc(){
RPM=((counter*4)*60)/(period/1000); // Calculate revolutions per minute (RPM)
}
void WindSpeed(){
speedwind = ((2 * pi * radio * RPM)/60) / 1000;
}
void addcount(){
counter++;
}
// save the tips and add them up
void addrain(){
rainCount++;
}
void Heading(){
analogRead(winDir)* 5.00 / 1023.0;//Wind direction, Tweek the voltage returns below to match your resistor
if ((winDir > 4.94)||(winDir < 0.01))
(winddir = 0);
if ((winDir >= 0.02)&&(winDir < 0.30))
(winddir = 22.5);
if ((winDir >= 0.31)&&(winDir < 0.72))
(winddir = 45);
if ((winDir >= 0.72)&&(winDir < 0.99))
(winddir= 67.5);
if ((winDir >= 1.00)&&(winDir < 1.25))
(winddir = 90);
if ((winDir >= 1.26)&&(winDir < 1.52))
(winddir= 112.5);
if ((winDir >= 1.53)&&(winDir < 1.91))
(winddir= 135);
if ((winDir >= 1.92)&&(winDir < 2.40))
(winddir = 157.5);
if ((winDir >= 2.41)&&(winDir < 2.73))
(winddir = 180);
if ((winDir >= 2.74)&&(winDir < 2.96))
(winddir = 202.5);
if ((winDir >= 2.97)&&(winDir < 3.37))
(winddir = 225);
if ((winDir >= 3.38)&&(winDir < 3.55))
(winddir = 247.5);
if ((winDir >= 3.56)&&(winDir < 3.85))
(winddir = 270);
if ((winDir >= 4.13)&&(winDir < 4.06))
(winddir = 292.5);
if ((winDir >= 4.07)&&(winDir < 4.32))
(winddir = 315);
if ((winDir >= 4.33)&&(winDir < 4.93))
(winddir = 337.5);
}