windown
Dependencies: SDFileSystem WIZnetInterface mbed-src
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "FsHandler.h" 00004 #include "HTTPServer.h" 00005 #include "SDFileSystem.h" 00006 #include "DHT.h" 00007 00008 #ifdef TARGET_WIZWIKI_W7500 00009 //Choose one of file system. 00010 SDFileSystem local(SD_MOSI, SD_MISO, SD_CLK, SD_SEL, "local");//PB_3, PB_2, PB_1, PB_0 00011 //LocalFileSystem local("local"); 00012 #endif 00013 00014 #ifdef TARGET_WIZWIKI_W7500 00015 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; 00016 #endif 00017 DHT sensor(D4, DHT11); 00018 DigitalIn Rain(D2); 00019 EthernetInterface eth; 00020 HTTPServer svr; 00021 char ip_addr[] = "192.168.1.112"; 00022 char subnet_mask[] = "255.255.255.0"; 00023 char gateway_addr[] = "192.168.1.1"; 00024 00025 //#define DHCP //If uncomment, W7500 runs DHCP 00026 int Rain_value=1; 00027 int mode = 0; 00028 00029 int main() 00030 { 00031 00032 00033 int error = 0; 00034 int h = 0, c = 0, Rain_value = 1; 00035 HTTPFsRequestHandler::mount("/local/", "/"); 00036 svr.addHandler<HTTPFsRequestHandler>("/"); 00037 00038 #ifdef TARGET_WIZWIKI_W7500 00039 00040 #ifdef DHCP 00041 eth.init(mac_addr); //Use DHCP 00042 #else 00043 eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); //Not Use DHCP 00044 #endif 00045 00046 #else 00047 00048 #ifdef DHCP 00049 eth.init(); //Use DHCP 00050 #else 00051 eth.init(ip_addr, subnet_mask, gateway_addr); //Not Use DHCP 00052 #endif 00053 00054 #endif 00055 00056 printf("Check Ethernet Link\r\n"); 00057 while(1) //Wait link up 00058 { 00059 if(eth.link() == true) 00060 break; 00061 } 00062 printf("Link up\r\n"); 00063 00064 eth.connect(); 00065 printf("Server IP Address is %s\r\n", eth.getIPAddress()); 00066 00067 if (!svr.start(80, ð)) { 00068 00069 //error("Server not starting !"); 00070 exit(0); 00071 } 00072 00073 while(1) { 00074 svr.poll(); 00075 Rain_value = Rain.read(); // read the rain value 00076 wait(0.2); 00077 error = sensor.readData(); 00078 if (0 == error) { 00079 c = sensor.ReadTemperature(CELCIUS); 00080 h = sensor.ReadHumidity(); 00081 printf("===============Smart window================\n\r"); 00082 printf("Temperature in Celcius: %d\n",c); 00083 printf("Humidity : %d\n", h); 00084 printf("Rain value : %d\n", Rain_value); 00085 printf("Mode : %d\n", mode); 00086 printf("===========================================\n\r"); 00087 00088 } else { 00089 printf("Error: %d\n", error); 00090 } 00091 00092 00093 //////// open the window 00094 if((c>27 || h>50) && (mode == 0&&Rain_value==1)){ 00095 // ((c>30 or h>50) and closed status) 00096 DigitalOut(D9,0); 00097 DigitalOut(D8,1); 00098 wait(0.87); 00099 DigitalOut(D9,0); 00100 DigitalOut(D8,0); 00101 mode = 1 ; // opened status 00102 00103 } 00104 /////// close the window 00105 else if((c<20 && h<40) || (mode == 1&&Rain_value==0)){ // ((c<20 and h<40) and opened status) 00106 DigitalOut(D9,1); 00107 DigitalOut(D8,0); 00108 wait(0.8); 00109 DigitalOut(D9,0); 00110 DigitalOut(D8,0); 00111 mode = 0; //closed status 00112 } 00113 00114 wait(1); 00115 } 00116 }
Generated on Fri Jul 22 2022 21:11:01 by
1.7.2