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, committed 2011-07-10
- Comitter:
- okini3939
- Date:
- Sun Jul 10 15:36:46 2011 +0000
- Parent:
- 0:bdb53686c194
- Child:
- 2:a3e5edf84f74
- Commit message:
Changed in this revision
--- a/ILinterpreter/ILinterpreter.cpp Mon Jul 04 15:16:45 2011 +0000 +++ b/ILinterpreter/ILinterpreter.cpp Sun Jul 10 15:36:46 2011 +0000 @@ -1,3 +1,9 @@ +/* + * Instruction List interpreter library + * Copyright (c) 2011 Hiroshi Suga + * Released under the MIT License: http://mbed.org/license/mit + */ + /** @file * @brief Instruction List interpreter */ @@ -414,7 +420,7 @@ fclose(fp); - return 0; + return il_count; } int ILinterpreter::push (int dat) {
--- a/ILinterpreter/ILinterpreter.h Mon Jul 04 15:16:45 2011 +0000 +++ b/ILinterpreter/ILinterpreter.h Sun Jul 10 15:36:46 2011 +0000 @@ -1,3 +1,9 @@ +/* + * Instruction List interpreter library + * Copyright (c) 2011 Hiroshi Suga + * Released under the MIT License: http://mbed.org/license/mit + */ + /** @file * @brief Instruction List interpreter */
--- a/display.cpp Mon Jul 04 15:16:45 2011 +0000 +++ b/display.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" #ifdef USE_DISPLAY @@ -75,13 +85,19 @@ if (lcd == NULL) return -1; lcd_flg = 1; - strncpy(leddisp_buf, VERSION, sizeof(leddisp_buf)); +#ifdef DEBUG + printf("LCD: %s\r\n", buf); +#endif } if (cfg.getValue("LEDDISP_MESG", buf, sizeof(buf))) { leddisp = new I2CLEDDisp(i2c); if (leddisp == NULL) return -1; leddisp_flg = 1; + strncpy(leddisp_buf, VERSION, sizeof(leddisp_buf)); +#ifdef DEBUG + printf("LED disp: %s\r\n", buf); +#endif } #endif
--- a/file.cpp Mon Jul 04 15:16:45 2011 +0000 +++ b/file.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 "SDHCFileSystem.h" @@ -7,7 +17,7 @@ static SDFileSystem sd(p5, p6, p7, p8, "sd"); static LocalFileSystem *local; static MSCFileSystem *usb; -static DigitalIn sd_cd(p21); +static DigitalIn sd_ins(p27); ConfigFile cfg; static char filename[30] = ""; @@ -15,6 +25,9 @@ FILE *fp; if (filename[0] == 0) return 0; +#ifdef USE_SD_INS + if (sd_ins != 0) return -1; +#endif LED_FILE_ON; fp = fopen(filename, "a"); @@ -34,6 +47,7 @@ char buf[128], buf2[10] = ""; FILE *fp; + if (cfg.getValue("FILE", buf, sizeof(buf))) { if (strncmp(buf, "SD", 2) == 0) { @@ -73,9 +87,17 @@ int init_conf () { +#ifdef USE_SD_INS + sd_ins.mode(PullUp); +#endif + // load config LED_FILE_ON; +#ifdef USE_SD_INS + if (sd_ins == 0 && cfg.read("/sd/" CONFIG_FILE)) { +#else if (cfg.read("/sd/" CONFIG_FILE)) { +#endif // from sd LED_FILE_OFF;
--- a/ilip.cpp Mon Jul 04 15:16:45 2011 +0000 +++ b/ilip.cpp Sun Jul 10 15:36:46 2011 +0000 @@ -1,6 +1,13 @@ +/* + * Weather Station - mbed Weather Platform + * Copyright (c) 2011 Hiroshi Suga + * Released under the MIT License: http://mbed.org/license/mit + */ + /** @file - * @brief mbed Weather Platform + * @brief Weather Station */ + #include "mbed.h" #include "weather.h" #ifdef USE_IL @@ -9,7 +16,11 @@ static ILinterpreter ilip; #endif static Serial xbee(p13, p14); -static volatile int measure_flg = 0; +static volatile int measure_flg = 0, exinout_flg = 0; +#ifdef USE_EXINOUT +static DigitalIn *exin1, *exin2; +static DigitalOut *exout1, *exout2; +#endif #ifdef USE_IL // input relay @@ -113,9 +124,10 @@ } break; - case 'X': // XBee + case 'B': // XBee if (mne == MNE_OUT && reg) { xbee.printf(csv); + xbee.printf("\r\n"); } break; @@ -142,9 +154,13 @@ measure_flg = enable; +#ifdef USE_EXINOUT // set input -// sensor.input[0] = conf.inputtype ? *aimoist > 0.5 : 0; -// sensor.input[1] = swin2; + if (exinout_flg) { + sensor.input[0] = *exin1 ? 0 : 1; + sensor.input[1] = *exin2 ? 0 : 1; + } +#endif sensor_tmp = sensor; @@ -161,26 +177,46 @@ } #endif +#ifdef USE_EXINOUT // set output -// led3 = swout1 = sensor.output[0]; -// led4 = swout2 = sensor.output[1]; + if (exinout_flg) { + *exout1 = sensor.output[0]; + *exout2 = sensor.output[1]; + } +#endif sensor_old = sensor_tmp; } // init IL int init_ilip (char *dir) { + int r; char buf[40]; if (cfg.getValue("XBEE", buf, sizeof(buf))) { xbee.baud(atoi(chop(buf))); } +#ifdef USE_EXINOUT + if (cfg.getValue("INPUT", buf, sizeof(buf))) { + if (atoi(buf) == INPUT_EXINOUT) { + exout1 = new DigitalOut(p30); + exout2 = new DigitalOut(p29); + exin1 = new DigitalIn(p18); + exin1->mode(PullUp); + exin2 = new DigitalIn(p19); + exin2->mode(PullUp); + exinout_flg = 1; + } + } +#endif + #ifdef USE_IL strcpy(buf, dir); strcat(buf, IL_FILE); - if (! ilip.load(buf)) { - pc.printf("IL load %s\r\n", buf); + r = ilip.load(buf); + if (r > 0) { + pc.printf("IL load: %d\r\n", r); ilip.attach(cb_input, cb_output); } #endif
--- a/main.cpp Mon Jul 04 15:16:45 2011 +0000 +++ b/main.cpp Sun Jul 10 15:36:46 2011 +0000 @@ -1,12 +1,25 @@ +/* + * 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" const char VERSION[] = "mbed Weather Platform 0.4.0 (C) 2011 Suga koubou"; Serial pc(USBTX, USBRX); DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); +#ifdef USE_3LED +DigitalOut led_red(p28), led_yellow(p23); +#endif static volatile int interval = 60; char csv[120]; -static char csv_mesg[120] = "%y-%m-%d %h:%i:%s,%.2P,%.2T,%.2H,%.2A,%.2V,%.2R,%.2L,%.2U,%.2M,%.2p\r\n"; +static char csv_mesg[120] = "%y-%m-%d %h:%i:%s,%.2P,%.2T,%.2H,%.2A,%.2V,%.2R,%.2L,%.2U,%.2M,%.2p"; // Interrupt 10Hz @@ -18,7 +31,7 @@ pool_ilip(); pool_display(); - LED_NET_OFF; + LED_NET_ACT_OFF; } void init () { @@ -70,7 +83,9 @@ // create CSV format_str(csv_mesg, csv, sizeof(csv)); pc.printf(csv); + pc.printf("\r\n"); write_log(csv); + update_display(); // in/out exec_ilip(1);
--- 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; + } } }
--- a/sensor.cpp Mon Jul 04 15:16:45 2011 +0000 +++ b/sensor.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 "BMP085.h" @@ -14,9 +24,9 @@ static AnalogIn ailight(p16), aiuv(p17); static AnalogIn *aimoist; static InterruptIn *intin; -static volatile int count_counter; -static volatile unsigned long lastCountTime; -static volatile int inputtype; +static volatile int count_counter = 0; +static volatile unsigned long lastCountTime = 0; +static volatile enum eINPUTTYPE inputtype = INPUT_MOIST; float get_light (AnalogIn &ain) { float f; @@ -86,12 +96,13 @@ sensor.light = get_light(ailight); sensor.uv = get_uv(aiuv); - if (inputtype) { + if (inputtype == INPUT_MOIST) { + // moist sensor + sensor.moist = get_moist(*aimoist); + } else + if (inputtype == INPUT_MOIST) { // counter sensor.moist = get_counter(inputtype & INPUT_CPM ? 0 : 1); - } else { - // moist sensor - sensor.moist = get_moist(*aimoist); } return 0; @@ -108,13 +119,15 @@ // moist sensor or counter if (cfg.getValue("INPUT", buf, sizeof(buf))) { // counter - inputtype = atoi(buf); - intin = new InterruptIn(p18); - if (inputtype & INPUT_FALL) { + inputtype = (eINPUTTYPE)atoi(buf); + if (inputtype & (INPUT_FALL|INPUT_RISE)) { intin->fall(&isr_counter); - } - if (inputtype & INPUT_RISE) { - intin->rise(&isr_counter); + if (inputtype & INPUT_FALL) { + intin = new InterruptIn(p18); + } + if (inputtype & INPUT_RISE) { + intin = new InterruptIn(p18); + } } } else { // moist @@ -155,6 +168,7 @@ flg = fmt[i + 1] - '0'; i ++; + // next char c = fmt[i + 1]; i ++; } @@ -189,7 +203,7 @@ value = sensor.moist; break; case 'p': - value = sensor.temp; + value = sensor.temp2; break; case 'y': @@ -241,6 +255,14 @@ j ++; continue; + case 'n': + buf[j] = '\n'; + j ++; + continue; + case 'r': + buf[j] = '\r'; + j ++; + continue; default: buf[j] = c; j ++;
--- a/snmp.cpp Mon Jul 04 15:16:45 2011 +0000 +++ b/snmp.cpp Sun Jul 10 15:36:46 2011 +0000 @@ -5,6 +5,7 @@ * Agentuino SNMP Agent Library Prototyping... * Copyright 2010 Eric C. Gionet <lavco_eg@hotmail.com> */ + #include "mbed.h" #include "EthernetNetIf.h" #include "weather.h"
--- a/weather.h Mon Jul 04 15:16:45 2011 +0000 +++ b/weather.h Sun Jul 10 15:36:46 2011 +0000 @@ -1,8 +1,20 @@ +/* + * 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 "ConfigFile.h" #include "EthernetNetIf.h" -#undef DEBUG +#define DEBUG + +#define PCB_LOT 0 // PCB version 0:i, 1:ro, 2:ha #define USE_IL // IL interpreter #undef USE_DISPLAY // I2C LCD, LED display module @@ -10,6 +22,12 @@ #undef USE_SNMP // SNMP Agent #undef USE_EMAIL // send mail +#if PCB_LOT >= 1 +#define USE_3LED // 3 leds level meter +#define USE_SD_INS // SD card insert sw +#define USE_EXINOUT // 2 input, 2 output +#endif + #define CONFIG_FILE "weather.cfg" #define IL_FILE "weather.asm" @@ -27,14 +45,18 @@ #define LED_BUSY_OFF led1 = 1 #define LED_FILE_ON led2 = 1 #define LED_FILE_OFF led2 = 0 -#define LED_NET_ON led_y = 0 -#define LED_NET_OFF led_y = 1 +#define LED_NET_ACT_ON led_yk = 0 +#define LED_NET_ACT_OFF led_yk = 1 +#define LED_NET_G_ON led_gayk = 1; led_gkya = 0 +#define LED_NET_Y_ON led_gayk = 0; led_gkya = 1 +#define LED_NET_GY_OFF led_gayk = 0; led_gkya = 0 enum eINPUTTYPE { INPUT_MOIST = 0, INPUT_FALL = 1, INPUT_RISE = 2, INPUT_CPM = 4, + INPUT_EXINOUT = 8, }; struct Sensor { @@ -49,7 +71,10 @@ extern EthernetNetIf *eth; extern ConfigFile cfg; extern DigitalOut led1, led2, led3, led4; -extern DigitalOut led_g2,led_g, led_y; +extern DigitalOut led_gayk, led_gkya, led_yk; +#ifdef USE_3LED +extern DigitalOut led_red, led_yellow; +#endif extern Sensor sensor, offset, sensor_old; extern volatile uint32_t locUpTime; extern char csv[];