Lawrence Lee / Mbed 2 deprecated WIZwiki-REST-io_WIZnetAcademy

Dependencies:   MbedJSONValue_v102 WIZnetInterface mbed

Fork of WIZwiki-REST-io_v103 by Lawrence Lee

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "HTTPServer.h"
00003 #include "RequestHandler.h"
00004 #include "EthernetInterface.h"
00005 #include "MbedJSONValue.h"
00006 //-- Library Include--
00007 //  DHT11 Lib
00008 
00009 #define SERVER_PORT 80
00010 //#define DHCP
00011 
00012 
00013 //-- GPIO LED --
00014 // GPIO Pin 선언 
00015 
00016 //-- ADC --
00017 // Anlog Pin 선언 
00018 
00019 //-- DHT --
00020 // DHT Class 선언 
00021 
00022 
00023 EthernetInterface eth;
00024 HTTPServer WIZwikiWebSvr;
00025 MbedJSONValue WIZwikiREST;
00026 
00027 GetRequestHandler  myGetReq;
00028 //PostRequestHandler myPostReq;
00029 PutRequestHandler  myPutReq;
00030 
00031 // Enter a MAC address for your controller below.
00032 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0xFE};
00033 char mac_str[20];
00034 char ip_addr[]      = "192.168.100.100";
00035 char subnet_mask[]  = "255.255.255.0";
00036 char gateway_addr[] = "192.168.100.1";
00037 
00038 
00039 //-- Callback 함수 구현
00040 //-- GPIO --
00041 
00042 
00043 //-- ADC --
00044 
00045 
00046 //-- DHT --
00047 
00048  
00049 
00050 void WIZwiki_REST_init();
00051 
00052 int main(void)
00053 {
00054     sprintf(mac_str, "%02X:%02X:%02X:%02X:%02X:%02X",mac_addr[0],mac_addr[1],mac_addr[2],mac_addr[3],mac_addr[4],mac_addr[5]);
00055 
00056     WIZwiki_REST_init();
00057                     
00058     // Serialize it into a JSON string
00059     printf("---------------------WIZwikiREST-------------------- \r\n");
00060     printf("\r\n%s\r\n", WIZwikiREST.serialize().c_str());
00061     printf("---------------------------------------------------- \r\n");
00062 
00063     WIZwikiWebSvr.add_request_handler("GET", &myGetReq);
00064     //WIZwikiWebSvr.add_request_handler("POST", &myPostReq);
00065     WIZwikiWebSvr.add_request_handler("PUT", &myPutReq);
00066     //WIZwikiWebSvr.add_request_handler("DELETE", new PostRequestHandler());
00067     
00068     #ifdef DHCP
00069         eth.init(mac_addr); //Use DHCP
00070     #else
00071         eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); //Not Use DHCP
00072     #endif
00073     
00074     
00075     printf("Check Ethernet Link\r\n");
00076     
00077     do{
00078         printf("   Link - Wait... \r\n");
00079         wait(1);
00080     }while(!eth.ethernet_link());
00081     printf("-- Ethetnet PHY Link - Done -- \r\n");
00082         
00083     if (eth.connect() < 0 )
00084         printf("-- EThernet Connect - Fail -- \r\n");
00085     else
00086     {
00087         printf("-- Assigned Network Information -- \r\n");
00088         printf("   IP   : %s\r\n\r\n", eth.getIPAddress()); 
00089         printf("   MASK : %s\r\n\r\n", eth.getNetworkMask());
00090         printf("   GW   : %s\r\n\r\n", eth.getGateway());
00091     }
00092     
00093     printf("Link up\r\n");
00094     printf("IP Address is %s\r\n", eth.getIPAddress());
00095 
00096     if(!WIZwikiWebSvr.init(SERVER_PORT))
00097     {
00098         eth.disconnect();
00099         return -1;
00100     }
00101 
00102     while(1)
00103     {
00104         WIZwikiWebSvr.run();
00105     }
00106 }
00107 
00108 void WIZwiki_REST_init(void)
00109 {
00110     //Fill the object
00111     WIZwikiREST["Name"] = "WIZwikiREST-io WIZnet Academy";
00112     WIZwikiREST["Name"].accessible = false;
00113     
00114     //Network
00115     WIZwikiREST["Network"]["MAC"] = mac_str;
00116     WIZwikiREST["Network"]["IP"] = ip_addr; 
00117     WIZwikiREST["Network"]["IP"].accessible = true; 
00118     WIZwikiREST["Network"]["SN"] = subnet_mask;  
00119     WIZwikiREST["Network"]["SN"].accessible = true;  
00120     WIZwikiREST["Network"]["GW"] = gateway_addr;
00121     WIZwikiREST["Network"]["GW"].accessible = true;
00122    
00123     //Object 생성 
00124     // GPIO
00125     
00126     
00127     // ADC
00128     
00129     
00130     // DHT11
00131     
00132     
00133 }