Weather Alert System

Fork of WeatherMeters by Suga koubou

Files at this revision

API Documentation at this revision

Comitter:
yongqiangwang
Date:
Mon Apr 29 23:39:45 2013 +0000
Parent:
2:6a62f29b1bb5
Commit message:
Weather Alert System

Changed in this revision

WeatherMeters.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/WeatherMeters.cpp	Fri Jun 03 14:34:54 2011 +0000
+++ b/WeatherMeters.cpp	Mon Apr 29 23:39:45 2013 +0000
@@ -15,6 +15,10 @@
 
 #define WEATHER_VREF 3.3
 
+
+DigitalOut rain(LED2);
+DigitalOut test(LED3);
+
 const float tbl_windvane[16][2] = {
   {0.0, 33000}, {22.5, 6570}, {45.0, 8200}, {67.5, 891},
   {90.0, 1000}, {112.5, 688}, {135.0, 2200}, {157.5, 1410},
@@ -100,6 +104,16 @@
 }
 
 void WeatherMeters::int_raingauge () {
+    if (rain == 1)
+    {
+        rain = 0;
+        wait (0.1);
+    }
+    else 
+    {
+        rain = 1;
+        wait (0.1);
+    }   
     count_rain ++;
 }
 
@@ -124,16 +138,30 @@
     }
     
     time_rain ++;
-    if (time_rain >= 4 * 300) {
+    if (time_rain >= 100) {
         n = 0;
         for (i = 11; i > 0; i --) {
             buf_rain[i] = buf_rain[i - 1];
             n = n + buf_rain[i];
+            
         }
         buf_rain[0] = count_rain;
         n = n + buf_rain[0];
+      
+     
         count_rain = 0;
         time_rain = 0;
         raingauge = n;
     }
+    
+      if (test == 1)
+            {
+                test  = 0;
+                wait (0.2);
+            }
+            else
+            { 
+                test = 1;
+                wait (0.2);
+             }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Apr 29 23:39:45 2013 +0000
@@ -0,0 +1,91 @@
+#include "mbed.h"
+#include "SCP1000.h"
+#include "SHTx/sht15.hpp"
+#include "WeatherMeters.h"
+ 
+Serial Xbee1(p13, p14);
+DigitalOut rst1(p16);
+
+SCP1000 scp1000(p5,p6,p7,p17);
+
+SHTx::SHT15 sensor(p28, p27);
+
+AnalogIn ain(p20);
+DigitalOut busy(LED1);
+
+Serial pc(USBTX, USBRX);
+
+WeatherMeters station(p8, p15, p10, Weather_auto);
+
+float w_speed = 0.0;
+float w_direction = 0.0;
+float w_raingauge = 0.0;
+
+char a = 'T';
+char data[15];
+ 
+void xbeesend(float x)
+{
+    sprintf(data, "%5.1f", x);
+        
+    int i = 0;
+    while (data[i] != NULL)
+    {
+        Xbee1.putc(data[i]);
+        i++;
+    }
+
+    Xbee1.putc (' ');
+}
+ 
+int main() {
+
+    rst1 = 0;   //Set reset pin to 0
+    wait_ms(1);
+    rst1 = 1;   //Set reset pin to 1
+    wait_ms(1);
+   
+    while(1) {               
+              
+        w_speed = station.get_windspeed();
+        w_direction = station.get_windvane();
+        w_raingauge = station.get_raingauge();
+        
+        pc.printf("Wind speed: %4.1f m/s\r\n", w_speed);
+        Xbee1.putc ('S');
+        xbeesend (w_speed);
+        
+        pc.printf("Wind direction: %4.0f\r\n", w_direction);
+        xbeesend (w_direction);
+        
+        pc.printf("Rain Gauge: %4.1f\r\n\n", w_raingauge);
+        xbeesend (w_raingauge);
+     
+        
+        busy = true;
+        sensor.update();
+        busy = false;     
+        
+        sensor.setOTPReload(false);
+        sensor.setResolution(true);
+ 
+        sensor.setScale(false);
+        pc.printf("Temperature [ %3.1f C ]\r\n", sensor.getTemperature());
+
+        xbeesend (sensor.getTemperature());
+        
+        pc.printf("Humdity     [ %3.1f %% ]\r\n\n", sensor.getHumidity());
+        xbeesend (sensor.getHumidity());
+       
+        pc.printf("The pressure is %d Pa \r\n\n", scp1000.readPressure());
+        xbeesend (scp1000.readPressure());
+        
+        pc.printf("Sun light intensity is %3.1f %%\r\n\n", ain * 100);
+        xbeesend (ain * 100);
+        
+        Xbee1.putc ('@');
+
+        wait(5);
+    }
+}
+