![](/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
Diff: main.cpp
- Revision:
- 9:f7d5a168a693
- Parent:
- 8:60d99da6eeb2
- Child:
- 10:fe96beb315e3
--- a/main.cpp Mon Sep 05 06:29:55 2016 +0000 +++ b/main.cpp Thu Oct 06 04:13:57 2016 +0000 @@ -3,149 +3,56 @@ #include "RequestHandler.h" #include "EthernetInterface.h" #include "MbedJSONValue.h" +#include "DHT.h" #define SERVER_PORT 80 //#define DHCP -//#define DEBUG -//-- I2C OLED -- -#include "Adafruit_SSD1306.h" - -class I2CPreInit : public I2C -{ -public: - I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) - { - frequency(100000); - start(); - }; -}; - -//-- I2C OLED -- -I2CPreInit gI2C(PA_10,PA_9); -Adafruit_SSD1306_I2c gOled(gI2C,NC,0x78,64,128); - -//-- PWM DC -- -PwmOut DC(D6); //-- GPIO LED -- -DigitalInOut GP05(D5); - -DigitalInOut GP04(D4); -DigitalInOut GP03(D3); - +// GPIO Pin 선언 //-- ADC -- -AnalogIn ain(A0); +// 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"; -float ain_value; -GetRequestHandler myGetReq; -//PostRequestHandler myPostReq; -PutRequestHandler myPutReq; -//-- I2C OLED -- -bool oled_set(void* param) -{ - char * oled; - if(!param) return false; - oled = (char*) param; - gOled.clearDisplay(); - gOled.setTextCursor(0,0); - gOled.printf("%s",oled); - gOled.display(); - return true; -} -//-- PWM DC -- -bool pwm_set(void* param) -{ - if(!param) return false; - DC.write((float)(*(int*)param)/100.0); - return true; -} +//-- Callback 함수 구현 //-- GPIO -- -bool p5_set(void* param) -{ - if(!param) return false; - GP05.write(*(int*)param); - return true; -} -bool p4_set(void* param) -{ - if(!param) return false; - GP04.write(*(int*)param); - return true; -} -bool p3_set(void* param) -{ - if(!param) return false; - GP03.write(*(int*)param); - return true; -} + //-- ADC -- -bool ain_read(void* param) -{ - ((MbedJSONValue*)param)->_value.asDouble = ain.read(); - return true; -} + -void debug_info() -{ - printf("SP:0x%X\r\n",__current_sp()); - __heapstats((__heapprt)fprintf,stderr); -#ifdef DEBUG - __heapvalid((__heapprt)fprintf,stderr, 1); -#endif - printf("\r\n"); -} +//-- DHT -- + + void WIZwiki_REST_init(); int main(void) { -#ifdef DEBUG - debug_info(); -#endif 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]); - - // OLED init - gOled.begin(); - gOled.clearDisplay(); - - // PWM init - DC.period_ms(1); - DC.write(0); - - //GPIO set & init - GP05.output(); - GP05.write(1); - - //ADC init - - printf("START \r\n"); - printf("sizeof(MbedJSONValue)=%d\r\n",sizeof(MbedJSONValue)); - printf("sizeof(vector)=%d\r\n",sizeof(std::vector<string*>)); - printf("sizeof(string)=%d\r\n",sizeof(std::string)); -#ifdef DEBUG - debug_info(); -#endif WIZwiki_REST_init(); - -#ifdef DEBUG - debug_info(); -#endif // Serialize it into a JSON string printf("---------------------WIZwikiREST-------------------- \r\n"); @@ -184,9 +91,6 @@ printf("Link up\r\n"); printf("IP Address is %s\r\n", eth.getIPAddress()); -#ifdef DEBUG - debug_info(); -#endif if(!WIZwikiWebSvr.init(SERVER_PORT)) { @@ -203,11 +107,8 @@ void WIZwiki_REST_init(void) { //Fill the object - WIZwikiREST["Name"] = "WIZwikiREST-io ver1.01"; + WIZwikiREST["Name"] = "WIZwikiREST-io WIZnet Academy"; WIZwikiREST["Name"].accessible = false; -#ifdef DEBUG - debug_info(); -#endif //Network WIZwikiREST["Network"]["MAC"] = mac_str; @@ -217,34 +118,15 @@ WIZwikiREST["Network"]["SN"].accessible = true; WIZwikiREST["Network"]["GW"] = gateway_addr; WIZwikiREST["Network"]["GW"].accessible = true; - - // I2C OLED - WIZwikiREST["I2C"]["OLED"] = "none"; - WIZwikiREST["I2C"]["OLED"].accessible = true; - WIZwikiREST["I2C"]["OLED"].cb_action = oled_set; - - // PWM DC - WIZwikiREST["PWM"]["DC"] = DC.read(); - WIZwikiREST["PWM"]["DC"].accessible = true; - WIZwikiREST["PWM"]["DC"].cb_action = pwm_set; + + //Object 생성 + // GPIO - // GPIO - WIZwikiREST["GPIOs"]["P03"] = GP03.read(); - WIZwikiREST["GPIOs"]["P03"].accessible = true; - WIZwikiREST["GPIOs"]["P03"].cb_action = p3_set; - WIZwikiREST["GPIOs"]["P04"] = GP04.read(); - WIZwikiREST["GPIOs"]["P04"].accessible = true; - WIZwikiREST["GPIOs"]["P04"].cb_action = p4_set;\ - WIZwikiREST["GPIOs"]["P05"] = GP05.read(); - WIZwikiREST["GPIOs"]["P05"].accessible = true; - WIZwikiREST["GPIOs"]["P05"].cb_action = p5_set; // ADC - WIZwikiREST["ADC"]["A0"] = ain.read(); - WIZwikiREST["ADC"]["A0"].accessible = false; - WIZwikiREST["ADC"]["A0"].cb_action = ain_read; - -#ifdef DEBUG - debug_info(); -#endif + + + // DHT11 + + }