finish ^o^
Dependencies: Air_Quality DHT SDFileSystem Servo WIZnetInterface httpServer mbed-src
Fork of httpServer-WIZwiki-W7500 by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "FsHandler.h" 00004 #include "HTTPServer.h" 00005 #include "SDFileSystem.h" 00006 00007 #include "DHT.h" 00008 #include "Servo.h" 00009 00010 int motion_detected = 0; // motion 00011 int i=0; // touch 00012 00013 extern int lumi_val; 00014 extern int cel_val; 00015 extern int touch_val; 00016 extern int control; 00017 00018 DHT sensor(D8, DHT11); 00019 InterruptIn motion(D9); 00020 AnalogIn luminance(A1); 00021 InterruptIn event(D10); // touch 00022 Servo myservo(D14); // touch servo 00023 00024 DigitalOut led_R(LED1); 00025 DigitalOut led_G(LED2); 00026 DigitalOut led_B(LED3); 00027 00028 DigitalOut vol_in(A5); 00029 00030 #ifdef TARGET_WIZWIKI_W7500 00031 //Choose one of file system. 00032 SDFileSystem local(SD_MOSI, SD_MISO, SD_CLK, SD_SEL, "local");//PB_3, PB_2, PB_1, PB_0 00033 //LocalFileSystem local("local"); 00034 #endif 00035 00036 #ifdef TARGET_WIZWIKI_W7500 00037 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; 00038 #endif 00039 00040 EthernetInterface eth; 00041 HTTPServer svr; 00042 char ip_addr[] = "192.168.1.111"; 00043 char subnet_mask[] = "255.255.255.0"; 00044 char gateway_addr[] = "192.168.1.1"; 00045 00046 //#define DHCP //If uncomment, W7500 runs DHCP 00047 00048 00049 // motion 00050 void irq_handler() 00051 { 00052 motion_detected = 1; 00053 } 00054 00055 // touch 00056 void trigger() { 00057 00058 if(touch_val == 0) 00059 printf("5. Touch : Can't move!\r\n\r\n"); 00060 else { 00061 printf("5. Touch : move!\r\n\r\n"); 00062 if(i==0) 00063 myservo = 0; 00064 else if (i==1) 00065 myservo = 0.3; 00066 else if (i==2) 00067 myservo = 0.6; 00068 else if (i==3) 00069 myservo = 0.9; 00070 } 00071 00072 if (i<3) 00073 i++; 00074 else 00075 i=0; 00076 } 00077 00078 void sensor_5() { 00079 00080 int rd_sensor = 0; // when rd_sensor = 0, sensor is ready to read the data. 00081 float hum = 0.0f; 00082 float cel = 0.0f; 00083 vol_in = 0; 00084 00085 //DHT sensor 00086 rd_sensor = sensor.readData(); 00087 if (0 == rd_sensor) { 00088 hum = sensor.ReadHumidity(); 00089 cel = sensor.ReadTemperature(CELCIUS); 00090 00091 printf("1. Humidity : %4.2f\r\n\n", hum); 00092 wait(0.3); 00093 printf("2. Temperature in Celcius : %2.2f\r\n\n", cel); 00094 wait(0.3); } 00095 else 00096 printf("1,2. Error! : %d\r\n\n", rd_sensor); 00097 00098 // motion 00099 if(motion_detected) { 00100 motion_detected = 0; 00101 00102 printf("3. Something move!\r\n\r\n"); 00103 wait(0.3); 00104 } 00105 00106 // luminance 00107 printf("4. Luminance: %f\r\n\r\n", luminance.read()); 00108 //printf(" + lumi_val = %d\r\n\r\n", lumi_val); 00109 00110 if(lumi_val == 0) { 00111 led_R=1; led_G=1; led_B=1;} // led off 00112 00113 else { 00114 if(luminance.read()<=0.1){ 00115 led_R=0; led_G=0; led_B=0;} // white LED on 00116 00117 else if(0.1<=luminance.read()&&luminance.read()<=0.3){ 00118 led_R=0; led_G=0; led_B=1;} // yellow LED on 00119 00120 else{ 00121 led_R=1; led_G=1; led_B=1;} // led off 00122 } 00123 00124 if(control == 1) { 00125 if(cel_val == 0) 00126 vol_in = 0; 00127 else if(cel_val == 1) 00128 vol_in = 1; } 00129 else { 00130 if(cel < 34) 00131 vol_in = 0; 00132 else if(cel >= 34) 00133 vol_in = 1; } 00134 00135 00136 wait(1); 00137 } 00138 00139 00140 00141 int main() 00142 { /* 00143 int rd_sensor = 0; // when rd_sensor = 0, sensor is ready to read the data. 00144 float hum = 0.0f; 00145 float cel = 0.0f; */ 00146 00147 HTTPFsRequestHandler::mount("/local/", "/"); 00148 svr.addHandler<HTTPFsRequestHandler>("/"); 00149 00150 #ifdef TARGET_WIZWIKI_W7500 00151 00152 #ifdef DHCP 00153 eth.init(mac_addr); //Use DHCP 00154 #else 00155 eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); //Not Use DHCP 00156 #endif 00157 00158 #else 00159 00160 #ifdef DHCP 00161 eth.init(); //Use DHCP 00162 #else 00163 eth.init(ip_addr, subnet_mask, gateway_addr); //Not Use DHCP 00164 #endif 00165 00166 #endif 00167 00168 printf("Check Ethernet Link\r\n"); 00169 while(1) //Wait link up 00170 { 00171 if(eth.link() == true) 00172 break; 00173 } 00174 printf("Link up\r\n"); 00175 00176 eth.connect(); 00177 printf("Server IP Address is %s\r\n", eth.getIPAddress()); 00178 00179 if (!svr.start(80, ð)) { 00180 00181 error("Server not starting !"); 00182 exit(0); 00183 } 00184 00185 motion.rise(&irq_handler); 00186 event.rise(&trigger); // touch 00187 00188 while(1) { 00189 svr.poll(); 00190 sensor_5(); 00191 00192 if(control == 0) { 00193 while (1) 00194 sensor_5(); 00195 } 00196 wait(1); 00197 00198 00199 /* 00200 //DHT sensor 00201 rd_sensor = sensor.readData(); 00202 if (0 == rd_sensor) { 00203 hum = sensor.ReadHumidity(); 00204 cel = sensor.ReadTemperature(CELCIUS); 00205 cel = cel*cel_val; // control with html 00206 printf("1. Humidity : %4.2f\r\n\n", hum); 00207 wait(0.3); 00208 printf("2. Temperature in Celcius : %2.2f\r\n\n", cel); 00209 wait(0.3); 00210 } 00211 else 00212 printf("1,2. Error! : %d\r\n\n", rd_sensor); 00213 00214 // motion 00215 if(motion_detected) { 00216 motion_detected = 0; 00217 00218 printf("3. Something move!\r\n\r\n"); 00219 wait(0.3); 00220 } 00221 00222 // luminance 00223 printf("4. Luminance: %f\r\n\r\n", luminance.read()); 00224 //printf(" + lumi_val = %d\r\n\r\n", lumi_val); 00225 00226 if(lumi_val == 0) { 00227 led_R=1; led_G=1; led_B=1;} // led off 00228 00229 else { 00230 if(luminance.read()<=0.1){ 00231 led_R=0; led_G=0; led_B=0;} // white LED on 00232 00233 else if(0.1<=luminance.read()&&luminance.read()<=0.3){ 00234 led_R=0; led_G=0; led_B=1;} // yellow LED on 00235 00236 else{ 00237 led_R=1; led_G=1; led_B=1;} // led off 00238 } */ 00239 //wait(1); 00240 } 00241 }
Generated on Thu Jul 14 2022 09:15:31 by 1.7.2