pet feeder system ver 0.2 (add timer alert)

Dependencies:   SDFileSystem SNTPClient WIZnetInterface httpServer_ntpsetting mbed

Fork of PetfeederWebServer by justin kim

Committer:
justinkim
Date:
Thu Jul 07 23:54:59 2016 +0000
Revision:
26:143e4192ce3e
Parent:
25:3fc1c4fa6b15
aaa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
justinkim 8:f837e0d255e8 1 #include "mbed.h"
justinkim 8:f837e0d255e8 2 #include "EthernetInterface.h"
hjjeon 14:9202a7785974 3 #include "FsHandler.h"
hjjeon 14:9202a7785974 4 #include "HTTPServer.h"
hjjeon 14:9202a7785974 5 #include "SDFileSystem.h"
hjjeon 9:a63ff95c354b 6
justinkim 25:3fc1c4fa6b15 7 #define DHCP
justinkim 25:3fc1c4fa6b15 8
justinkim 25:3fc1c4fa6b15 9 #if defined(TARGET_WIZWIKI_W7500)||defined(TARGET_WIZWIKI_W7500P)||defined(TARGET_WIZWIKI_W7500ECO)
hjjeon 17:be86c9b2cbda 10 //Choose one of file system.
hjjeon 14:9202a7785974 11 SDFileSystem local(SD_MOSI, SD_MISO, SD_CLK, SD_SEL, "local");//PB_3, PB_2, PB_1, PB_0
hjjeon 17:be86c9b2cbda 12 //LocalFileSystem local("local");
hjjeon 14:9202a7785974 13 #endif
hjjeon 9:a63ff95c354b 14
justinkim 25:3fc1c4fa6b15 15 #if defined(TARGET_WIZWIKI_W7500)||defined(TARGET_WIZWIKI_W7500P)||defined(TARGET_WIZWIKI_W7500ECO)
justinkim 25:3fc1c4fa6b15 16 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0xff, 0xff, 0x10};
hjjeon 14:9202a7785974 17 #endif
hjjeon 14:9202a7785974 18
hjjeon 14:9202a7785974 19 EthernetInterface eth;
hjjeon 14:9202a7785974 20 HTTPServer svr;
justinkim 25:3fc1c4fa6b15 21
irinakim 21:a5e91b90d7a3 22 char ip_addr[] = "192.168.240.111";
hjjeon 14:9202a7785974 23 char subnet_mask[] = "255.255.255.0";
irinakim 21:a5e91b90d7a3 24 char gateway_addr[] = "192.168.240.1";
hjjeon 14:9202a7785974 25
justinkim 25:3fc1c4fa6b15 26 int flag_t = 1;
justinkim 25:3fc1c4fa6b15 27 int hour_r, min_r, hm_r = 2460, hm_n = 0;
justinkim 25:3fc1c4fa6b15 28 double duty;
justinkim 25:3fc1c4fa6b15 29
justinkim 25:3fc1c4fa6b15 30 //ymd_buffer[0]~[3] : Year
justinkim 25:3fc1c4fa6b15 31 //ymd_buffer[4]~[5] : Month
justinkim 25:3fc1c4fa6b15 32 //ymd_buffer[6]~[7] : Day
justinkim 25:3fc1c4fa6b15 33 char ymd_buffer[8];
justinkim 25:3fc1c4fa6b15 34 //hms_buffer[0]~[1] : Hour
justinkim 25:3fc1c4fa6b15 35 //hms_buffer[2]~[3] : Minute
justinkim 25:3fc1c4fa6b15 36 //hms_buffer[4]~[5] : Second
justinkim 25:3fc1c4fa6b15 37 char hms_buffer[6];
justinkim 25:3fc1c4fa6b15 38
hjjeon 15:0091888ada99 39 //#define DHCP //If uncomment, W7500 runs DHCP
hjjeon 14:9202a7785974 40
hjjeon 14:9202a7785974 41 int main()
justinkim 8:f837e0d255e8 42 {
justinkim 19:0ea7e7a9ebae 43 HTTPFsRequestHandler::mount_eth(&eth);
hjjeon 14:9202a7785974 44 HTTPFsRequestHandler::mount("/local/", "/");
hjjeon 14:9202a7785974 45 svr.addHandler<HTTPFsRequestHandler>("/");
hjjeon 14:9202a7785974 46
justinkim 25:3fc1c4fa6b15 47 #if defined(TARGET_WIZWIKI_W7500)||defined(TARGET_WIZWIKI_W7500P)||defined(TARGET_WIZWIKI_W7500ECO)
hjjeon 14:9202a7785974 48
hjjeon 14:9202a7785974 49 #ifdef DHCP
hjjeon 14:9202a7785974 50 eth.init(mac_addr); //Use DHCP
hjjeon 14:9202a7785974 51 #else
hjjeon 14:9202a7785974 52 eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); //Not Use DHCP
hjjeon 14:9202a7785974 53 #endif
hjjeon 14:9202a7785974 54
hjjeon 14:9202a7785974 55 #else
hjjeon 14:9202a7785974 56
hjjeon 14:9202a7785974 57 #ifdef DHCP
hjjeon 14:9202a7785974 58 eth.init(); //Use DHCP
hjjeon 14:9202a7785974 59 #else
hjjeon 14:9202a7785974 60 eth.init(ip_addr, subnet_mask, gateway_addr); //Not Use DHCP
hjjeon 14:9202a7785974 61 #endif
hjjeon 14:9202a7785974 62
hjjeon 14:9202a7785974 63 #endif
hjjeon 14:9202a7785974 64
hjjeon 18:5d96484995cf 65 printf("Check Ethernet Link\r\n");
hjjeon 18:5d96484995cf 66 while(1) //Wait link up
hjjeon 18:5d96484995cf 67 {
hjjeon 18:5d96484995cf 68 if(eth.link() == true)
hjjeon 18:5d96484995cf 69 break;
hjjeon 18:5d96484995cf 70 }
hjjeon 18:5d96484995cf 71 printf("Link up\r\n");
hjjeon 14:9202a7785974 72
justinkim 8:f837e0d255e8 73 eth.connect();
justinkim 25:3fc1c4fa6b15 74
justinkim 8:f837e0d255e8 75 printf("Server IP Address is %s\r\n", eth.getIPAddress());
hjjeon 14:9202a7785974 76
hjjeon 14:9202a7785974 77 if (!svr.start(80, &eth)) {
hjjeon 14:9202a7785974 78
hjjeon 14:9202a7785974 79 error("Server not starting !");
hjjeon 14:9202a7785974 80 exit(0);
hjjeon 14:9202a7785974 81 }
hjjeon 14:9202a7785974 82
hjjeon 14:9202a7785974 83 while(1) {
hjjeon 14:9202a7785974 84 svr.poll();
justinkim 25:3fc1c4fa6b15 85
justinkim 25:3fc1c4fa6b15 86 time_t seconds = time(NULL);
justinkim 25:3fc1c4fa6b15 87 strftime(hms_buffer, 6, "%H%M%S\n\r", localtime(&seconds));
justinkim 25:3fc1c4fa6b15 88 hm_n = atoi(hms_buffer);
justinkim 25:3fc1c4fa6b15 89 hm_n = hm_n / 100;
justinkim 25:3fc1c4fa6b15 90
justinkim 25:3fc1c4fa6b15 91 if(hm_r == hm_n)
justinkim 25:3fc1c4fa6b15 92 {
justinkim 25:3fc1c4fa6b15 93 if(flag_t)
justinkim 25:3fc1c4fa6b15 94 {
justinkim 25:3fc1c4fa6b15 95 duty = 0.2;
justinkim 25:3fc1c4fa6b15 96 myservo = duty;
justinkim 25:3fc1c4fa6b15 97 wait(5);
justinkim 25:3fc1c4fa6b15 98 duty = 1;
justinkim 25:3fc1c4fa6b15 99 myservo = duty;
justinkim 25:3fc1c4fa6b15 100 flag_t = 0;
justinkim 25:3fc1c4fa6b15 101 }
justinkim 25:3fc1c4fa6b15 102 }
hjjeon 14:9202a7785974 103 }
justinkim 8:f837e0d255e8 104 }
justinkim 8:f837e0d255e8 105