Initial setup for TheKsystem.

Dependencies:   mbed-http HTS221

Files at this revision

API Documentation at this revision

Comitter:
Jan Jongboom
Date:
Mon Sep 04 17:01:11 2017 +0100
Parent:
16:1374b4c35897
Child:
18:b661324be638
Commit message:
Enable entropy sources for ODIN-W2; add note on memory usage

Changed in this revision

README.md Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
mbedtls_entropy_config.h Show annotated file Show diff for this revision Revisions of this file
source/main-http.cpp Show annotated file Show diff for this revision Revisions of this file
source/main-https-socket-reuse.cpp Show annotated file Show diff for this revision Revisions of this file
source/select-demo.h Show annotated file Show diff for this revision Revisions of this file
--- a/README.md	Mon Sep 04 16:32:38 2017 +0100
+++ b/README.md	Mon Sep 04 17:01:11 2017 +0100
@@ -15,6 +15,8 @@
 
 Response parsing is done through [nodejs/http-parser](https://github.com/nodejs/http-parser).
 
+**Note:** HTTPS requests do not work on targets with less than 128K of RAM due to the size of the TLS handshake. For more background see [mbed-http](https://developer.mbed.org/teams/sandbox/code/mbed-http).
+
 ## To build
 
 1. Open ``mbed_app.json`` and change the `network-interface` option to your connectivity method ([more info](https://github.com/ARMmbed/easy-connect)).
@@ -24,9 +26,10 @@
 
 ## Entropy (or lack thereof)
 
-On all platforms **except** the FRDM-K64F and FRDM-K22F the application is compiled without TLS entropy sources. This means that your code is inherently unsafe and should not be deployed to any production systems. To enable entropy, remove the `MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES` and `MBEDTLS_TEST_NULL_ENTROPY` macros from mbed_app.json.
+On all platforms **except** the FRDM-K64F, FRDM-K22F and EVK-ODIN-W2, the application is compiled without TLS entropy sources. This means that your code is inherently unsafe and should not be deployed to any production systems. To enable entropy, remove the `MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES` and `MBEDTLS_TEST_NULL_ENTROPY` macros from mbed_app.json.
 
 ## Tested on
 
 * K64F with Ethernet.
 * NUCLEO_F411RE with ESP8266.
+* ODIN-W2 with WiFi.
--- a/mbed_app.json	Mon Sep 04 16:32:38 2017 +0100
+++ b/mbed_app.json	Mon Sep 04 17:01:11 2017 +0100
@@ -1,7 +1,7 @@
 {
     "config": {
         "network-interface": {
-            "help": "options are ETHERNET,WIFI_ESP8266,MESH_LOWPAN_ND,MESH_THREAD",
+            "help": "options are ETHERNET,WIFI_ESP8266,WIFI_ODIN,MESH_LOWPAN_ND,MESH_THREAD",
             "value": "ETHERNET"
         },
         "mesh_radio_type": {
@@ -27,8 +27,7 @@
         }
     },
     "macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_entropy_config.h\"",
-               "MBEDTLS_TEST_NULL_ENTROPY", "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES",
-               "MBED_HEAP_STATS_ENABLED=1" ],
+               "MBEDTLS_TEST_NULL_ENTROPY", "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES" ],
     "target_overrides": {
         "*": {
             "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"],
--- a/mbedtls_entropy_config.h	Mon Sep 04 16:32:38 2017 +0100
+++ b/mbedtls_entropy_config.h	Mon Sep 04 17:01:11 2017 +0100
@@ -19,10 +19,10 @@
 
 #include "select-demo.h"
 
-/* Enable entropy for K64F and K22F. This means entropy is disabled for all other targets. */
+/* Enable entropy for K64F, K22F, ODIN-W2. This means entropy is disabled for all other targets. */
 /* Do **NOT** deploy this code in production on other targets! */
 /* See https://tls.mbed.org/kb/how-to/add-entropy-sources-to-entropy-pool */
-#if defined(TARGET_K64F) || defined(TARGET_K22F)
+#if defined(TARGET_K64F) || defined(TARGET_K22F) || defined(TARGET_UBLOX_EVK_ODIN_W2)
 #undef MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
 #undef MBEDTLS_TEST_NULL_ENTROPY
 #endif
--- a/source/main-http.cpp	Mon Sep 04 16:32:38 2017 +0100
+++ b/source/main-http.cpp	Mon Sep 04 17:01:11 2017 +0100
@@ -5,6 +5,7 @@
 #include "mbed.h"
 #include "easy-connect.h"
 #include "http_request.h"
+#include "mbed_stats.h"
 
 Serial pc(USBTX, USBRX);
 
@@ -20,6 +21,12 @@
 
 int main() {
     pc.baud(115200);
+
+    mbed_stats_heap_t heap_stats;
+
+    mbed_stats_heap_get(&heap_stats);
+    printf("[1] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
+
     // Connect to the network (see mbed_app.json for the connectivity method used)
     NetworkInterface* network = easy_connect(true);
     if (!network) {
@@ -27,6 +34,9 @@
         return 1;
     }
 
+    mbed_stats_heap_get(&heap_stats);
+    printf("[2] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
+
     // Do a GET request to httpbin.org
     {
         // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
@@ -45,6 +55,9 @@
         delete get_req;
     }
 
+    mbed_stats_heap_get(&heap_stats);
+    printf("[3] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
+
     // POST request to httpbin.org
     {
         HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://httpbin.org/post");
@@ -61,9 +74,15 @@
         printf("\n----- HTTP POST response -----\n");
         dump_response(post_res);
 
+        mbed_stats_heap_get(&heap_stats);
+        printf("[4] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
+
         delete post_req;
     }
 
+    mbed_stats_heap_get(&heap_stats);
+    printf("[5] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
+
     Thread::wait(osWaitForever);
 }
 
--- a/source/main-https-socket-reuse.cpp	Mon Sep 04 16:32:38 2017 +0100
+++ b/source/main-https-socket-reuse.cpp	Mon Sep 04 17:01:11 2017 +0100
@@ -60,7 +60,7 @@
     mbed_stats_heap_t heap_stats;
 
     mbed_stats_heap_get(&heap_stats);
-    printf("[1] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+    printf("[1] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
 
     NetworkInterface* network = easy_connect(true);
     if (!network) {
@@ -68,7 +68,7 @@
     }
 
     mbed_stats_heap_get(&heap_stats);
-    printf("[2] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+    printf("[2] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
 
     // Create a TLS socket (which holds a TCPSocket)
     printf("\n----- Setting up TLS connection -----\n");
@@ -81,7 +81,7 @@
     }
 
     mbed_stats_heap_get(&heap_stats);
-    printf("[3] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+    printf("[3] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
 
     // GET request to httpbin.org
     {
@@ -97,13 +97,13 @@
         dump_response(get_res);
 
         mbed_stats_heap_get(&heap_stats);
-        printf("[4a] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+        printf("[4a] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
 
         delete get_req;
     }
 
     mbed_stats_heap_get(&heap_stats);
-    printf("[4] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+    printf("[4b] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
 
     // POST request to httpbin.org
     {
@@ -126,12 +126,12 @@
     }
 
     mbed_stats_heap_get(&heap_stats);
-    printf("[5] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+    printf("[5] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
 
     delete socket;
 
     mbed_stats_heap_get(&heap_stats);
-    printf("[6] Heap: %lu / %lu\n", heap_stats.current_size, heap_stats.reserved_size);
+    printf("[6] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
 
     Thread::wait(osWaitForever);
 }
--- a/source/select-demo.h	Mon Sep 04 16:32:38 2017 +0100
+++ b/source/select-demo.h	Mon Sep 04 17:01:11 2017 +0100
@@ -6,6 +6,6 @@
 #define         DEMO_HTTPS                  3
 #define         DEMO_HTTPS_SOCKET_REUSE     4
 
-#define         DEMO            DEMO_HTTPS_SOCKET_REUSE
+#define         DEMO            DEMO_HTTP
 
 #endif // _SELECT_METHOD_H_