![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
WIZwikiREST-io exercise code for WIZnet Academy
Dependencies: MbedJSONValue_v102 WIZnetInterface mbed
Fork of WIZwiki-REST-io_v103 by
main.cpp
- Committer:
- joon874
- Date:
- 2016-10-06
- Revision:
- 10:fe96beb315e3
- Parent:
- 9:f7d5a168a693
File content as of revision 10:fe96beb315e3:
#include "mbed.h" #include "HTTPServer.h" #include "RequestHandler.h" #include "EthernetInterface.h" #include "MbedJSONValue.h" //-- Library Include-- // DHT11 Lib #define SERVER_PORT 80 //#define DHCP //-- GPIO LED -- // GPIO Pin 선언 //-- ADC -- // Anlog Pin 선언 //-- DHT -- // DHT Class 선언 EthernetInterface eth; HTTPServer WIZwikiWebSvr; MbedJSONValue WIZwikiREST; GetRequestHandler myGetReq; //PostRequestHandler myPostReq; PutRequestHandler myPutReq; // Enter a MAC address for your controller below. uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0xFE}; char mac_str[20]; char ip_addr[] = "192.168.100.100"; char subnet_mask[] = "255.255.255.0"; char gateway_addr[] = "192.168.100.1"; //-- Callback 함수 구현 //-- GPIO -- //-- ADC -- //-- DHT -- void WIZwiki_REST_init(); int main(void) { 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]); WIZwiki_REST_init(); // Serialize it into a JSON string printf("---------------------WIZwikiREST-------------------- \r\n"); printf("\r\n%s\r\n", WIZwikiREST.serialize().c_str()); printf("---------------------------------------------------- \r\n"); WIZwikiWebSvr.add_request_handler("GET", &myGetReq); //WIZwikiWebSvr.add_request_handler("POST", &myPostReq); WIZwikiWebSvr.add_request_handler("PUT", &myPutReq); //WIZwikiWebSvr.add_request_handler("DELETE", new PostRequestHandler()); #ifdef DHCP eth.init(mac_addr); //Use DHCP #else eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); //Not Use DHCP #endif printf("Check Ethernet Link\r\n"); do{ printf(" Link - Wait... \r\n"); wait(1); }while(!eth.ethernet_link()); printf("-- Ethetnet PHY Link - Done -- \r\n"); if (eth.connect() < 0 ) printf("-- EThernet Connect - Fail -- \r\n"); else { printf("-- Assigned Network Information -- \r\n"); printf(" IP : %s\r\n\r\n", eth.getIPAddress()); printf(" MASK : %s\r\n\r\n", eth.getNetworkMask()); printf(" GW : %s\r\n\r\n", eth.getGateway()); } printf("Link up\r\n"); printf("IP Address is %s\r\n", eth.getIPAddress()); if(!WIZwikiWebSvr.init(SERVER_PORT)) { eth.disconnect(); return -1; } while(1) { WIZwikiWebSvr.run(); } } void WIZwiki_REST_init(void) { //Fill the object WIZwikiREST["Name"] = "WIZwikiREST-io WIZnet Academy"; WIZwikiREST["Name"].accessible = false; //Network WIZwikiREST["Network"]["MAC"] = mac_str; WIZwikiREST["Network"]["IP"] = ip_addr; WIZwikiREST["Network"]["IP"].accessible = true; WIZwikiREST["Network"]["SN"] = subnet_mask; WIZwikiREST["Network"]["SN"].accessible = true; WIZwikiREST["Network"]["GW"] = gateway_addr; WIZwikiREST["Network"]["GW"].accessible = true; //Object 생성 // GPIO // ADC // DHT11 }