Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MbedJSONValue WIZnetInterface httpServer_with_Ethernt mbed
Fork of Simple_HTTPClient_JSON by
Revision 1:97cf847e16cd, committed 2016-02-25
- Comitter:
- joon874
- Date:
- Thu Feb 25 07:59:46 2016 +0000
- Parent:
- 0:e6cc33c4970b
- Commit message:
- web server json
Changed in this revision
diff -r e6cc33c4970b -r 97cf847e16cd WIZnetInterface.lib --- a/WIZnetInterface.lib Thu Oct 29 08:00:44 2015 +0000 +++ b/WIZnetInterface.lib Thu Feb 25 07:59:46 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/embeddist/code/WIZnetInterface/#1169973d836c +http://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/#c91884bd2713
diff -r e6cc33c4970b -r 97cf847e16cd httpServer.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/httpServer.lib Thu Feb 25 07:59:46 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/IOP/code/httpServer_with_Ethernt/#2903435e3811
diff -r e6cc33c4970b -r 97cf847e16cd main.cpp
--- a/main.cpp Thu Oct 29 08:00:44 2015 +0000
+++ b/main.cpp Thu Feb 25 07:59:46 2016 +0000
@@ -1,7 +1,8 @@
-#include "mbed.h"
-#include "EthernetInterface.h"
-#include "MbedJSONValue.h"
+//#include "mbed.h"
+//#include "EthernetInterface.h"
+//#include "MbedJSONValue.h"
+/*
MbedJSONValue parser;
EthernetInterface eth;
TCPSocketConnection sock;
@@ -55,3 +56,168 @@
}
}
+*/
+
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "MbedJSONValue.h"
+
+
+EthernetInterface eth;
+TCPSocketConnection sock;
+
+MbedJSONValue WIZwikiREST;
+MbedJSONValue GPIOs;
+
+char ip_addr[] = "192.168.0.100";
+char subnet_mask[] = "255.255.255.0";
+char gateway_addr[] = "192.168.0.1";
+
+int main() {
+
+ std::string s;
+
+ // Fill the object
+ WIZwikiREST["Name"] = "WIZwiki-REST-01";
+ WIZwikiREST["Network"]["IP"] = ip_addr;
+ WIZwikiREST["Network"]["SN"] = subnet_mask;
+ WIZwikiREST["Network"]["GW"] = gateway_addr;
+ WIZwikiREST["User"]["Name"] = "Lawrence";
+ WIZwikiREST["User"]["ID"] = "law";
+ WIZwikiREST["User"]["PSWD"] = "law1234";
+ GPIOs["P5"]["Mode"] = "DIO";
+ GPIOs["P6"]["Mode"] = "DIO";
+ WIZwikiREST["GPIOs"] = GPIOs;
+
+
+ // Serialize it into a JSON string
+ s = WIZwikiREST.serialize();
+ printf("json: %s\r\n", s.c_str());
+ string item = "Name";
+ printf("WIZwikiREST[item] =%s", WIZwikiREST[item].get<string>().c_str());
+
+
+ int http_tx_msg_sz=800;
+ char http_tx_msg[http_tx_msg_sz];
+ int http_rx_msg_sz=500;
+ char http_rx_msg[http_rx_msg_sz];
+ int returnCode = 0;
+
+ // Enter a MAC address for your controller below.
+ uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0xFE};
+
+ // initializing MAC address
+ printf("initializing Ethernet\r\n");
+ eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr);
+
+ // Check Ethernet Link
+ printf("Check Ethernet Link\r\n");
+ while(1) //Wait link up
+ {
+ if(eth.link() == true)
+ break;
+ }
+ printf("Link up\r\n");
+
+ // Connect
+ eth.connect();
+ printf("Server IP Address is %s\r\n", eth.getIPAddress());
+
+ if (!svr.start(80, ð)) {
+
+ error("Server not starting !");
+ exit(0);
+ }
+
+ while(1) {
+ svr.poll();
+ }
+
+/*
+ while(1) {
+ sock.connect("192.168.0.223", 8000);
+
+ snprintf(http_tx_msg, http_tx_msg_sz, "GET / HTTP/1.1\r\nHost: 192.168.0.223:8000\r\nUser-Agent: WIZwiki-W7500ECO\r\nConection: close\r\n\r\n");
+ sock.send_all(http_tx_msg, http_tx_msg_sz-1);
+
+ while ( (returnCode = sock.receive(http_rx_msg, http_rx_msg_sz-1)) > 0) {
+ http_rx_msg[returnCode] = '\0';
+ printf("Received %d chars from server:\n\r%s\n", returnCode, http_rx_msg);
+ }
+
+ sock.close();
+
+ parse(parser, http_rx_msg);
+ printf("name =%s\r\n" , parser["name"].get<string>().c_str());
+ printf("age =%d\r\n" , parser["age"].get<int>());
+ printf("gender =%s\r\n" , parser["gender"].get<string>().c_str());
+
+ wait(10);
+ }
+*/
+
+}
+
+
+
+
+/** MbedJSONValue class
+ *
+ * Example:
+ * - creation of an MbedJSONValue of type TypeObject containing two others MbedJSONValue:
+ * -one array of one string and one integer identified by "my_array"
+ * -a boolean identified by "my_boolean"
+ * - serialization in JSON format of this object
+ * @code
+ * #include "mbed.h"
+ * #include "MbedJSONValue.h"
+ * #include <string>
+ *
+ * int main() {
+ *
+ * MbedJSONValue demo;
+ * std::string s;
+ *
+ * //fill the object
+ * demo["my_array"][0] = "demo_string";
+ * demo["my_array"][1] = 10;
+ * demo["my_boolean"] = false;
+ *
+ * //serialize it into a JSON string
+ * s = demo.serialize();
+ * printf("json: %s\r\n", s.c_str());
+ * }
+ *
+ * @endcode
+ *
+ * Example:
+ * - creation of an MbedJSONValue from a JSON string
+ * - extraction of different values from this existing MbedJSONValue
+ * @code
+ * #include "mbed.h"
+ * #include "MbedJSONValue.h"
+ * #include <string>
+ *
+ * int main() {
+ * MbedJSONValue demo;
+ *
+ * const char * json = "{\"my_array\": [\"demo_string\", 10], \"my_boolean\": true}";
+ *
+ * //parse the previous string and fill the object demo
+ * parse(demo, json);
+ *
+ * std::string my_str;
+ * int my_int;
+ * bool my_bool;
+ *
+ * my_str = demo["my_array"][0].get<std::string>();
+ * my_int = demo["my_array"][1].get<int>();
+ * my_bool = demo["my_boolean"].get<bool>();
+ *
+ * printf("my_str: %s\r\n", my_str.c_str());
+ * printf("my_int: %d\r\n", my_int);
+ * printf("my_bool: %s\r\n", my_bool ? "true" : "false");
+ * }
+ * @endcode
+ */
\ No newline at end of file
