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

Dependencies:   EthernetNetIf SDHCFileSystem I2CLEDDisp Agentbed NTPClient_NetServices mbed BMP085 HTTPClient ConfigFile I2CLCD

Committer:
okini3939
Date:
Wed May 18 15:01:56 2011 +0000
Revision:
0:d7b4484099bf

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 0:d7b4484099bf 1 /*
okini3939 0:d7b4484099bf 2 * mbed Weather Platform
okini3939 0:d7b4484099bf 3 * Copyright (c) 2011 Hiroshi Suga
okini3939 0:d7b4484099bf 4 * Released under the MIT License: http://mbed.org/license/mit
okini3939 0:d7b4484099bf 5 */
okini3939 0:d7b4484099bf 6
okini3939 0:d7b4484099bf 7 /** @file
okini3939 0:d7b4484099bf 8 * @brief mbed Weather Platform
okini3939 0:d7b4484099bf 9 */
okini3939 0:d7b4484099bf 10
okini3939 0:d7b4484099bf 11 #define VERSION "mbed Weather Platform 0.2.1 (C) 2011 Suga koubou Co.,Ltd."
okini3939 0:d7b4484099bf 12
okini3939 0:d7b4484099bf 13 //#define NONBLOCKING // ethernet function non-bloking
okini3939 0:d7b4484099bf 14
okini3939 0:d7b4484099bf 15 #include "mbed.h"
okini3939 0:d7b4484099bf 16 #include "BMP085.h"
okini3939 0:d7b4484099bf 17 #include "SHT.h"
okini3939 0:d7b4484099bf 18 #include "WeatherMeters.h"
okini3939 0:d7b4484099bf 19 #include "SDHCFileSystem.h"
okini3939 0:d7b4484099bf 20 #include "MSCFileSystem.h"
okini3939 0:d7b4484099bf 21 #include "EthernetNetIf.h"
okini3939 0:d7b4484099bf 22 #include "NTPClient.h"
okini3939 0:d7b4484099bf 23 #include "HTTPClient.h"
okini3939 0:d7b4484099bf 24 #include "Agentbed.h"
okini3939 0:d7b4484099bf 25 #include "conf.h"
okini3939 0:d7b4484099bf 26 #include "I2CLEDDisp.h"
okini3939 0:d7b4484099bf 27 #include "I2CLCD.h"
okini3939 0:d7b4484099bf 28
okini3939 0:d7b4484099bf 29 Serial pc(USBTX, USBRX), xbee(p13, p14);
okini3939 0:d7b4484099bf 30 int seq = 0;
okini3939 0:d7b4484099bf 31 char filename[20];
okini3939 0:d7b4484099bf 32 struct Config conf;
okini3939 0:d7b4484099bf 33 DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
okini3939 0:d7b4484099bf 34 LocalFileSystem local("local");
okini3939 0:d7b4484099bf 35 SDFileSystem sd(p5, p6, p7, p8, "sd");
okini3939 0:d7b4484099bf 36 MSCFileSystem *usb;
okini3939 0:d7b4484099bf 37
okini3939 0:d7b4484099bf 38 // Sensors
okini3939 0:d7b4484099bf 39 struct Sensor sensor, offset, sensor_old;
okini3939 0:d7b4484099bf 40 I2C i2c(p9, p10);
okini3939 0:d7b4484099bf 41 BMP085 bmp085(i2c, BMP085_oss4);
okini3939 0:d7b4484099bf 42 SHT sht15(p12, p11, SHT_high); // sclock, data
okini3939 0:d7b4484099bf 43 WeatherMeters wmeters(p21, p15, p22); // anemo, vane, rain
okini3939 0:d7b4484099bf 44 AnalogIn ailight(p16), aiuv(p17);
okini3939 0:d7b4484099bf 45 AnalogIn *aimoist;
okini3939 0:d7b4484099bf 46 InterruptIn *intcounter;
okini3939 0:d7b4484099bf 47 int count_counter;
okini3939 0:d7b4484099bf 48 unsigned long lastCountTime;
okini3939 0:d7b4484099bf 49
okini3939 0:d7b4484099bf 50 DigitalOut swout1(p29), swout2(p30);
okini3939 0:d7b4484099bf 51 I2CLEDDisp *leddisp;
okini3939 0:d7b4484099bf 52 I2CLCD *lcd;
okini3939 0:d7b4484099bf 53 int ledpos, ledflg;
okini3939 0:d7b4484099bf 54 char ledbuf[200];
okini3939 0:d7b4484099bf 55 Ticker ticker;
okini3939 0:d7b4484099bf 56
okini3939 0:d7b4484099bf 57 // Ethernet
okini3939 0:d7b4484099bf 58 EthernetNetIf *eth;
okini3939 0:d7b4484099bf 59 NTPClient *ntp;
okini3939 0:d7b4484099bf 60 HTTPClient *clientP, *clientT;
okini3939 0:d7b4484099bf 61 DigitalOut led_g2(p24),led_g(p25), led_y(p26);
okini3939 0:d7b4484099bf 62 DigitalIn eth_link(P1_25), eth_speed(P1_26);
okini3939 0:d7b4484099bf 63
okini3939 0:d7b4484099bf 64 extern AgentbedClass Agentbed;
okini3939 0:d7b4484099bf 65 extern uint32_t locUpTime;
okini3939 0:d7b4484099bf 66
okini3939 0:d7b4484099bf 67 void writefile (char *);
okini3939 0:d7b4484099bf 68 void pachube (char *);
okini3939 0:d7b4484099bf 69 char *fmtstr (char *, char *, int);
okini3939 0:d7b4484099bf 70 void twitter (int);
okini3939 0:d7b4484099bf 71 void weatherstations ();
okini3939 0:d7b4484099bf 72 void ntpdate ();
okini3939 0:d7b4484099bf 73 int check_action (char);
okini3939 0:d7b4484099bf 74 void pduReceived ();
okini3939 0:d7b4484099bf 75
okini3939 0:d7b4484099bf 76 float get_photo (AnalogIn &ain) {
okini3939 0:d7b4484099bf 77 float f;
okini3939 0:d7b4484099bf 78
okini3939 0:d7b4484099bf 79 f = ain * 5.0 / 1000; // A
okini3939 0:d7b4484099bf 80 return f / 0.0000026; // lx
okini3939 0:d7b4484099bf 81 }
okini3939 0:d7b4484099bf 82
okini3939 0:d7b4484099bf 83 float get_moist (AnalogIn &ain) {
okini3939 0:d7b4484099bf 84 float f;
okini3939 0:d7b4484099bf 85
okini3939 0:d7b4484099bf 86 f = ain * 5.0; // V
okini3939 0:d7b4484099bf 87 f = f / ((3.3 - f) / 10.0); // k ohm
okini3939 0:d7b4484099bf 88 if (f < 0) f = 0;
okini3939 0:d7b4484099bf 89 return f;
okini3939 0:d7b4484099bf 90 }
okini3939 0:d7b4484099bf 91
okini3939 0:d7b4484099bf 92 float get_uv (AnalogIn &ain) {
okini3939 0:d7b4484099bf 93 float f;
okini3939 0:d7b4484099bf 94
okini3939 0:d7b4484099bf 95 f = ain * 5.0 / 100000; // A
okini3939 0:d7b4484099bf 96 f = f / 0.000384; // mW/cm2
okini3939 0:d7b4484099bf 97 if (f < 0) f = 0;
okini3939 0:d7b4484099bf 98 return f;
okini3939 0:d7b4484099bf 99 }
okini3939 0:d7b4484099bf 100
okini3939 0:d7b4484099bf 101 void int_counter () {
okini3939 0:d7b4484099bf 102 count_counter ++;
okini3939 0:d7b4484099bf 103 }
okini3939 0:d7b4484099bf 104
okini3939 0:d7b4484099bf 105 float get_counter (char flg) {
okini3939 0:d7b4484099bf 106 float t;
okini3939 0:d7b4484099bf 107
okini3939 0:d7b4484099bf 108 if (flg) {
okini3939 0:d7b4484099bf 109 t = (float)count_counter;
okini3939 0:d7b4484099bf 110 } else {
okini3939 0:d7b4484099bf 111 if (locUpTime > lastCountTime) {
okini3939 0:d7b4484099bf 112 t = (float)(locUpTime - lastCountTime) / 6000.0;
okini3939 0:d7b4484099bf 113 } else {
okini3939 0:d7b4484099bf 114 t = (float)(0xffffffff - lastCountTime + locUpTime) / 6000.0;
okini3939 0:d7b4484099bf 115 }
okini3939 0:d7b4484099bf 116 t = (float)count_counter / t;
okini3939 0:d7b4484099bf 117 }
okini3939 0:d7b4484099bf 118 lastCountTime = locUpTime;
okini3939 0:d7b4484099bf 119 count_counter = 0;
okini3939 0:d7b4484099bf 120 return t;
okini3939 0:d7b4484099bf 121 }
okini3939 0:d7b4484099bf 122
okini3939 0:d7b4484099bf 123
okini3939 0:d7b4484099bf 124 void ledscroll () {
okini3939 0:d7b4484099bf 125
okini3939 0:d7b4484099bf 126 if (conf.leddisp_mesg[0]) {
okini3939 0:d7b4484099bf 127 int i, addr, len;
okini3939 0:d7b4484099bf 128
okini3939 0:d7b4484099bf 129 len = strlen(ledbuf);
okini3939 0:d7b4484099bf 130 leddisp->locate(0, 0);
okini3939 0:d7b4484099bf 131 for (i = 0; i < 4; i ++) {
okini3939 0:d7b4484099bf 132 addr = ledpos + i;
okini3939 0:d7b4484099bf 133 if (addr >= 0 && addr < len) {
okini3939 0:d7b4484099bf 134 leddisp->putc(ledbuf[addr]);
okini3939 0:d7b4484099bf 135 } else {
okini3939 0:d7b4484099bf 136 leddisp->putc(' ');
okini3939 0:d7b4484099bf 137 }
okini3939 0:d7b4484099bf 138 }
okini3939 0:d7b4484099bf 139 ledpos ++;
okini3939 0:d7b4484099bf 140 if (ledpos >= len + 4) {
okini3939 0:d7b4484099bf 141 ledpos = -4;
okini3939 0:d7b4484099bf 142 }
okini3939 0:d7b4484099bf 143 }
okini3939 0:d7b4484099bf 144
okini3939 0:d7b4484099bf 145 locUpTime = locUpTime + 40; // 0.4s
okini3939 0:d7b4484099bf 146 led_y = 1;
okini3939 0:d7b4484099bf 147 }
okini3939 0:d7b4484099bf 148
okini3939 0:d7b4484099bf 149 void action (char *buf) {
okini3939 0:d7b4484099bf 150 int i;
okini3939 0:d7b4484099bf 151
okini3939 0:d7b4484099bf 152 i = check_action('A');
okini3939 0:d7b4484099bf 153 if (i) {
okini3939 0:d7b4484099bf 154 swout1 = (i == ' ' ? 1 : i - '0');
okini3939 0:d7b4484099bf 155 led3 = swout1;
okini3939 0:d7b4484099bf 156 }
okini3939 0:d7b4484099bf 157 i = check_action('B');
okini3939 0:d7b4484099bf 158 if (i) {
okini3939 0:d7b4484099bf 159 swout2 = (i == ' ' ? 1 : i - '0');
okini3939 0:d7b4484099bf 160 led4 = swout2;
okini3939 0:d7b4484099bf 161 }
okini3939 0:d7b4484099bf 162 if (check_action('P')) {
okini3939 0:d7b4484099bf 163 if (conf.ipaddr[0] && conf.pachube_apikey[0] && conf.pachube_feedid[0]) {
okini3939 0:d7b4484099bf 164 pachube(buf);
okini3939 0:d7b4484099bf 165 }
okini3939 0:d7b4484099bf 166 }
okini3939 0:d7b4484099bf 167 i = check_action('T');
okini3939 0:d7b4484099bf 168 if (i) {
okini3939 0:d7b4484099bf 169 if (conf.ipaddr[0] && conf.twitter_user[0] && conf.twitter_pwd[0]) {
okini3939 0:d7b4484099bf 170 twitter(i == ' ' ? 0 : i - '0');
okini3939 0:d7b4484099bf 171 }
okini3939 0:d7b4484099bf 172 }
okini3939 0:d7b4484099bf 173 if (check_action('S')) {
okini3939 0:d7b4484099bf 174 if (conf.ipaddr[0] && conf.stations_id[0] && conf.stations_pin[0]) {
okini3939 0:d7b4484099bf 175 weatherstations();
okini3939 0:d7b4484099bf 176 }
okini3939 0:d7b4484099bf 177 }
okini3939 0:d7b4484099bf 178 if (check_action('X')) {
okini3939 0:d7b4484099bf 179 xbee.printf(buf);
okini3939 0:d7b4484099bf 180 }
okini3939 0:d7b4484099bf 181 sensor_old = sensor;
okini3939 0:d7b4484099bf 182 }
okini3939 0:d7b4484099bf 183
okini3939 0:d7b4484099bf 184 void init () {
okini3939 0:d7b4484099bf 185 FILE *fp;
okini3939 0:d7b4484099bf 186
okini3939 0:d7b4484099bf 187 if (config("/sd/" CONFIG_FILE) == -1) {
okini3939 0:d7b4484099bf 188 pc.printf("local strage\r\n", conf.interval);
okini3939 0:d7b4484099bf 189 config("/local/" CONFIG_FILE);
okini3939 0:d7b4484099bf 190 }
okini3939 0:d7b4484099bf 191
okini3939 0:d7b4484099bf 192 pc.printf("\r\nInterval: %d sec\r\n", conf.interval);
okini3939 0:d7b4484099bf 193
okini3939 0:d7b4484099bf 194 if (conf.lcd_mesg[0]) {
okini3939 0:d7b4484099bf 195 // use I2C LCD
okini3939 0:d7b4484099bf 196 lcd = new I2CLCD(i2c, I2CLCD_ADDR, conf.lcdtype, conf.lcdconf);
okini3939 0:d7b4484099bf 197 }
okini3939 0:d7b4484099bf 198
okini3939 0:d7b4484099bf 199 if (conf.leddisp_mesg[0]) {
okini3939 0:d7b4484099bf 200 // use I2C LED Display
okini3939 0:d7b4484099bf 201 leddisp = new I2CLEDDisp(i2c);
okini3939 0:d7b4484099bf 202 }
okini3939 0:d7b4484099bf 203
okini3939 0:d7b4484099bf 204 if (conf.ipaddr[0]) {
okini3939 0:d7b4484099bf 205 // use ethernet
okini3939 0:d7b4484099bf 206
okini3939 0:d7b4484099bf 207 eth_link.mode(PullUp);
okini3939 0:d7b4484099bf 208 eth_speed.mode(PullUp);
okini3939 0:d7b4484099bf 209 led_g = eth_link ? 1 : 0;
okini3939 0:d7b4484099bf 210 led_g2 = 1;
okini3939 0:d7b4484099bf 211 led_y = 0;
okini3939 0:d7b4484099bf 212 if (conf.ipaddr[0] == 255) {
okini3939 0:d7b4484099bf 213 // dhcp
okini3939 0:d7b4484099bf 214 eth = new EthernetNetIf;
okini3939 0:d7b4484099bf 215 } else {
okini3939 0:d7b4484099bf 216 // static
okini3939 0:d7b4484099bf 217 eth = new EthernetNetIf(conf.ipaddr, conf.netmask, conf.gateway, conf.nameserver);
okini3939 0:d7b4484099bf 218 }
okini3939 0:d7b4484099bf 219
okini3939 0:d7b4484099bf 220 EthernetErr ethErr = eth->setup();
okini3939 0:d7b4484099bf 221 if(ethErr) {
okini3939 0:d7b4484099bf 222 // error
okini3939 0:d7b4484099bf 223 conf.ipaddr = IpAddr(0, 0, 0, 0);
okini3939 0:d7b4484099bf 224 } else
okini3939 0:d7b4484099bf 225 if (conf.ipaddr[0] == 255) {
okini3939 0:d7b4484099bf 226 // succeed dhcp
okini3939 0:d7b4484099bf 227 conf.ipaddr = eth->getIp();
okini3939 0:d7b4484099bf 228 }
okini3939 0:d7b4484099bf 229 pc.printf("Ethernet: %d.%d.%d.%d\r\n", eth->getIp()[0], eth->getIp()[1], eth->getIp()[2], eth->getIp()[3]);
okini3939 0:d7b4484099bf 230
okini3939 0:d7b4484099bf 231 if (conf.ipaddr[0]) {
okini3939 0:d7b4484099bf 232
okini3939 0:d7b4484099bf 233 if (conf.ntpserver[0]) {
okini3939 0:d7b4484099bf 234 // ntp
okini3939 0:d7b4484099bf 235 pc.printf("Ntp: %s\r\n", conf.ntpserver);
okini3939 0:d7b4484099bf 236 ntpdate();
okini3939 0:d7b4484099bf 237 }
okini3939 0:d7b4484099bf 238
okini3939 0:d7b4484099bf 239 clientP = new HTTPClient;
okini3939 0:d7b4484099bf 240 clientT = new HTTPClient;
okini3939 0:d7b4484099bf 241
okini3939 0:d7b4484099bf 242 if (conf.snmp_commname[0]) {
okini3939 0:d7b4484099bf 243 Agentbed.begin(conf.snmp_commname, "None", SNMP_DEFAULT_PORT, eth);
okini3939 0:d7b4484099bf 244 Agentbed.onPduReceive(pduReceived);
okini3939 0:d7b4484099bf 245 pc.printf("Snmp community name: %s\r\n", conf.snmp_commname);
okini3939 0:d7b4484099bf 246 }
okini3939 0:d7b4484099bf 247 }
okini3939 0:d7b4484099bf 248 } else {
okini3939 0:d7b4484099bf 249 // not use ethernet
okini3939 0:d7b4484099bf 250 led_g = eth_link ? 0 : 1;
okini3939 0:d7b4484099bf 251 led_g2 = 0;
okini3939 0:d7b4484099bf 252 }
okini3939 0:d7b4484099bf 253
okini3939 0:d7b4484099bf 254 if (conf.filetype) {
okini3939 0:d7b4484099bf 255 // seq num
okini3939 0:d7b4484099bf 256
okini3939 0:d7b4484099bf 257 if (conf.filetype == 1) {
okini3939 0:d7b4484099bf 258 strcpy(filename, "/sd");
okini3939 0:d7b4484099bf 259 } else
okini3939 0:d7b4484099bf 260 if (conf.filetype == 2) {
okini3939 0:d7b4484099bf 261 usb = new MSCFileSystem("usb");
okini3939 0:d7b4484099bf 262 strcpy(filename, "/usb");
okini3939 0:d7b4484099bf 263 }
okini3939 0:d7b4484099bf 264 strcat(filename, "/weather.seq");
okini3939 0:d7b4484099bf 265
okini3939 0:d7b4484099bf 266 // load
okini3939 0:d7b4484099bf 267 fp = fopen(filename, "r");
okini3939 0:d7b4484099bf 268 if (fp) {
okini3939 0:d7b4484099bf 269 fscanf(fp, "%d", &seq);
okini3939 0:d7b4484099bf 270 fclose(fp);
okini3939 0:d7b4484099bf 271 }
okini3939 0:d7b4484099bf 272 seq ++;
okini3939 0:d7b4484099bf 273 // save
okini3939 0:d7b4484099bf 274 fp = fopen(filename, "w");
okini3939 0:d7b4484099bf 275 if (fp) {
okini3939 0:d7b4484099bf 276 fprintf(fp, "%d", seq);
okini3939 0:d7b4484099bf 277 fclose(fp);
okini3939 0:d7b4484099bf 278 // csv filename
okini3939 0:d7b4484099bf 279 if (conf.filetype == 1) {
okini3939 0:d7b4484099bf 280 sprintf(filename, "/sd/w%05d.csv", seq);
okini3939 0:d7b4484099bf 281 } else
okini3939 0:d7b4484099bf 282 if (conf.filetype == 2) {
okini3939 0:d7b4484099bf 283 sprintf(filename, "/usb/w%05d.csv", seq);
okini3939 0:d7b4484099bf 284 }
okini3939 0:d7b4484099bf 285 pc.printf("Filename: %s\r\n", filename);
okini3939 0:d7b4484099bf 286 led2 = 1;
okini3939 0:d7b4484099bf 287 }
okini3939 0:d7b4484099bf 288 }
okini3939 0:d7b4484099bf 289
okini3939 0:d7b4484099bf 290 pc.printf("Actions: %d\r\n", conf.actionscount);
okini3939 0:d7b4484099bf 291
okini3939 0:d7b4484099bf 292 if (conf.inputtype & INPUT_FALL) {
okini3939 0:d7b4484099bf 293 intcounter = new InterruptIn(p18);
okini3939 0:d7b4484099bf 294 intcounter->fall(&int_counter);
okini3939 0:d7b4484099bf 295 } else
okini3939 0:d7b4484099bf 296 if (conf.inputtype & INPUT_RISE) {
okini3939 0:d7b4484099bf 297 intcounter = new InterruptIn(p18);
okini3939 0:d7b4484099bf 298 intcounter->rise(&int_counter);
okini3939 0:d7b4484099bf 299 } else {
okini3939 0:d7b4484099bf 300 aimoist = new AnalogIn(p18);
okini3939 0:d7b4484099bf 301 }
okini3939 0:d7b4484099bf 302
okini3939 0:d7b4484099bf 303 count_counter = 0;
okini3939 0:d7b4484099bf 304 lastCountTime = 0;
okini3939 0:d7b4484099bf 305 }
okini3939 0:d7b4484099bf 306
okini3939 0:d7b4484099bf 307 int main () {
okini3939 0:d7b4484099bf 308 Timer timer;
okini3939 0:d7b4484099bf 309 time_t sec;
okini3939 0:d7b4484099bf 310 char buf[100];
okini3939 0:d7b4484099bf 311
okini3939 0:d7b4484099bf 312 swout1 = 0;
okini3939 0:d7b4484099bf 313 swout2 = 0;
okini3939 0:d7b4484099bf 314 led1 = 1;
okini3939 0:d7b4484099bf 315 ledpos = -4;
okini3939 0:d7b4484099bf 316 ledflg = 0;
okini3939 0:d7b4484099bf 317 strcpy(ledbuf, VERSION);
okini3939 0:d7b4484099bf 318 ticker.attach(&ledscroll, 0.4);
okini3939 0:d7b4484099bf 319 init();
okini3939 0:d7b4484099bf 320 pc.printf("%s\r\n\r\n", VERSION);
okini3939 0:d7b4484099bf 321
okini3939 0:d7b4484099bf 322 if (conf.filetype) {
okini3939 0:d7b4484099bf 323 strcpy(buf, "date,pres(hPa),temp(`C),humi(%%),anemo(m/s),vane(`),rain(mm),light(lx),uv(mW/cm2),moist(kohm),\r\n");
okini3939 0:d7b4484099bf 324 writefile(buf);
okini3939 0:d7b4484099bf 325 }
okini3939 0:d7b4484099bf 326
okini3939 0:d7b4484099bf 327 if (conf.leddisp_mesg[0]) {
okini3939 0:d7b4484099bf 328 ledpos = -4;
okini3939 0:d7b4484099bf 329 sec = time(NULL);
okini3939 0:d7b4484099bf 330 strftime(ledbuf, sizeof(ledbuf), "%H:%M", localtime(&sec));
okini3939 0:d7b4484099bf 331 sprintf(&ledbuf[5], " %ds %s", conf.interval, filename);
okini3939 0:d7b4484099bf 332 if (conf.ipaddr[0]) {
okini3939 0:d7b4484099bf 333 sprintf(&ledbuf[strlen(ledbuf)], " %d.%d.%d.%d", conf.ipaddr[0], conf.ipaddr[1], conf.ipaddr[2], conf.ipaddr[3]);
okini3939 0:d7b4484099bf 334 if (conf.pachube_apikey[0] && conf.pachube_feedid[0]) {
okini3939 0:d7b4484099bf 335 strcat(ledbuf, " P");
okini3939 0:d7b4484099bf 336 }
okini3939 0:d7b4484099bf 337 if (conf.twitter_user[0] && conf.twitter_pwd[0]) {
okini3939 0:d7b4484099bf 338 strcat(ledbuf, " T");
okini3939 0:d7b4484099bf 339 }
okini3939 0:d7b4484099bf 340 }
okini3939 0:d7b4484099bf 341 }
okini3939 0:d7b4484099bf 342
okini3939 0:d7b4484099bf 343 timer.start();
okini3939 0:d7b4484099bf 344 #ifdef NONBLOCKING
okini3939 0:d7b4484099bf 345 while (timer.read() < 5) {
okini3939 0:d7b4484099bf 346 wait_ms(1);
okini3939 0:d7b4484099bf 347 Net::poll();
okini3939 0:d7b4484099bf 348 }
okini3939 0:d7b4484099bf 349 timer.reset();
okini3939 0:d7b4484099bf 350 #endif
okini3939 0:d7b4484099bf 351
okini3939 0:d7b4484099bf 352 while(1) {
okini3939 0:d7b4484099bf 353 led1 = 0;
okini3939 0:d7b4484099bf 354
okini3939 0:d7b4484099bf 355 sec = time(NULL);
okini3939 0:d7b4484099bf 356 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&sec));
okini3939 0:d7b4484099bf 357
okini3939 0:d7b4484099bf 358 // sensors
okini3939 0:d7b4484099bf 359 __disable_irq();
okini3939 0:d7b4484099bf 360 bmp085.update();
okini3939 0:d7b4484099bf 361 sensor.pres = bmp085.get_pressure() + offset.pres;
okini3939 0:d7b4484099bf 362 sensor.temp2 = bmp085.get_temperature();
okini3939 0:d7b4484099bf 363
okini3939 0:d7b4484099bf 364 sht15.update(SHT_high);
okini3939 0:d7b4484099bf 365 sensor.temp = sht15.get_temperature() + offset.temp;
okini3939 0:d7b4484099bf 366 sensor.humi = sht15.get_humidity() + offset.humi;
okini3939 0:d7b4484099bf 367
okini3939 0:d7b4484099bf 368 sensor.anemo = wmeters.get_windspeed();
okini3939 0:d7b4484099bf 369 sensor.vane = wmeters.get_windvane();
okini3939 0:d7b4484099bf 370 sensor.rain = wmeters.get_raingauge();
okini3939 0:d7b4484099bf 371
okini3939 0:d7b4484099bf 372 sensor.light = get_photo(ailight);
okini3939 0:d7b4484099bf 373 if (conf.inputtype == INPUT_MOIST) {
okini3939 0:d7b4484099bf 374 sensor.moist = get_moist(*aimoist);
okini3939 0:d7b4484099bf 375 } else {
okini3939 0:d7b4484099bf 376 sensor.moist = get_counter(conf.inputtype & INPUT_CPM ? 0 : 1);
okini3939 0:d7b4484099bf 377 }
okini3939 0:d7b4484099bf 378 sensor.uv = get_uv(aiuv);
okini3939 0:d7b4484099bf 379
okini3939 0:d7b4484099bf 380 sprintf(&buf[strlen(buf)], ",%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f\r\n",
okini3939 0:d7b4484099bf 381 sensor.pres, sensor.temp, sensor.humi, sensor.anemo, sensor.vane, sensor.rain, sensor.light, sensor.uv, sensor.moist, sensor.temp2);
okini3939 0:d7b4484099bf 382 if (conf.filetype) {
okini3939 0:d7b4484099bf 383 // csv
okini3939 0:d7b4484099bf 384 writefile(buf);
okini3939 0:d7b4484099bf 385 }
okini3939 0:d7b4484099bf 386 __enable_irq();
okini3939 0:d7b4484099bf 387 pc.printf(buf);
okini3939 0:d7b4484099bf 388
okini3939 0:d7b4484099bf 389 action(&buf[20]);
okini3939 0:d7b4484099bf 390
okini3939 0:d7b4484099bf 391 if (conf.leddisp_mesg[0]) {
okini3939 0:d7b4484099bf 392 if (ledflg) {
okini3939 0:d7b4484099bf 393 ledpos = -4;
okini3939 0:d7b4484099bf 394 fmtstr(conf.leddisp_mesg, ledbuf, sizeof(ledbuf));
okini3939 0:d7b4484099bf 395 }
okini3939 0:d7b4484099bf 396 ledflg = 1;
okini3939 0:d7b4484099bf 397 }
okini3939 0:d7b4484099bf 398 if (conf.lcd_mesg[0]) {
okini3939 0:d7b4484099bf 399 fmtstr(conf.lcd_mesg, buf, sizeof(buf));
okini3939 0:d7b4484099bf 400 lcd->cls();
okini3939 0:d7b4484099bf 401 lcd->puts(buf);
okini3939 0:d7b4484099bf 402 }
okini3939 0:d7b4484099bf 403
okini3939 0:d7b4484099bf 404 led1 = 1;
okini3939 0:d7b4484099bf 405
okini3939 0:d7b4484099bf 406 while (timer.read() < conf.interval) {
okini3939 0:d7b4484099bf 407 // wait(1);
okini3939 0:d7b4484099bf 408 // pc.putc('.');
okini3939 0:d7b4484099bf 409 wait_ms(1);
okini3939 0:d7b4484099bf 410 if (conf.ipaddr[0]) {
okini3939 0:d7b4484099bf 411 led_g = eth_link ? 1 : 0;
okini3939 0:d7b4484099bf 412 led_g2 = 1;
okini3939 0:d7b4484099bf 413 } else {
okini3939 0:d7b4484099bf 414 led_g = eth_link ? 0 : 1;
okini3939 0:d7b4484099bf 415 led_g2 = 0;
okini3939 0:d7b4484099bf 416 }
okini3939 0:d7b4484099bf 417 Net::poll();
okini3939 0:d7b4484099bf 418
okini3939 0:d7b4484099bf 419 if (pc.readable()) {
okini3939 0:d7b4484099bf 420 int i;
okini3939 0:d7b4484099bf 421 i = pc.getc();
okini3939 0:d7b4484099bf 422 if (i == ' ') {
okini3939 0:d7b4484099bf 423 break;
okini3939 0:d7b4484099bf 424 } else {
okini3939 0:d7b4484099bf 425 pc.printf("( %d )\r\n", (int)timer.read());
okini3939 0:d7b4484099bf 426 }
okini3939 0:d7b4484099bf 427 }
okini3939 0:d7b4484099bf 428 }
okini3939 0:d7b4484099bf 429 timer.reset();
okini3939 0:d7b4484099bf 430 }
okini3939 0:d7b4484099bf 431 }