This is WIZwiki-REST-io upper version. This version possible to handle PWM, I2C, GPIO.
Dependencies: Adafruit_GFX MbedJSONValue_copy WIZnetInterface mbed
Fork of WIZwiki-REST-io by
Revision 2:ca36ecca24c2, committed 2016-05-03
- Comitter:
- joon874
- Date:
- Tue May 03 02:15:59 2016 +0000
- Parent:
- 1:728e5b5c8dae
- Child:
- 3:31ffbba7e8e9
- Commit message:
- Revision 2016.05.03
Changed in this revision
--- a/HTTPServer.cpp Tue Apr 05 11:40:33 2016 +0000
+++ b/HTTPServer.cpp Tue May 03 02:15:59 2016 +0000
@@ -60,7 +60,9 @@
}
else if(n != -1)
{
+#ifdef DEBUG_HTTP
printf("Received data : %d\r\n",n);
+#endif
HTTPBUF[n] = '\0';
if(handle_request(HTTPBUF) == HTTP_SUCCESS)
@@ -90,26 +92,33 @@
//{"Name":"WIZwiki-REST-01","Network":{"IP":"192.168.100.100","SN":"255.255.255.0","GW":"192.168.100.1"},"User":{"Name":"Lawrence","ID":"law","PSWD":"law1234"}} 159
if(buffer)
{
+#ifdef DEBUG_HTTP
// buffer check
printf("*******************************************************\r\n");
printf("buffer=%s\r\n",buffer);
printf("*******************************************************\r\n");
-
+#endif
// type parsing
request_type = strtok(buffer," \r\n");
+#ifdef DEBUG_HTTP
printf("Type = %s\r\n", request_type);
+#endif
if(request_type)
{
request = strtok(NULL, " \r\n"); // corrested " " -> " /" : /Name -> Name
if(request)
{
+#ifdef DEBUG_HTTP
printf("URI = %s\r\n", request);
+#endif
}
else
{
strcpy(rest_result, "Invaild URI");
+#ifdef DEBUG_HTTP
printf("%s\r\n",rest_result);
+#endif
return HTTP_INVALID_URI;
}
}
--- a/HTTPServer.h Tue Apr 05 11:40:33 2016 +0000
+++ b/HTTPServer.h Tue May 03 02:15:59 2016 +0000
@@ -8,6 +8,8 @@
#include "RequestHandler.h"
#include "EthernetInterface.h"
+//#define DEBUG_HTTP
+
typedef enum _HTTP_RESULT
{
HTTP_INVALID_URI = -3,
--- a/MbedJSONValue.lib Tue Apr 05 11:40:33 2016 +0000 +++ b/MbedJSONValue.lib Tue May 03 02:15:59 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/MidnightCow/code/MbedJSONValue/#f8bec9cada34 +https://developer.mbed.org/users/MidnightCow/code/MbedJSONValue/#174bc7a49aa2
--- a/RequestHandler.cpp Tue Apr 05 11:40:33 2016 +0000
+++ b/RequestHandler.cpp Tue May 03 02:15:59 2016 +0000
@@ -12,85 +12,97 @@
char* tok;
char* last;
-
+ const char * pchar = 0;
+#ifdef DEBUG_HTTPREQ
printf("GetRequestHandler():%s\r\n",rest_uri);
-
+#endif
if(!strcmp(rest_uri, "/"))
{
- strcpy(reply, WIZwikiREST.serialize().c_str());
- return;
+ tmpJson = &WIZwikiREST;
}
+ else
+ {
tok = strtok_r(rest_uri+1, "/", &last); // 20160226
tmpJson = &WIZwikiREST;
-
- char depth = 0;
- char* name = 0;
- while(tok)
- {
- printf("tok = %s \r\n", tok); // Name
- if(tmpJson->hasMember(tok))
+
+ char depth = 0;
+ char* name = 0;
+ while(tok)
+ {
+#ifdef DEBUG_HTTPREQ
+ printf("tok = %s \r\n", tok); // Name
+#endif
+ if(tmpJson->hasMember(tok))
+ {
+ tmpJson = &((*tmpJson)[tok]);
+ name = tok;
+ tok = strtok_r(0, "/", &last);
+ depth++;
+ }
+ else
+ {
+#ifdef DEBUG_HTTPREQ
+ printf("No Member\r\n");
+#endif
+ break;
+ }
+ }
+ if(name)
{
- tmpJson = &((*tmpJson)[tok]);
- name = tok;
- tok = strtok_r(0, "/", &last);
- depth++;
+ if(tok)
+ {
+ if(tmpJson->accessible)
+ {
+#ifdef DEBUG_HTTPREQ
+ printf("accessible : tmpJson->size()=%d\r\n",tmpJson->size());
+#endif
+
+ if(tmpJson->size() > 0) {
+ *tmpJson = std::string(tok);
+ tmpJson->cb_action((void*)tok);
+#ifdef DEBUG_HTTPREQ
+ printf("set string:%s\r\n",tok);
+#endif
+ }
+ else {
+ *tmpJson = atoi(tok);
+ tmpJson->cb_action(&tmpJson->_value);
+#ifdef DEBUG_HTTPREQ
+ printf("set int:%d\r\n",atoi(tok));
+#endif
+ }
+ }
+ else
+ {
+ strcpy (reply, "HTTP/1.1 403 OK\r\n");
+ strcat (reply, "Sever: WIZwiki-REST\r\n");
+ strcat (reply, "content-Type: text/json\r\n");
+ sprintf(reply + strlen(reply), "Content-Length: %d\r\n\r\n", 26+4);
+ strcat(reply, "{\"Result : No Accessible\"}");
+ strcat (reply, "\r\n\r\n");
+ return;
+ }
+ }
}
else
{
- printf("No Member\r\n");
- break;
+ strcpy (reply, "HTTP/1.1 404 OK\r\n");
+ strcat (reply, "Sever: WIZwiki-REST\r\n");
+ strcat (reply, "content-Type: text/json\r\n");
+ sprintf(reply + strlen(reply), "Content-Length: %d\r\n\r\n", 33+4);
+ strcat(reply, "{\"Result\" : \"No defined Resource\"}");
+ strcat (reply, "\r\n\r\n");
+ return;
}
}
- /*
- if(tmpJson && tmpJson->size() > 0)
- {
- strcpy(reply, (*tmpJson).serialize().c_str());
- }
- else
- {
- strcpy(reply, "{\"Result\" : \"No defined Resource\"}");
- }
- */
- /*
- if(name)
- {
- printf("name=%s, tok=%s\r\n",name,tok);
- if(tok)
- {
- if(depth == 2)
- {
- if(!strcmp(name, "MAC"))
- strcpy(reply, "{\"Result\" : \"No Accessible\"}");
- else
- {
- if(tmpJson->size() > 0) *tmpJson = std::string(tok);
- else *tmpJson = atoi(tok);
- strcpy(reply, (*tmpJson).serialize().c_str());
- }
- }
- else if(depth == 1) strcpy(reply, "{\"Result : No Accessible\"}");
- }
- else strcpy(reply, (*tmpJson).serialize().c_str());
- return;
- }
- strcpy(reply, "{\"Result\" : \"No defined Resource\"}");
- */
- if(name)
- {
- if(tok)
- {
- if(tmpJson->accessible)
- {
- printf("accessible : tmpJson->size()=%d\r\n",tmpJson->size());
- if(tmpJson->size() > 0) {*tmpJson = std::string(tok); tmpJson->cb_action((void*)tok); printf("set string:%s\r\n",tok);}
- else {*tmpJson = atoi(tok); tmpJson->cb_action(&tmpJson->_value); printf("set int:%d\r\n",atoi(tok));}
- strcpy(reply, (*tmpJson).serialize().c_str());
- }
- else strcpy(reply, "{\"Result : No Accessible\"}");
- }
- else strcpy(reply, (*tmpJson).serialize().c_str());
- }
- else strcpy(reply, "{\"Result\" : \"No defined Resource\"}");
+ pchar = (*tmpJson).serialize().c_str();
+ strcpy (reply, "HTTP/1.1 200 OK\r\n");
+ strcat (reply, "Sever: WIZwiki-REST\r\n");
+ strcat (reply, "content-Type: text/json\r\n");
+ sprintf(reply + strlen(reply), "Content-Length: %d\r\n\r\n", strlen(pchar)+4);
+ strcat (reply, pchar);
+ strcat (reply, "\r\n\r\n");
+
return;
}
@@ -101,5 +113,3 @@
void DeleteRequestHandler::handle(char* rest_uri, char *reply)
{
}
-
-
--- a/RequestHandler.h Tue Apr 05 11:40:33 2016 +0000
+++ b/RequestHandler.h Tue May 03 02:15:59 2016 +0000
@@ -1,6 +1,8 @@
#ifndef __REQUESTHANDLER_H_
#define __REQUESTHANDLER_H_
+//#define DEBUG_HTTPREQ
+
class RequestHandler
{
public :
--- a/main.cpp Tue Apr 05 11:40:33 2016 +0000
+++ b/main.cpp Tue May 03 02:15:59 2016 +0000
@@ -6,6 +6,8 @@
#define SERVER_PORT 80
+#define DHCP
+
EthernetInterface eth;
HTTPServer WIZwikiWebSvr;
MbedJSONValue WIZwikiREST;
@@ -228,14 +230,62 @@
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]);
//GPIO Set
GP05.output();
- GP05.write(0);
- GP06.input();
+ GP05.write(1);
+ GP06.output();
+ GP06.write(1);
+ GP07.output();
+ GP07.write(1);
+ GP08.output();
+ GP08.write(1);
+ GP09.output();
+ GP09.write(1);
+ GP10.output();
+ GP10.write(1);
+ GP11.output();
+ GP11.write(1);
+ GP12.output();
+ GP12.write(1);
+ GP13.output();
+ GP13.write(1);
+ GP14.output();
+ GP14.write(1);
+ GP15.output();
+ GP15.write(1);
+ GP16.output();
+ GP16.write(1);
+ GP17.output();
+ GP17.write(1);
+ GP18.output();
+ GP18.write(1);
+ GP19.output();
+ GP19.write(1);
+ GP20.output();
+ GP20.write(1);
+ GP21.output();
+ GP21.write(1);
+ GP22.output();
+ GP22.write(1);
+ GP23.output();
+ GP23.write(1);
+ GP24.output();
+ GP24.write(1);
+ GP25.output();
+ GP25.write(1);
+ GP26.output();
+ GP26.write(1);
+ GP27.output();
+ GP27.write(1);
+ GP28.output();
+ GP28.write(1);
+ GP29.output();
+ GP29.write(1);
+
//LED Setbit
LED_1.write(0); // LED On
@@ -266,13 +316,30 @@
eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); //Not Use DHCP
#endif
+
printf("Check Ethernet Link\r\n");
-
- while(1) //Wait link up
+ //Add
+ 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
{
- if(eth.link() == true)
- break;
+ 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());
}
+
+ //while(1) //Wait link up
+ //{
+ // if(eth.link() == true)
+ // break;
+ //}
printf("Link up\r\n");
printf("IP Address is %s\r\n", eth.getIPAddress());
@@ -394,6 +461,7 @@
WIZwikiREST["GPIOs"]["P29"] = GP29.read();
WIZwikiREST["GPIOs"]["P29"].accessible = true;
WIZwikiREST["GPIOs"]["P29"].cb_action = p29_set;
+/*
WIZwikiREST["GPIOs"]["P30"] = GP30.read();
WIZwikiREST["GPIOs"]["P30"].accessible = true;
WIZwikiREST["GPIOs"]["P30"].cb_action = p30_set;
@@ -403,6 +471,6 @@
WIZwikiREST["GPIOs"]["P32"] = GP32.read();
WIZwikiREST["GPIOs"]["P32"].accessible = true;
WIZwikiREST["GPIOs"]["P32"].cb_action = p32_set;
-
+*/
debug_info();
}
