WIZwikiREST ver1.0 (Memory problem)

Dependencies:   MbedJSONValue WIZnetInterface mbed

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 
00007 #define SERVER_PORT 80
00008 
00009 EthernetInterface eth;
00010 HTTPServer WIZwikiWebSvr;
00011 MbedJSONValue WIZwikiREST;
00012 
00013 // Enter a MAC address for your controller below.
00014 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0xFE};
00015 char mac_str[20];
00016 char ip_addr[] = "192.168.100.100";
00017 char subnet_mask[] = "255.255.255.0";
00018 char gateway_addr[] = "192.168.100.1";
00019 
00020 DigitalOut LED_1(PA_1);
00021 DigitalOut LED_2(PA_2);
00022 
00023 DigitalInOut P05(P5);
00024 DigitalInOut P06(P6);
00025 
00026 void WIZwiki_REST_init();
00027 
00028 int main(void)
00029 {
00030     sprintf(mac_str, "%02X:%02X:%02X:%02X:%02X:%02X",mac_addr[0],mac_addr[1],
00031                                                      mac_addr[2],mac_addr[3], 
00032                                                      mac_addr[4],mac_addr[5]);
00033     //GPIO Set
00034     P05.output();
00035     P05.write(1);
00036     P06.input();
00037     
00038     //LED Setbit
00039     LED_1.write(0); // LED On
00040     LED_2.write(1); // LED Off
00041 
00042     WIZwiki_REST_init();
00043                 
00044     // Serialize it into a JSON string
00045     printf("\r\n");
00046     printf("-------------------------WIZwikiREST--------------------------- \r\n");
00047     printf("%s\r\n", WIZwikiREST.serialize().c_str());
00048     printf("--------------------------------------------------------------- \r\n");
00049 
00050     WIZwikiWebSvr.add_request_handler("GET", new GetRequestHandler());
00051     //WIZwikiWebSvr.add_request_handler("DELETE", new DeleteRequestHandler());
00052     //WIZwikiWebSvr.add_request_handler("PUT", new PutRequestHandler());
00053     
00054     #ifdef DHCP
00055         eth.init(mac_addr); //Use DHCP
00056     #else
00057         eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); //Not Use DHCP
00058     #endif
00059     
00060     printf("Check Ethernet Link\r\n");
00061     
00062     while(1) //Wait link up
00063     {
00064         if(eth.link() == true) 
00065         break;
00066     }
00067     
00068     printf("Link up\r\n");
00069     printf("IP Address is %s\r\n", eth.getIPAddress());
00070 
00071     if(!WIZwikiWebSvr.init(SERVER_PORT))
00072     {
00073         eth.disconnect();
00074         return -1;
00075     }
00076 
00077     while(1)
00078     {
00079         WIZwikiWebSvr.run();
00080     }
00081 }
00082 
00083 void WIZwiki_REST_init(void)
00084 {
00085     //Fill the object
00086     WIZwikiREST["Name"] = "WIZwiki-REST-01";
00087     //Network
00088     WIZwikiREST["Network"]["MAC"] = mac_str;
00089     WIZwikiREST["Network"]["IP"] = ip_addr; 
00090     WIZwikiREST["Network"]["SN"] = subnet_mask;  
00091     WIZwikiREST["Network"]["GW"] = gateway_addr;
00092     //LEDs
00093     WIZwikiREST["LEDs"]["LED_1"]["Value"] = (LED_1.read() ? "Off" : "On");
00094     WIZwikiREST["LEDs"]["LED_2"]["Value"] = (LED_2.read() ? "Off" : "On");
00095     
00096     // GPIOs
00097     WIZwikiREST["GPIOs"]["P05"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_5) ? "Output" : "Input");
00098     WIZwikiREST["GPIOs"]["P05"]["Value"] = (P05.read() ? "1" : "0");
00099     WIZwikiREST["GPIOs"]["P06"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_6) ? "Output" : "Input");
00100     WIZwikiREST["GPIOs"]["P06"]["Value"] = (P06.read() ? "1" : "0");
00101 //  WIZwikiREST["GPIOs"]["P07"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_7) ? "Output" : "Input");
00102 //  WIZwikiREST["GPIOs"]["P07"]["Value"] = (P07.read() ? "1" : "0");
00103 //  WIZwikiREST["GPIOs"]["P08"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_8) ? "Output" : "Input");
00104 //  WIZwikiREST["GPIOs"]["P08"]["Value"] = (P08.read() ? "1" : "0");
00105 //  WIZwikiREST["GPIOs"]["P09"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_9) ? "Output" : "Input");
00106 //  WIZwikiREST["GPIOs"]["P09"]["Value"] = (P09.read() ? "1" : "0");
00107 //  WIZwikiREST["GPIOs"]["P10"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_10) ? "Output" : "Input");
00108 //  WIZwikiREST["GPIOs"]["P10"]["Value"] = (P10.read() ? "1" : "0");
00109 //  WIZwikiREST["GPIOs"]["P11"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_11) ? "Output" : "Input");
00110 //  WIZwikiREST["GPIOs"]["P11"]["Value"] = (P11.read() ? "1" : "0");
00111 //  WIZwikiREST["GPIOs"]["P12"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_12) ? "Output" : "Input");
00112 //  WIZwikiREST["GPIOs"]["P12"]["Value"] = (P12.read() ? "1" : "0");
00113 //  WIZwikiREST["GPIOs"]["P13"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_13) ? "Output" : "Input");
00114 //  WIZwikiREST["GPIOs"]["P13"]["Value"] = (P13.read() ? "1" : "0");
00115 //  WIZwikiREST["GPIOs"]["P14"]["Mode"] = ((GPIOA->OUTENSET&GPIO_Pin_14) ? "Output" : "Input");
00116 //  WIZwikiREST["GPIOs"]["P14"]["Value"] = (P14.read() ? "1" : "0");
00117 //  WIZwikiREST["GPIOs"]["P15"]["Mode"] = ((GPIOB->OUTENSET&GPIO_Pin_0) ? "Output" : "Input");
00118 //  WIZwikiREST["GPIOs"]["P15"]["Value"] = (P15.read() ? "1" : "0");
00119 //  WIZwikiREST["GPIOs"]["P16"]["Mode"] = ((GPIOB->OUTENSET&GPIO_Pin_1) ? "Output" : "Input");
00120 //  WIZwikiREST["GPIOs"]["P16"]["Value"] = (P16.read() ? "1" : "0");
00121 //  WIZwikiREST["GPIOs"]["P17"]["Mode"] = ((GPIOB->OUTENSET&GPIO_Pin_2) ? "Output" : "Input");
00122 //  WIZwikiREST["GPIOs"]["P17"]["Value"] = (P17.read() ? "1" : "0");
00123 //  WIZwikiREST["GPIOs"]["P18"]["Mode"] = ((GPIOB->OUTENSET&GPIO_Pin_3) ? "Output" : "Input");
00124 //  WIZwikiREST["GPIOs"]["P18"]["Value"] = (P18.read() ? "1" : "0");
00125 //  WIZwikiREST["GPIOs"]["P19"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_8) ? "Output" : "Input");
00126 //  WIZwikiREST["GPIOs"]["P19"]["Value"] = (P19.read() ? "1" : "0");
00127 //  WIZwikiREST["GPIOs"]["P20"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_4) ? "Output" : "Input");
00128 //  WIZwikiREST["GPIOs"]["P20"]["Value"] = (P20.read() ? "1" : "0");
00129 //  WIZwikiREST["GPIOs"]["P21"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_0) ? "Output" : "Input");
00130 //  WIZwikiREST["GPIOs"]["P21"]["Value"] = (P21.read() ? "1" : "0");
00131 //  WIZwikiREST["GPIOs"]["P22"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_1) ? "Output" : "Input");
00132 //  WIZwikiREST["GPIOs"]["P22"]["Value"] = (P22.read() ? "1" : "0");
00133 //  WIZwikiREST["GPIOs"]["P23"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_2) ? "Output" : "Input");
00134 //  WIZwikiREST["GPIOs"]["P23"]["Value"] = (P23.read() ? "1" : "0");
00135 //  WIZwikiREST["GPIOs"]["P24"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_3) ? "Output" : "Input");
00136 //  WIZwikiREST["GPIOs"]["P24"]["Value"] = (P24.read() ? "1" : "0");
00137 //  WIZwikiREST["GPIOs"]["P25"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_9) ? "Output" : "Input");
00138 //  WIZwikiREST["GPIOs"]["P25"]["Value"] = (P25.read() ? "1" : "0");
00139 //  WIZwikiREST["GPIOs"]["P26"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_5) ? "Output" : "Input");
00140 //  WIZwikiREST["GPIOs"]["P26"]["Value"] = (P26.read() ? "1" : "0");
00141 //  WIZwikiREST["GPIOs"]["P27"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_12) ? "Output" : "Input");
00142 //  WIZwikiREST["GPIOs"]["P27"]["Value"] = (P27.read() ? "1" : "0");
00143 //  WIZwikiREST["GPIOs"]["P28"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_13) ? "Output" : "Input");
00144 //  WIZwikiREST["GPIOs"]["P28"]["Value"] = (P28.read() ? "1" : "0");
00145 //  WIZwikiREST["GPIOs"]["P29"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_14) ? "Output" : "Input");
00146 //  WIZwikiREST["GPIOs"]["P29"]["Value"] = (P29.read() ? "1" : "0");
00147 //  WIZwikiREST["GPIOs"]["P30"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_15) ? "Output" : "Input");
00148 //  WIZwikiREST["GPIOs"]["P30"]["Value"] = (P30.read() ? "1" : "0");
00149 //  WIZwikiREST["GPIOs"]["P31"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_6) ? "Output" : "Input");
00150 //  WIZwikiREST["GPIOs"]["P31"]["Value"] = (P31.read() ? "1" : "0");
00151 //  WIZwikiREST["GPIOs"]["P32"]["Mode"] = ((GPIOC->OUTENSET&GPIO_Pin_7) ? "Output" : "Input");
00152 //  WIZwikiREST["GPIOs"]["P32"]["Value"] = (P32.read() ? "1" : "0");
00153 }