Author Topic: The Dream Machine - II  (Read 9769 times)

0 Members and 1 Guest are viewing this topic.

Offline wxtech

  • Weather Equipment Technician
  • Moderator
  • Forecaster
  • *****
  • Posts: 1681
  • USAF Weather Equipment Maintenance Tech (retired)
    • Lexington, Ga. Weather
The Dream Machine - II
« on: November 23, 2011, 08:51:10 AM »
The Dream Machine - II will use individual sensors communicating by XBee radios.  The Arduino Uno microcontroller connects to an XBee radio and to the host PC via USB and/or an Internet connection using an Ethernet shield.  Several programmable XBee radios form an outside network to allow flexibility in locating the weather sensors.
The XBee radios cost about $21 each and has a range of 30 meters (1 mile for the $40 pro version).  The radios can have a dual function as repeater for distant radios.
I have the parts for this but will concentrate on the VN1 version first.
Al Washington, Lexington, Ga.,  NWS Coop station=LXTG1, Fischer Porter, SRG, MMTS. 
CoCoRaHS=GA-OG-1. CWOP=CW2074.  Davis VP2+ WLIP 5.9.2, VP(original) serial, VWS v15.00 p02. ImageSalsa, Win7 & Win8 all-in-one.

Offline wxtech

  • Weather Equipment Technician
  • Moderator
  • Forecaster
  • *****
  • Posts: 1681
  • USAF Weather Equipment Maintenance Tech (retired)
    • Lexington, Ga. Weather
Re: The Dream Machine - II
« Reply #1 on: November 24, 2011, 08:52:18 AM »
Sketch of ideas while reading Arduino and XBee books.  I forgot to include a display console.
Al Washington, Lexington, Ga.,  NWS Coop station=LXTG1, Fischer Porter, SRG, MMTS. 
CoCoRaHS=GA-OG-1. CWOP=CW2074.  Davis VP2+ WLIP 5.9.2, VP(original) serial, VWS v15.00 p02. ImageSalsa, Win7 & Win8 all-in-one.

Offline AIW

  • Member
  • *
  • Posts: 18
Re: The Dream Machine - II
« Reply #2 on: September 22, 2013, 06:41:38 PM »
I realize that this thread hasn't had any comments in sometime and I'm a new member as of today so just trying to get caught up.

To give you a little background on myself, I have a small business that I started some time ago but just never really did much with it. It was there just in case I got an opportunity to do something that I was interested in. The small business is a side project, but my normal dialy job is as a Senior Electronics Technician for the NWS repair depot in KC. My shop is responsible for all the Upper-Air balloon tracking systems, non-ASOS surface and hydrological equipment including the COOP network.

I have a passion for trying to redesign alot of this old equipment and am currently in the process of trying to take the current NWS min/max temperature system and convert it to a wireless device utilizing a custom config I designed that uses an arduino ATmega2560 processor board (Chip only), a 24 bit ADC w/ 8-Channel mux (for the thermistor reading), and utilizing 900MHz Xbees for the RF link. I'm looking at the option of an ethernet or Wifi connection once I get the info inside the house.

There are a few other projects that I'm working on including a NOAA Weather Radio Receiver / SAME Decoder w/ integrated GPS and data logger.
Very first iteration of just the basics can be seen here. http://forums.adafruit.com/viewtopic.php?f=25&t=35772&p=176822&hilit=weather+radio#p176822

Larger scale version of the radio itself in its initial pprototype form is here.
http://forums.adafruit.com/viewtopic.php?f=25&t=35772&p=176822&hilit=weather+radio#p176822

I did design a consumer breakout for the SI4707 IC receiver SAME decoder here. http://www.aiwindustries.com/products.html

I don't have pictures yet, but I'm also working on an SDI-12 Arduino interface board as well.

My reason for saying all this is that I would be very interested in collaborating on a dream machine if it was still something that enough people were interested in. I don't have all the know how, but enough to give it a go. My vision, at least within my NWS projects is that the NWS will never be in the sensor making business, leave that to the companies with the funds to do the proper R&D and produce those. Building a logger to extract the data from those sensors shouldn't be that hard to do though. Most sensors are either I2C, SPI, Serial, or Analog with a few exceptions. The Arduino will do all of those, so why not harness the open source information available to that platform to build to suit.

 

Offline wxtech

  • Weather Equipment Technician
  • Moderator
  • Forecaster
  • *****
  • Posts: 1681
  • USAF Weather Equipment Maintenance Tech (retired)
    • Lexington, Ga. Weather
Re: The Dream Machine - II
« Reply #3 on: September 22, 2013, 07:07:36 PM »
Thank you for your interest in 'The Wxtech Dream Machine'.  I'm Wxtech.  AKA Al.
My main interest was in building a replacement for the Nimbus max/min temperature system.  I'm a Co-Op in Downtown Lexington, Ga.  LXTG1.
I don't have a lot of confidence in the MMTS and use back up systems to verify the data.  A modern sensor to the display link should be wireless.
Only a few members have shown interest in helping to design a dream machine.  Lately there has been Davis VP & Vue members' ideas/activity using the Arduino, Raspberry Pi, Picaxe, etc.  Our members will jump in and build after a prototype is produced and kit parts with instructions are available.
I have ideas but lost my focus on this project.  We need someone who can rally several of our member builders into a common direction.   
Al
Al Washington, Lexington, Ga.,  NWS Coop station=LXTG1, Fischer Porter, SRG, MMTS. 
CoCoRaHS=GA-OG-1. CWOP=CW2074.  Davis VP2+ WLIP 5.9.2, VP(original) serial, VWS v15.00 p02. ImageSalsa, Win7 & Win8 all-in-one.

Offline AIW

  • Member
  • *
  • Posts: 18
Re: The Dream Machine - II
« Reply #4 on: September 22, 2013, 07:16:01 PM »
Al,
I understand your issues with the NIMBUS. Most of the time the issue doesn't necessarily rest with the sensor itself, but within the way the NIMBUS itself works. The thermistor is actually a fairly precise unit (spec'd to within +/- 0.3 deg C). The NIMBUS however uses a resistance to frequency conversion through a PLL. There are a series of calibration resistors within the device that will typically become out of tolerance over time and therefore cause the drift in readings. They are also highly susceptible to RF interference because of the frequency conversion.

I can't make any promises, but this is the system that I'm redesigning for 900MHz. We'll see how it goes.

Offline wxtech

  • Weather Equipment Technician
  • Moderator
  • Forecaster
  • *****
  • Posts: 1681
  • USAF Weather Equipment Maintenance Tech (retired)
    • Lexington, Ga. Weather
Re: The Dream Machine - II
« Reply #5 on: September 26, 2013, 05:03:46 PM »
A weather station is the most appropriate application for a solar panel.  Voltaic Systems is giving away 5 solar panels in a contest.  http://www.voltaicsystems.com/solar-project-contest.shtml  The contest runs through October 30. 
Design your solar application and enter for the free power.  Good luck.
Al Washington, Lexington, Ga.,  NWS Coop station=LXTG1, Fischer Porter, SRG, MMTS. 
CoCoRaHS=GA-OG-1. CWOP=CW2074.  Davis VP2+ WLIP 5.9.2, VP(original) serial, VWS v15.00 p02. ImageSalsa, Win7 & Win8 all-in-one.

Offline fmbfla

  • Member
  • *
  • Posts: 9
Re: The Dream Machine - II
« Reply #6 on: January 04, 2014, 08:39:28 AM »
Your project looks good to me! :grin:
My idea: 8-)
With an added Adafruit CC3000 WiFi BOB you can have the entire unit enclosed and solar powered, outside and freed from the PC.
I 'm trying to get the uno to hold all the sketch and the uno only has 2 interrupts so currently I have to use  MEGA/ADK (31,550).
once i get it to hold steady on the uploads to Wunderground I will unwire the sensors and hook up the Xbee's
WindDir
Speed (interrupt)
Temp
Humi
Rain  (interrupt)
Baro
The sketch is kinda messy for now as i am still debugging the Hanging issue of periodically stopping
I get any where from zero to 50 Tx to wunderground then poof!

Any input would be appreciated
Code below;

Code: [Select]

/***************************************************
 * This is an example for the Adafruit CC3000 Wifi Breakout & Shield
 *
 * Designed specifically to work with the Adafruit WiFi products:
 * ----> https://www.adafruit.com/products/1469
 *
 * Adafruit invests time and resources providing this open source code,
 * please support Adafruit and open-source hardware by purchasing
 * products from Adafruit!
 *
 * Written by Limor Fried & Kevin Townsend for Adafruit Industries. 
 * BSD license, all text above must be included in any redistribution
 ****************************************************/

/*
This example does a test of the TCP client capability:
 * Initialization
 * Optional: SSID scan
 * AP connection
 * DHCP printout
 * DNS lookup
 * Optional: Ping
 * Connect to website and print out webpage contents
 * Disconnect
 SmartConfig is still beta and kind of works but is not fully vetted!
 It might not work on all networks!
 */
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <Wire.h>
#include <DHT.h>
#include <Adafruit_BMP085.h>
#include "RTClib.h"
//Pins
#define anemometer  2         // Wind speed
//const int rainTip = 3;  // Digital 3, Receive the pulse from Rain HALL EFFECT sensor on pin 3/Interupt 1
#define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
#define DHTPIN  A0            // DHT 22  (AM2302)
#define winDir  A2            // Wind direction
#define WLAN_SSID       "XXXXXXX"           // cannot be longer than 32 characters!
#define WLAN_PASS       "XXXXXXX"
#define WLAN_SECURITY   WLAN_SEC_WPA2
#define IDLE_TIMEOUT_MS  3000      // Amount of time to wait (in milliseconds) with no data
#define ID  "KFLFORTMXX"
#define PASSWORD   "XXXXXXXX"
//#define WEBSITE      "rtupdate.wunderground.com"// RapidFire Server
#define WEBSITE      "weatherstation.wunderground.com"//standard server
#define WEBPAGE      "GET /weatherstation/updateweatherstation.php?"
#define DHTTYPE DHT22             // DHT 22  (AM2302)
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2); // you can change this clock speed
//const char PROGMEM
//WEBSITE []= "weatherstation.wunderground.com",
//WEBPAGE []="GET /weatherstation/updateweatherstation.php?",
//ID []= "KFLFORTMXX",
//PASSWORD [] = "XXXXXX";
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 Wind speed calculations
int period = 5000;          // Measurement period (miliseconds)
int Wait = 2500;          // Amount of Time to wait till Re-connecting
const int radio = 65;             // Radius from vertical anemometer axis to a cup center (mm)


DHT dht(DHTPIN, DHTTYPE);         // DHT 22  (AM2302)
Adafruit_BMP085 bmp;              // BMP Sensor
unsigned int counter = 0;         // pulse count for wind sensor
unsigned int RPM = 0;             // Revolutions per minute
unsigned int Sample = 0;          // Sample number
//unsigned int timesConnected = 0;  // WiFi conections
unsigned int winddir = 0;         // Wind direction
float speedwind = 0 ;      // Wind speed (m/s)
unsigned int maxwind = 0;
//---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
RTC_DS1307 rtc;
uint32_t ip;
void setup(void)
{
    if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
  }

  Wire.begin();
  Serial.begin(115200);
  pinMode(anemometer, INPUT);
  digitalWrite(anemometer, HIGH);
  rtc.begin();
  //rtc.adjust(DateTime(__DATE__, __TIME__));
  Serial.println(F("CC3000 Wunderground Test!\n"));
  dht.begin();// Connect the DHT22 sensor
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
  Serial.println(F("Connected!"));
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
    ip = 0;
  Serial.print(WEBSITE);
  Serial.print(F(" -> "));
  while (ip == 0) {
    if (! cc3000.getHostByName(WEBSITE, &ip)) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }
  cc3000.printIPdotsRev(ip);
  //timesConnected++;
  Serial.println();
}
void loop(void)
{
 
  Sample++;
  float Dew = (dewPoint(dht.readTemperature(2), dht.readHumidity()));
 
  windvelocity();
  RPMcalc();
  WindSpeed();
  Heading();
  if (speedwind > maxwind) {
    maxwind = speedwind;
  }
  //Serial.println();
 
  //Serial.println("attempting to Connect");
 
  //Serial.print(" WiFi Connects ");
  //Serial.println(timesConnected);
  Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
  //Serialprint for debuging HANGS!
  if (client.connected()) {
    Serial.print(" Sample # ");
    Serial.println(Sample);
    //Serial.println("-------------------------------------");
    DateTime now = rtc.now();
  //  Serial.print(WEBSITE);
    client.print("GET /weatherstation/updateweatherstation.php?");
    Serial.println("Sending DATA ");
    client.print("ID=");
  //  Serial.print("ID=");
    client.print(ID);
    //Serial.println(ID);
    client.print("&PASSWORD=");
    client.print(PASSWORD);
  //  Serial.print("&PASSWORD=");
    //Serial.println(PASSWORD);
    client.print("&dateutc=");
  //  Serial.println("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=");
    Serial.print("winddir=");
    client.print(winddir);
    Serial.println(winddir);
    client.print("&windspeedmph=");
    Serial.print("&windspeedmph=");
    client.print(speedwind/0.445);
    Serial.println(speedwind/0.445);
    client.print("&windgustmph=");
    Serial.print("&windgustmph=");
    client.print(maxwind/0.445);
    Serial.println(maxwind/0.445);
    client.print("&rainin=");
    Serial.print("&rainin=");
    client.print("0");
    Serial.println("0");
    client.print("&tempf=");
    Serial.print("&tempf=");
    client.print(dht.readTemperature(2));
    Serial.println(dht.readTemperature(2));
    client.print("&baromin=");
    Serial.print("&baromin=");
    client.print(bmp.readPressure()* 0.0002953);
    Serial.println(bmp.readPressure()* 0.0002953);
    client.print("&dewptf=");
    Serial.print("&dewptf=");
    client.print(Dew);
    Serial.println(Dew);
    client.print("&humidity=");
    client.print(dht.readHumidity());
    Serial.print("&humidity=");
    Serial.println(dht.readHumidity());
    client.print("&action=updateraw");
    //Serial.println("&action=updateraw");
    client.println();
    delay(1);
   
  }

  else {
    Serial.println(F("Connection failed"));   
    return;
  }

  Serial.println("UpLoad Completed!");
 
  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.close();
 // Serial.println("-------------------------------------");
  Serial.print("Waiting ");
  Serial.print(Wait/1000.0);
  Serial.println(" seconds.");
  delay(Wait);// 30sec
  Serial.println();
  //Serial.println("-------------------------------------");

}
void listSSIDResults(void)
{
  uint8_t valid, rssi, sec, index;
  char ssidname[33];

  index = cc3000.startSSIDscan();

  Serial.print(F("Networks found: "));
  Serial.println(index);
  Serial.println(F("================================================"));

  while (index) {
    index--;

    valid = cc3000.getNextSSID(&rssi, &sec, ssidname);

    Serial.print(F("SSID Name    : "));
    Serial.print(ssidname);
    Serial.println();
    Serial.print(F("RSSI         : "));
    Serial.println(rssi);
    Serial.print(F("Security Mode: "));
    Serial.println(sec);
    Serial.println();
  }
  Serial.println(F("================================================"));

  cc3000.stopSSIDscan();
}
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;

  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: "));
    cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: "));
    cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: "));
    cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: "));
    cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: "));
    cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    //timesConnected++;
    return true;
  }
}

void windvelocity(){
  speedwind = 0;
  counter = 0; 
  attachInterrupt(0, addcount, RISING);//anemometer
  unsigned long millis();                     
  long startTime = millis();
  while(millis() < startTime + Wait) {
  }
  detachInterrupt(0);
}

void RPMcalc(){
  RPM=((counter*2)*60)/(period/1000);  // Calculate revolutions per minute (RPM)
}

void WindSpeed(){
  speedwind = ((2 * pi * radio * RPM)/60) / 1000;
}


void addcount(){
  counter++;
}

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);
}


Offline fmbfla

  • Member
  • *
  • Posts: 9
Re: The Dream Machine - II
« Reply #7 on: January 10, 2014, 07:22:35 PM »
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
Code: [Select]



/*
  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);
}





« Last Edit: January 10, 2014, 07:24:39 PM by fmbfla »