Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Air_Quality DHT SDFileSystem Servo WIZnetInterface httpServer mbed-src
Fork of httpServer-WIZwiki-W7500 by
Revision 19:e2b03f4e2c7e, committed 2015-08-19
- Comitter:
- M_J
- Date:
- Wed Aug 19 16:28:07 2015 +0000
- Parent:
- 18:5d96484995cf
- Child:
- 20:3b473e577885
- Commit message:
- html+sensor(error o)
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Air_Quality.lib Wed Aug 19 16:28:07 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/M_J/code/Air_Quality/#3d804fbaa44d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DHT.lib Wed Aug 19 16:28:07 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/components/code/DHT/#df22ddf10d75
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Wed Aug 19 16:28:07 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- a/httpServer.lib Wed Jul 01 04:06:51 2015 +0000 +++ b/httpServer.lib Wed Aug 19 16:28:07 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/WIZnet/code/httpServer/#772534e3b627 +http://developer.mbed.org/teams/WIZnet/code/httpServer/#859187375533
--- a/main.cpp Wed Jul 01 04:06:51 2015 +0000
+++ b/main.cpp Wed Aug 19 16:28:07 2015 +0000
@@ -4,29 +4,84 @@
#include "HTTPServer.h"
#include "SDFileSystem.h"
+#include "DHT.h"
+#include "Servo.h"
+
+int motion_detected = 0; // motion
+int i=0; // touch
+
+extern int lumi_val;
+extern int cel_val;
+extern int touch_val;
+
+DHT sensor(D4, DHT11);
+InterruptIn motion(D5);
+AnalogIn luminance(A1);
+InterruptIn event(D2); // touch
+Servo myservo(D14); // touch servo
+
+DigitalOut led_R(LED1);
+DigitalOut led_G(LED2);
+DigitalOut led_B(LED3);
+
#ifdef TARGET_WIZWIKI_W7500
//Choose one of file system.
SDFileSystem local(SD_MOSI, SD_MISO, SD_CLK, SD_SEL, "local");//PB_3, PB_2, PB_1, PB_0
//LocalFileSystem local("local");
#endif
-
+
#ifdef TARGET_WIZWIKI_W7500
uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};
#endif
-
+
EthernetInterface eth;
HTTPServer svr;
char ip_addr[] = "192.168.1.111";
char subnet_mask[] = "255.255.255.0";
char gateway_addr[] = "192.168.1.1";
-
+
//#define DHCP //If uncomment, W7500 runs DHCP
+
+
+// motion
+void irq_handler()
+{
+ motion_detected = 1;
+}
+// touch
+void trigger() {
+
+ if(touch_val == 0)
+ printf("5. Touch : Can't move!\r\n\r\n");
+ else {
+ printf("5. Touch : move!\r\n\r\n");
+ if(i==0)
+ myservo = 0;
+ else if (i==1)
+ myservo = 0.3;
+ else if (i==2)
+ myservo = 0.6;
+ else if (i==3)
+ myservo = 0.9;
+ }
+
+ if (i<3)
+ i++;
+ else
+ i=0;
+}
+
+
int main()
{
+ int rd_sensor = 0; // when rd_sensor = 0, sensor is ready to read the data.
+ float hum = 0.0f;
+ float cel = 0.0f;
+
HTTPFsRequestHandler::mount("/local/", "/");
svr.addHandler<HTTPFsRequestHandler>("/");
-
+
#ifdef TARGET_WIZWIKI_W7500
#ifdef DHCP
@@ -34,17 +89,17 @@
#else
eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); //Not Use DHCP
#endif
-
+
#else
-
+
#ifdef DHCP
eth.init(); //Use DHCP
#else
eth.init(ip_addr, subnet_mask, gateway_addr); //Not Use DHCP
#endif
-
+
#endif
-
+
printf("Check Ethernet Link\r\n");
while(1) //Wait link up
{
@@ -52,19 +107,63 @@
break;
}
printf("Link up\r\n");
-
+
eth.connect();
printf("Server IP Address is %s\r\n", eth.getIPAddress());
-
+
if (!svr.start(80, ð)) {
-
+
error("Server not starting !");
exit(0);
}
-
+
+ motion.rise(&irq_handler);
+ event.rise(&trigger); // touch
+
while(1) {
svr.poll();
+
+ wait(0.3);
+
+ //DHT sensor
+ rd_sensor = sensor.readData();
+ if (0 == rd_sensor) {
+ hum = sensor.ReadHumidity();
+ cel = sensor.ReadTemperature(CELCIUS);
+ cel = cel*cel_val; // control with html
+ printf("1. Humidity : %4.2f\r\n\n", hum);
+ wait(0.3);
+ printf("2. Temperature in Celcius : %2.2f\r\n\n", cel);
+ wait(0.3);
+ }
+ else
+ printf("1,2. Error! : %d\r\n\n", rd_sensor);
+
+ // motion
+ if(motion_detected) {
+ motion_detected = 0;
+
+ printf("3. Something move!\r\n\r\n");
+ wait(0.3);
+ }
+
+ // luminance
+ printf("4. Luminance: %f\r\n\r\n", luminance.read());
+ //printf(" + lumi_val = %d\r\n\r\n", lumi_val);
+
+ if(lumi_val == 0) {
+ led_R=1; led_G=1; led_B=1;} // led off
+
+ else {
+ if(luminance.read()<=0.1){
+ led_R=0; led_G=0; led_B=0;} // white LED on
+
+ else if(0.1<=luminance.read()&&luminance.read()<=0.3){
+ led_R=0; led_G=0; led_B=1;} // yellow LED on
+
+ else{
+ led_R=1; led_G=1; led_B=1;} // led off
+ }
+ wait(1);
}
-
-}
-
+}
\ No newline at end of file
