Upper Version Add PUT method Delete POST method

Dependencies:   Adafruit_GFX MbedJSONValue_v102 WIZnetInterface mbed

Fork of WIZwiki-REST-io_v102 by Lawrence Lee

Revision:
8:60d99da6eeb2
Parent:
6:2974bbc94e7a
--- a/main.cpp	Fri Jul 29 08:15:34 2016 +0000
+++ b/main.cpp	Mon Sep 05 06:29:55 2016 +0000
@@ -3,16 +3,14 @@
 #include "RequestHandler.h"
 #include "EthernetInterface.h"
 #include "MbedJSONValue.h"
-// 20160630
-#include "Adafruit_SSD1306.h"
 
 #define SERVER_PORT 80
-
-#define DHCP
-
+//#define DHCP
 //#define DEBUG
 
 //-- I2C OLED --
+#include "Adafruit_SSD1306.h"
+
 class I2CPreInit : public I2C
 {
 public:
@@ -33,6 +31,10 @@
 //-- GPIO LED --
 DigitalInOut GP05(D5);
 
+DigitalInOut GP04(D4);
+DigitalInOut GP03(D3);
+
+
 //-- ADC --
 AnalogIn   ain(A0);
 
@@ -48,8 +50,9 @@
 char gateway_addr[] = "192.168.100.1";
 float ain_value;
 
-GetRequestHandler myGetReq;
-PostRequestHandler myPostReq;
+GetRequestHandler  myGetReq;
+//PostRequestHandler myPostReq;
+PutRequestHandler  myPutReq;
 
 //-- I2C OLED --
 bool oled_set(void* param)
@@ -77,6 +80,19 @@
     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)
 {
@@ -116,8 +132,7 @@
     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*>));
@@ -133,14 +148,14 @@
 #endif
                     
     // Serialize it into a JSON string
-    printf("-------------------------WIZwikiREST--------------------------- \r\n");
+    printf("---------------------WIZwikiREST-------------------- \r\n");
     printf("\r\n%s\r\n", WIZwikiREST.serialize().c_str());
-    printf("--------------------------------------------------------------- \r\n");
+    printf("---------------------------------------------------- \r\n");
 
     WIZwikiWebSvr.add_request_handler("GET", &myGetReq);
-    WIZwikiWebSvr.add_request_handler("POST", &myPostReq);
+    //WIZwikiWebSvr.add_request_handler("POST", &myPostReq);
+    WIZwikiWebSvr.add_request_handler("PUT", &myPutReq);
     //WIZwikiWebSvr.add_request_handler("DELETE", new PostRequestHandler());
-    //WIZwikiWebSvr.add_request_handler("PUT", new PutRequestHandler());
     
     #ifdef DHCP
         eth.init(mac_addr); //Use DHCP
@@ -214,6 +229,12 @@
     WIZwikiREST["PWM"]["DC"].cb_action = pwm_set;
     
     // 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;