mbed Weather Platform firmware http://mbed.org/users/okini3939/notebook/mbed-weather-platform-firmware/

Dependencies:   ChaNFSSD EthernetNetIf I2CLEDDisp Agentbed ChaNFSUSB ILinterpreter mbed BMP085 WeatherMeters ConfigFile ChaNFS I2CLCD

Revision:
1:6c7141895545
Parent:
0:bdb53686c194
Child:
2:a3e5edf84f74
--- a/net.cpp	Mon Jul 04 15:16:45 2011 +0000
+++ b/net.cpp	Sun Jul 10 15:36:46 2011 +0000
@@ -1,3 +1,13 @@
+/*
+ * Weather Station - mbed Weather Platform
+ * Copyright (c) 2011 Hiroshi Suga
+ * Released under the MIT License: http://mbed.org/license/mit
+ */
+
+/** @file
+ * @brief Weather Station
+ */
+
 #include "mbed.h"
 #include "weather.h"
 #include "EthernetNetIf.h"
@@ -14,10 +24,16 @@
 #define PACHUBE_URL "http://api.pachube.com/v1/feeds/"
 
 EthernetNetIf *eth; 
-DigitalOut led_g2(p24),led_g(p25), led_y(p26);
+DigitalOut led_gayk(p24),led_gkya(p25), led_yk(p26);
 static DigitalIn eth_link(P1_25), eth_speed(P1_26);
 static volatile int ethernet_flg = 0;
 static HTTPClient *http;
+#ifdef USE_NTP
+static NTPClient ntp;
+#endif
+#ifdef USE_EMAIL
+static SMTPClient smtp;
+#endif
 
 int weatherstations () {
     char post_data[200];
@@ -35,7 +51,7 @@
     pc.printf("S: %s %s\r\n", id, pin);
 #endif
 
-    LED_NET_ON;
+    LED_NET_ACT_ON;
     format_str("d0=%.2P&d1=%.2T&d2=%.2H&d3=%.2A&d4=%.2V&d5=%.2R&d6=%.2L&d7=%.2U&d8=%.2M&d9=%.2p", post_data, sizeof(post_data));
     strcat(post_data, "&fcd=");
     strcat(post_data, chop(id));
@@ -75,7 +91,7 @@
     pc.printf("P: %s %s\r\n", apikey, feedid);
 #endif
 
-    LED_NET_ON;
+    LED_NET_ACT_ON;
     csvContent.set(csv);
     strcpy(uri, PACHUBE_URL);
     strcat(uri, chop(feedid));
@@ -116,7 +132,7 @@
     pc.printf("T: %s %s %s\r\n", user, pwd, tmp);
 #endif
 
-    LED_NET_ON;
+    LED_NET_ACT_ON;
     format_str(tmp, buf, sizeof(buf));
     msg["status"] = buf;
 
@@ -141,7 +157,6 @@
     int port = 25;
     char buf[170], smtphost[40], from[40], to[40], tmp[128];
     char key[40], key2[40];
-    static SMTPClient smtp;
     Host smtpserver;
     EmailMessage msg;
     SMTPResult ret;
@@ -156,7 +171,7 @@
         return -1;
     }
 
-    LED_NET_ON;
+    LED_NET_ACT_ON;
     if (cfg.getValue("SMTPPORT", buf, sizeof(buf))) {
         port = atoi(buf);
     }
@@ -203,14 +218,13 @@
 
 int ntpdate (char *hostname) {
 #ifdef USE_NTP
-    static NTPClient ntp;
     Host ntpserver;
     NTPResult ret;
     time_t sec;
 
     if (! ethernet_flg) return 0;
 
-    LED_NET_ON;
+    LED_NET_ACT_ON;
     ntpserver.setName(hostname);
     ntpserver.setPort(123);
 
@@ -241,12 +255,14 @@
     
     eth_link.mode(PullUp);
     eth_speed.mode(PullUp);
-    led_g = eth_link ? 1 : 0;
-    led_g2 = 1;
-    LED_NET_ON;
 
     if (cfg.getValue("IPADDRESS", buf, sizeof(buf))) {
 
+        if (! eth_link) {
+            LED_NET_G_ON;
+        }
+        LED_NET_ACT_ON;
+
         if (strncmp(buf, "DHCP", 4) == 0) {
             // dhcp ip address
             
@@ -281,6 +297,7 @@
         ethErr = eth->setup();
         if (ethErr) {
             // error
+            LED_NET_Y_ON;
             return -1;
         }
 
@@ -310,12 +327,10 @@
     if (ethernet_flg) {
         Net::poll();
 
-        // ethernet LED green
-        led_g = eth_link ? 1 : 0;
-        led_g2 = 1;
-    } else {
-        // ethernet LED orange
-        led_g = eth_link ? 0 : 1;
-        led_g2 = 0;
+        if (! eth_link) {
+            LED_NET_G_ON;
+        } else {
+            LED_NET_GY_OFF;
+        }
     }
 }