use serial connected to PC communicate with cloud, and send command to actor and receive date from sensor

Dependencies:   MbedJSONValue mbed nRF24L01

Files at this revision

API Documentation at this revision

Comitter:
Andthen
Date:
Fri Nov 27 09:47:12 2015 +0000
Commit message:
use serial connected to communicate with cloud, and use nrf24l01 remote control and read sensor and actor

Changed in this revision

MbedJSONValue.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nRF24L01.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MbedJSONValue.lib	Fri Nov 27 09:47:12 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/samux/code/MbedJSONValue/#10a99cdf7846
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Nov 27 09:47:12 2015 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+#include "MbedJSONValue.h"
+#include <string>
+//------------------------------------
+// Hyperterminal configuration
+// 9600 bauds, 8-bit data, no parity
+//------------------------------------
+
+void Jserialize(void);
+void Jparse(void);
+
+Serial pc(SERIAL_TX, SERIAL_RX);
+
+DigitalOut myled(LED1);
+
+int main()
+{
+    int i = 1;
+    Jserialize();
+    Jserialize();
+    while(1) {
+        wait(1);
+        pc.printf("This program runs since %d seconds.\r\n", i++);
+        myled = !myled;
+    }
+}
+
+void Jserialize(void)
+{
+
+    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());
+}
+
+void Jparse(void)
+{
+    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");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Nov 27 09:47:12 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF24L01.lib	Fri Nov 27 09:47:12 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/ianmcc/code/nRF24L01/#cd113026825f