petfeeder st ver
Fork of httpServer_ntpsetting by
Revision 7:2a38bd4be00f, committed 2017-06-09
- Comitter:
- justinkim
- Date:
- Fri Jun 09 04:44:18 2017 +0000
- Parent:
- 6:b33c1a450937
- Commit message:
- petfeeder st ver
Changed in this revision
diff -r b33c1a450937 -r 2a38bd4be00f HTTPRequestHandler.cpp --- a/HTTPRequestHandler.cpp Thu Jul 07 23:53:18 2016 +0000 +++ b/HTTPRequestHandler.cpp Fri Jun 09 04:44:18 2017 +0000 @@ -1,7 +1,7 @@ /* HTTPRequestHandler.cpp */ #include "mbed.h" #include "HTTPRequestHandler.h" -//#define DEBUG +#define DEBUG #include "hl_debug.h" #include <ctype.h>
diff -r b33c1a450937 -r 2a38bd4be00f Handler/FsHandler.cpp --- a/Handler/FsHandler.cpp Thu Jul 07 23:53:18 2016 +0000 +++ b/Handler/FsHandler.cpp Fri Jun 09 04:44:18 2017 +0000 @@ -1,37 +1,14 @@ /* FsHandler.cpp */ #include "mbed.h" #include "FsHandler.h" -//#define DEBUG +#define DEBUG #include "hl_debug.h" #include "stdlib.h" - -DigitalOut led_red(LED1); -DigitalOut led_green(LED2); -DigitalOut led_blue(LED3); +#include <stdio.h> -void SNTP_Connect(void); -void time_set(void); -void time_update(char buffer[]); - -extern int hour_r, min_r,hm_r, hm_n; -extern int flag_t; extern double duty; -PwmOut myservo(P10); -datetime ntptime; -struct tm timeinfo; - -uint8_t update_mode = 0; -uint8_t Set_update[3] = {18, 00, 00}; //Hour,Minute,Second - -//ymd_buffer[0]~[3] : Year -//ymd_buffer[4]~[5] : Month -//ymd_buffer[6]~[7] : Day -extern char ymd_buffer[8]; -//hms_buffer[0]~[1] : Hour -//hms_buffer[2]~[3] : Minute -//hms_buffer[4]~[5] : Second -extern char hms_buffer[6]; +PwmOut myservo(PC_6); static int matchstrings(const char* one, const char* two) { @@ -87,7 +64,7 @@ int HTTPFsRequestHandler::handleGetRequest() { HTTPHeaders headers; - EthernetInterface test_eth; + //EthernetInterface test_eth; int retval = 0; //success if( std::string::npos != msg.uri.find("get_netinfo.cgi") ) @@ -111,6 +88,7 @@ else //read html pages { + //printf("test100"); if (m_localPath.length() > 4) getStandardHeaders(headers, m_localPath.substr(m_localPath.length()-4).c_str()); else @@ -129,8 +107,10 @@ reqPath = m_rootPath + m_localPath; INFO("Mapping \"%s\" to \"%s\"", msg.uri.c_str(), reqPath.c_str()); - + +// printf("before open\r\n"); FILE *fp = fopen(reqPath.c_str(), "r"); +// printf("after open\r\n"); if (fp != NULL) { char * pBuffer = NULL; int sz = 8192; @@ -139,25 +119,33 @@ pBuffer = (char*)malloc(sz); if (sz < 128) error ("OutOfMemory"); + +// printf("%d\r\n",sz); } // File was found and can be returned // first determine the size +// printf("fseekstart\r\n"); fseek(fp, 0, SEEK_END); long size = ftell(fp); fseek(fp, 0, SEEK_SET); +// printf("fseekset\r\n"); startResponse(200, size); - while(!feof(fp) && !ferror(fp)) { +// printf("startresponse\r\n"); + while(!(fgetc(fp)==EOF) && !ferror(fp)) { int cnt = fread(pBuffer, 1, sz , fp); if (cnt < 0) cnt = 0; processResponse(cnt, pBuffer); } delete pBuffer; +// printf("response\r\n"); endResponse(); +// printf("endresponse\r\n"); fclose(fp); +// printf("fclose\r\n"); } else { retval = 404; @@ -174,29 +162,7 @@ myservo.period_ms(20); int pin = 0; - if( std::string::npos != msg.uri.find("set_dio.cgi") ) - { - pin = get_http_param_value("pin"); - if(pin == 8) - { - led_red = get_http_param_value("val"); - } - else if(pin == 9) - { - led_green = get_http_param_value("val"); - } - else if(pin == 5) - { - led_blue = get_http_param_value("val"); - } - else - { - WARN("Wrong pin number"); - } - - return 0; - } - else if( std::string::npos != msg.uri.find("set_dio2.cgi") ) + if( std::string::npos != msg.uri.find("set_dio2.cgi") ) { ch = get_http_param_value("pin"); printf("ch : %d \r\n",ch); @@ -232,35 +198,6 @@ printf("duty : %lf\r\n", duty); } } - else if( std::string::npos != msg.uri.find("set_time.cgi") ) - { - hour_r = get_http_param_value("hour"); - min_r = get_http_param_value("min"); - - printf("hour : %d, min : %d\r\n", hour_r, min_r); - - SNTP_Connect(); - time_set(); - - time_t seconds = time(NULL); - - - strftime(ymd_buffer, 8, "%Y%m%d%\n\r", localtime(&seconds)); - - if(hms_buffer[4] == '0' && hms_buffer[5] == '0') - { - time_update(hms_buffer); - printf("update HMS : %s\r\n",hms_buffer); - } - - hm_r = (hour_r*100) + min_r; - hm_n = atoi(hms_buffer); - hm_n = hm_n / 100; - printf("HMr : %d\r\n",hm_r); - printf("HMn : %d\r\n",hm_n); - - flag_t = 1; - } else { return 404; @@ -299,54 +236,3 @@ } return ret; } - -void SNTP_Connect(void) { - printf("Getting time information by using NTP...\r\n"); - - SNTPClient sntp("time.nist.gov", 40); // timezone: Korea, Republic of - sntp.connect(); - if(sntp.getTime(&ntptime) == true) { - printf("%d-%d-%d, %02d:%02d:%02d\r\n", ntptime.yy, ntptime.mo, ntptime.dd, ntptime.hh, ntptime.mm, ntptime.ss); - printf("Completed Get and Set Time\r\n\r\n"); - } - else { - while(sntp.getTime(&ntptime) == true) { - printf("%d-%d-%d, %02d:%02d:%02d\r\n", ntptime.yy, ntptime.mo, ntptime.dd, ntptime.hh, ntptime.mm, ntptime.ss); - printf("Completed Get and Set Time\r\n\r\n"); - break; - } - } - sntp.close(); -} - -void time_set(void) { - timeinfo.tm_mon = ntptime.mo-1; - timeinfo.tm_mday = ntptime.dd; - timeinfo.tm_hour = ntptime.hh; - timeinfo.tm_min = ntptime.mm; - timeinfo.tm_sec = ntptime.ss; - timeinfo.tm_year = ntptime.yy-1900; - time_t t =mktime(&timeinfo); - set_time(t); - t = time(NULL); -} - -void time_update(char buffer[]) { - uint8_t h_buffer = ((buffer[0]-48)*10) + (buffer[1]-48); - uint8_t m_buffer = ((buffer[2]-48)*10) + (buffer[3]-48); - uint8_t s_buffer = ((buffer[4]-48)*10) + (buffer[5]-48); - - if(update_mode == 0){ - if(h_buffer == Set_update[0] && m_buffer == Set_update[1] && s_buffer == Set_update[2]){ - SNTP_Connect(); - time_set(); - update_mode = 1; - printf("Time Update Completed.\n\r\n\r"); - } - } - else if(update_mode == 1){ - if(!(h_buffer == Set_update[0] && m_buffer == Set_update[1] && s_buffer == Set_update[2])){ - update_mode = 0; - } - } -}
diff -r b33c1a450937 -r 2a38bd4be00f Handler/FsHandler.h --- a/Handler/FsHandler.h Thu Jul 07 23:53:18 2016 +0000 +++ b/Handler/FsHandler.h Fri Jun 09 04:44:18 2017 +0000 @@ -26,8 +26,7 @@ #include "mbed.h" #include "HTTPRequestHandler.h" #include "HTTPConnection.h" -#include "EthernetInterface.h" -#include "SNTPClient.h" +#include "HTTPServer.h" #include <map> #include <list> @@ -80,7 +79,7 @@ static void mount(const char* requestPath, const char* localPath) { m_fsMap[requestPath] = localPath; } //Test - //static std::list<EthernetInterface> m_eth_list; +// static std::list<EthernetInterface> m_eth_list; static std::map<int, EthernetInterface*> m_eth_list; static void mount_eth(EthernetInterface* eth) { m_eth_list[0] = eth; } @@ -91,6 +90,5 @@ uint32_t get_http_param_value(char* param_name); }; -extern datetime ntptime; extern PwmOut myservo; #endif // __FSHANDLER_H__