kio

Dependencies:   mbed-http

Files at this revision

API Documentation at this revision

Comitter:
yonaetworks
Date:
Thu Aug 05 00:08:53 2021 +0000
Child:
1:078a6d9a2ae3
Commit message:
kio

Changed in this revision

README.md Show annotated file Show diff for this revision Revisions of this file
mbed-http.lib Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib 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
simconfig.json 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/network-helper.h 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Thu Aug 05 00:08:53 2021 +0000
@@ -0,0 +1,68 @@
+# HTTP/HTTPS example for Mbed OS 5
+
+This application demonstrates how to make HTTP and HTTPS requests and parse the response from Mbed OS 5.
+
+It consists of six demo's, which you can select in ``source/select-demo.h``.
+
+* HTTP demo:
+    * Does a GET request to http://httpbin.org/status/418.
+    * Does a POST request to http://httpbin.org/post.
+* HTTPS demo:
+    * Does a GET request to https://os.mbed.com/media/uploads/mbed_official/hello.txt.
+    * Does a POST request to https://httpbin.org/post.
+* HTTP demo with socket re-use.
+* HTTPS demo with socket re-use.
+* HTTP demo over IPv6.
+* HTTPS demo with chunked requests.
+
+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. If you're using WiFi, specify the credentials in `mbed_app.json`.
+1. Build the project in the online compiler or using Mbed CLI.
+1. Flash the project to your development board.
+1. Attach a serial monitor to your board to see the debug messages.
+
+## Defining the network interface
+
+This application uses the on-board network interface for your board. If you use an external network interface (f.e. a WiFi module) you need to add the driver to this project. Then, open `network-helper.h` and specify which network driver to use.
+
+More information is in the Mbed OS documentation under [IP Networking](https://os.mbed.com/docs/latest/reference/ip-networking.html).
+
+## Entropy (or lack thereof)
+
+On all platforms that do not have the `TRNG` feature, 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.
+
+## Flash size
+
+Default flash size for HTTPS is very large, as the application is loading the default Mbed TLS configuration. To use a more optimized version, you can disable unused cypher suites and other Mbed TLS features with a custom configuration file. Create a new configuration file, then add in `mbed_app.json`:
+
+```
+"MBEDTLS_CONFIG_FILE=\"mbedtls_config.h\""
+```
+
+to the `macros` array.
+
+## Running tests
+
+You can run the integration tests from this project via Mbed CLI.
+
+1. In `select-demo.h` set the `DEMO` macro to `DEMO_TESTS`.
+1. Set your WiFi credentials in `mbed_app.json`.
+1. Then run the tests via:
+
+```
+$ mbed test -v -n mbed-http-tests-tests-*
+```
+
+## Tested on
+
+* K64F with Ethernet.
+* NUCLEO_F411RE with ESP8266.
+* ODIN-W2 with WiFi.
+* K64F with Atmel 6LoWPAN shield.
+* DISCO-L475VG-IOT01A with WiFi (requires the [wifi-ism43362](https://github.com/ARMmbed/wifi-ism43362/) driver).
+* [Mbed Simulator](https://github.com/janjongboom/mbed-simulator).
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-http.lib	Thu Aug 05 00:08:53 2021 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/sandbox/code/mbed-http/#a8d157986ad8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Aug 05 00:08:53 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#c966348d3f9ca80843be7cdc9b748f06ea73ced0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Thu Aug 05 00:08:53 2021 +0000
@@ -0,0 +1,31 @@
+{
+    "config": {
+        "main-stack-size": {
+            "value": 8192
+        }
+    },
+    "macros": [
+        "MBEDTLS_MPI_MAX_SIZE=1024",
+        "MBEDTLS_MPI_WINDOW_SIZE=1",
+        "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_entropy_config.h\"",
+        "MBEDTLS_TEST_NULL_ENTROPY",
+        "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES",
+        "MBED_HEAP_STATS_ENABLED=1"
+    ],
+    "target_overrides": {
+        "*": {
+            "platform.stdio-baud-rate": 9600,
+            "platform.stdio-convert-newlines": true,
+            "mbed-mesh-api.6lowpan-nd-channel-page": 0,
+            "mbed-mesh-api.6lowpan-nd-channel": 12,
+            "mbed-trace.enable": null,
+            "mbed-http.http-buffer-size": 2048,
+            "nsapi.default-wifi-security": "WPA_WPA2",
+            "nsapi.default-wifi-ssid": "\"SSID\"",
+            "nsapi.default-wifi-password": "\"Password\""
+        },
+        "DISCO_L475VG_IOT01A": {
+            "target.network-default-interface-type" : "WIFI"
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbedtls_entropy_config.h	Thu Aug 05 00:08:53 2021 +0000
@@ -0,0 +1,28 @@
+/*
+ *  Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
+ *  SPDX-License-Identifier: Apache-2.0
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  This file is part of mbed TLS (https://tls.mbed.org)
+ */
+
+#include "select-demo.h"
+
+/* Enable entropy for devices with TRNG. 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(DEVICE_TRNG)
+#undef MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
+#undef MBEDTLS_TEST_NULL_ENTROPY
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simconfig.json	Thu Aug 05 00:08:53 2021 +0000
@@ -0,0 +1,5 @@
+{
+    "ignore": [
+        "./mbed-http"
+    ]
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/main-http.cpp	Thu Aug 05 00:08:53 2021 +0000
@@ -0,0 +1,423 @@
+#include "select-demo.h"
+#if DEMO == DEMO_HTTP
+#include "mbed.h"
+#include "http_request.h"
+#include "network-helper.h"
+#include "mbed_mem_trace.h"
+#include <iostream>
+#include <cstring>
+#include <Thread.h>
+#include <stdio.h>
+#include "EthernetInterface.h"
+
+DigitalOut PUERTA1(PG_9);
+DigitalOut PUERTA2(PG_14);
+DigitalOut PUERTA3(PF_15);
+DigitalOut PUERTA4(PE_13);
+
+Serial      sim808(PD_5, PD_6,9600);
+int         onetime = 0, i=0, j=0, onedbquery[4];
+const int   kMaxBufferSize = 100;
+char        buffer[kMaxBufferSize];
+string      opendoors = "http://192.168.1.10/ws/ws.php?op=micopendoors&telefono=";
+string      closedoors = "http://192.168.1.10/ws/ws.php?op=micclosedoors&telefono=";
+string      registers = "http://192.168.1.10/ws/ws.php?op=create-register&telefono=";
+char        linkdoors[40]= "http://192.168.1.10/ws/ws.php?op=doors";
+string      linkregister01 = "";
+string      linkregister02;
+string      linkregister03;
+string      linkregister04;
+char        char_linkregister01[55];
+char        char_linkregister02[55];
+char        char_linkregister03[55];
+char        char_linkregister04[55];
+char        linkopendoors[100];
+char        linkclosedoors[100];
+char        linkregisters[100];
+string      link_string;
+string      http_response = "";
+int         len = 0;
+char        telbuf[11];
+int         mensaje=0;
+Timer       t;
+
+void dump_response(HttpResponse* res) {
+    http_response = res->get_body_as_string().c_str();
+}
+
+int main() {
+    
+//-------------------------------------------------------------------- INICIALIZACION DE PINES -------------------------------------------------------------------------------------------
+
+    PUERTA1 = 1;
+    PUERTA2 = 1;
+    PUERTA3 = 1;
+    PUERTA4 = 1;
+    linkregister01 = "http://192.168.1.10/ws/ws.php?op=create-registeri&id=1";
+    linkregister02 = "http://192.168.1.10/ws/ws.php?op=create-registeri&id=2";
+    linkregister03 = "http://192.168.1.10/ws/ws.php?op=create-registeri&id=3";
+    linkregister04 = "http://192.168.1.10/ws/ws.php?op=create-registeri&id=4";
+    
+    int m = linkregister01.length();
+ 
+    // declaring character array
+    char link_char4[m + 1];
+    char link_char5[m + 1];
+    char link_char6[m + 1];
+    char link_char7[m + 1];
+ 
+    // copying the contents of the
+    // string to char array
+    strcpy(link_char4, linkregister01.c_str());
+    strcpy(link_char5, linkregister02.c_str());
+    strcpy(link_char6, linkregister03.c_str());
+    strcpy(link_char7, linkregister04.c_str());
+ 
+    for (int i2 = 0; i2 < m; i2++){
+        cout << link_char4[i2];
+        cout << link_char5[i2];
+        cout << link_char6[i2];
+        cout << link_char7[i2];
+    }
+    
+    for(int k2 = 0; k2 < 54 ; k2++){
+            char_linkregister01[k2] = linkregister01[k2];
+            char_linkregister02[k2] = linkregister02[k2];
+            char_linkregister03[k2] = linkregister03[k2];
+            char_linkregister04[k2] = linkregister04[k2];
+    }
+
+//-------------------------------------------------------------------- INICIALIZACION DE TARJETA DE RED -------------------------------------------------------------------------------------------
+
+
+    NetworkInterface* network = connect_to_default_network_interface();
+    if (!network) {
+        printf("Cannot connect to the network, see serial output\n");
+        return 1;
+    }
+    
+//------------------------------------------------------------------- RECEPCION Y ALMACENAMIENTO DE TELEFONO --------------------------------------------------------------------------------------
+    t.start();
+    unsigned long int T1, T2;
+    T1 = t.read();
+    buffer[0] = '\0';
+    
+    while (true) {
+        
+        T2 = t.read();
+        if(T2 > (T1 + 2)){
+            T1 = T2;
+            {HttpRequest* get_req = new HttpRequest(network, HTTP_GET, linkdoors);
+            HttpResponse* get_res = get_req->send();
+            if (!get_res) {
+                printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+                return 1;
+            }
+            dump_response(get_res);
+            delete get_req;}
+            
+            char doors_ddbb[4];
+            doors_ddbb[0] = http_response[0];
+            doors_ddbb[1] = http_response[1];
+            doors_ddbb[2] = http_response[2];
+            doors_ddbb[3] = http_response[3];
+            
+            char logicone[0];
+            logicone[0] = '1';            
+            
+            if(doors_ddbb[0] == logicone[0]){
+                PUERTA1 = 1;
+                onedbquery[0] = 0;
+            }
+            else if (doors_ddbb[0] != logicone[0] && onedbquery[0] == 0){
+                PUERTA1 = 0;
+                {HttpRequest* get_req = new HttpRequest(network, HTTP_GET, char_linkregister01);
+                HttpResponse* get_res = get_req->send();
+                if (!get_res) {
+                printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+                return 1;}
+                dump_response(get_res);
+                delete get_req;
+                printf("[aXessKontrol] Se detecto cambio en la base de datos, agregando registro...  Repuesta de DDBB: %s \n", http_response);}
+                onedbquery[0]++;
+                mensaje = 0;
+            }
+            if(doors_ddbb[1] == logicone[0]){
+                PUERTA2 = 1;
+                onedbquery[1] = 0;
+            }
+            else if (doors_ddbb[1] != logicone[0] && onedbquery[1] == 0){
+                PUERTA2 = 0;
+                {HttpRequest* get_req = new HttpRequest(network, HTTP_GET, char_linkregister02);
+                HttpResponse* get_res = get_req->send();
+                if (!get_res) {
+                printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+                return 1;}
+                dump_response(get_res);
+                delete get_req;
+                printf("[aXessKontrol] Se detecto cambio en la base de datos, agregando registro...  Repuesta de DDBB: %s \n", http_response);}
+                onedbquery[1]++;
+                mensaje = 0;
+            }
+            if(doors_ddbb[2] == logicone[0]){
+                PUERTA3 = 1;
+                onedbquery[2] = 0;
+    
+            }
+            else if (doors_ddbb[2] != logicone[0] && onedbquery[2] == 0){
+                PUERTA3 = 0;
+                {HttpRequest* get_req = new HttpRequest(network, HTTP_GET, char_linkregister03);
+                HttpResponse* get_res = get_req->send();
+                if (!get_res) {
+                printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+                return 1;}
+                dump_response(get_res);
+                delete get_req;
+                printf("[aXessKontrol]Se detecto cambio en la base de datos, agregando registro...  Repuesta de DDBB: %s \n", http_response);}
+                onedbquery[2]++;
+                mensaje = 0;
+            }
+            if(doors_ddbb[3] == logicone[0]){
+                PUERTA4 = 1;
+            }
+            else if (doors_ddbb[3] != logicone[0] && onedbquery[3] == 0){
+                PUERTA4 = 0;
+                {HttpRequest* get_req = new HttpRequest(network, HTTP_GET, char_linkregister04);
+                HttpResponse* get_res = get_req->send();
+                if (!get_res) {
+                printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+                return 1;}
+                dump_response(get_res);
+                delete get_req;
+                printf("[aXessKontrol]Se detecto cambio en la base de datos, agregando registro...  Repuesta de DDBB: %s \n", http_response);}
+                onedbquery[3]++;
+                mensaje = 0;
+            }
+        }
+        HOME:
+        
+        if(mensaje == 0){
+            printf("\n[aXessKontrol] Bievenido a la consola de aXessKontrol, aqui se visualiza informacion importante sobre el estado actual del sistema \n");
+            printf("[aXessKontrol] El sistema esta disponible para recibir solicitudes \n\n");
+            mensaje++;
+        }
+        //----------------------------------------------- GET VERIFICACION DE ESTADO DE PINES EN BASE DE DATOS -----------------------------------------------------------------------------
+            
+        while (sim808.readable()) {
+            char new_char = sim808.getc();
+            if(new_char == '0' || new_char == '1' || new_char == '2' || new_char == '3' || new_char == '4' || new_char == '5' || new_char == '6' || new_char == '7' || new_char == '8' || new_char == '9'){
+                buffer[len] = new_char;
+                len++;
+                if(len == 10 && onetime == 0){
+                    for(j=0;j<10;j++){
+                        telbuf[j] = buffer[j];
+                        printf("[aXessKontrol] Se almaceno el numero %c en la posicion j %d de TELBUF\n", telbuf[j], j);
+                    }
+                    onetime++;
+                    goto A;
+                }          
+        }
+            
+            // new message received, handle
+            if (new_char == '\n'){
+                len = 0;
+            }
+        }
+    }
+    A:
+    printf("\n[aXessKontrol] Solicitud recibida.\n[aXessKontrol] El telefono del usuario actual es : %s \n\n", telbuf);
+    
+    sim808.printf("ATA\n");
+    
+//-------------------------------------------CONVERSION Y CONCATENACION DE STRING PARA FORMAR LINK------------------------------------------------------------------------
+
+
+    //--------------------------------------------------CREACION DE LINK OPENDOOR-----------------------------------------------------------------------------------------
+    int n = opendoors.length();
+ 
+    // declaring character array
+    char link_char[n + 1];
+ 
+    // copying the contents of the
+    // string to char array
+    strcpy(link_char, opendoors.c_str());
+ 
+    for (int i = 0; i < n; i++){
+        cout << link_char[i];
+    }
+    
+    for(int k = 0; k < 65 ; k++){
+        if(k < 55){
+            linkopendoors[k] = opendoors[k];
+        }
+        else if (k >= 55) {
+            linkopendoors[k] = telbuf[k-55];
+        }
+    }
+    printf("[aXessKontrol] Iniciando generacion de URLs...\n");
+    printf("[aXessKontrol] El URL para abrir creado es el siguiente:  %s \n", linkopendoors);
+    
+    
+    //-------------------------------------------------- CREACION DE LINK CLOSEDOOR ---------------------------------------------------------------------------------------
+    
+    int n2 = closedoors.length();
+ 
+    // declaring character array
+    char link_char2[n2 + 1];
+ 
+    // copying the contents of the
+    // string to char array
+    strcpy(link_char2, closedoors.c_str());
+ 
+    for (int z = 0; z < n2; z++){
+        cout << link_char2[z];
+    }
+    
+    for(int x = 0; x < 66 ; x++){
+        if(x < 56){
+            linkclosedoors[x] = closedoors[x];
+        }
+        else if (x >= 56) {
+            linkclosedoors[x] = telbuf[x-56];
+        }
+    }
+    
+    printf("[aXessKontrol] El URL para cerrar creado es el siguiente:  %s \n", linkclosedoors);
+    
+    
+        //-------------------------------------------------- CREACION DE LINK REGISTRO ---------------------------------------------------------------------------------------
+    
+    int n3 = registers.length();
+ 
+    // declaring character array
+    char link_char3[n3 + 1];
+ 
+    // copying the contents of the
+    // string to char array
+    strcpy(link_char3, registers.c_str());
+ 
+    for (int z = 0; z < n3; z++){
+        cout << link_char2[z];
+    }
+    
+    for(int x = 0; x < 68 ; x++){
+        if(x < 58){
+            linkregisters[x] = registers[x];
+        }
+        else if (x >= 58) {
+            linkregisters[x] = telbuf[x-58];
+        }
+    }
+    
+    printf("[aXessKontrol] El URL del registro es el siguiente:  %s \n", linkregisters);
+    
+//-------------------------------------------------------------------- CREACION DEL GET HTTP ------------------------------------------------------------------------------------------------------
+    
+//-------------------------------------------------------------------- APERTURA DE PUERTA --------------------------------------------------------------------------------------------------
+    printf("[aXessKontrol] Se generaron correctamente las URLs...\n\n");
+    wait(0.7);   
+    sim808.printf("ATH\n");
+    
+    
+    {
+        HttpRequest* get_req = new HttpRequest(network, HTTP_GET, linkopendoors);
+        
+        HttpResponse* get_res = get_req->send();
+        if (!get_res) {
+            printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+            return 1;
+        }
+        
+        //IMPRESION DE RESPUESTA HTTP
+        dump_response(get_res);
+        delete get_req;
+         
+        printf("[aXessKontrol] La puerta fue abierta, el id del usuario es: %s\n", http_response);
+    }
+    char compare[0];
+    compare[0] = http_response[0];
+    char primero[0];
+    char segundo[0];
+    char tercero[0];
+    char cuarto[0];
+    
+    primero[0] = '1';
+    segundo[0] = '2';
+    tercero[0] = '3';
+    cuarto[0] = '4';
+    
+    if(compare[0] == primero[0]){
+        PUERTA1 = 0;
+    }
+    else if(compare[0] == segundo[0]){
+        PUERTA2 = 0;
+    }
+    else if(compare[0] == tercero[0]){
+        PUERTA3 = 0;
+    }
+    else if(compare[0] == cuarto[0]){
+        PUERTA4 = 0;
+    }
+    
+    //-------------------------------------------------------------------- CREACION DE REGISTRO --------------------------------------------------------------------------------------------------
+    
+    {
+        HttpRequest* get_req = new HttpRequest(network, HTTP_GET, linkregisters);
+        
+        HttpResponse* get_res = get_req->send();
+        if (!get_res) {
+            printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+            return 1;
+        }
+        
+        //IMPRESION DE RESPUESTA HTTP
+        dump_response(get_res);
+        delete get_req;
+         
+        printf("[aXessKontrol] Enviando registro de acceso... Respuesta de DDBB: %s\n", http_response);
+        printf("\n[aXessKontrol] Iniciando cierre en 10 segundos...\n");
+    }
+    
+    wait(10);
+    
+    if(compare[0] == primero[0]){
+        PUERTA1 = 1;
+    }
+    else if(compare[0] == segundo[0]){
+        PUERTA2 = 1;
+    }
+    else if(compare[0] == tercero[0]){
+        PUERTA3 = 1;
+    }
+    else if(compare[0] == cuarto[0]){
+        PUERTA4 = 1;
+    }
+//-------------------------------------------------------------------- CIERRE DE PUERTA --------------------------------------------------------------------------------------------------
+    printf("\n[aXessKontrol] Cerrando la puerta... \n");
+    {
+        HttpRequest* get_req = new HttpRequest(network, HTTP_GET, linkclosedoors);
+        
+        HttpResponse* get_res = get_req->send();
+        if (!get_res) {
+            printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+            return 1;
+        }
+        
+        //IMPRESION DE RESPUESTA HTTP
+        dump_response(get_res);
+        delete get_req;
+         
+        printf("[aXessKontrol] La puerta fue cerrada, actualizando campo. Respuesta de DDBB: %s\n", http_response);
+    }
+    
+    printf("\n[aXessKontrol] Preparando recepcion de nuevas solicitudes... \n");
+    onetime = 0;
+    len = 0;
+    mensaje = 0;
+    opendoors = "http://192.168.1.10/ws/ws.php?op=micopendoors&telefono=";
+    closedoors = "http://192.168.1.10/ws/ws.php?op=micclosedoors&telefono=";
+    registers = "http://192.168.1.10/ws/ws.php?op=create-register&telefono=";
+    goto HOME;
+}
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/network-helper.h	Thu Aug 05 00:08:53 2021 +0000
@@ -0,0 +1,34 @@
+#ifndef _MBED_HTTP_EXAMPLE_H_
+#define _MBED_HTTP_EXAMPLE_H_
+
+#include "mbed.h"
+#include "NetworkInterface.h"
+
+/**
+ * Connect to the network using the default networking interface,
+ * you can also swap this out with a driver for a different networking interface
+ * if you use WiFi: see mbed_app.json for the credentials
+ */
+NetworkInterface *connect_to_default_network_interface() {
+    printf("[NWKH] Connecting to network...\n");
+
+    NetworkInterface* network = NetworkInterface::get_default_instance();
+
+    if (!network) {
+        printf("[NWKH] No network interface found, select an interface in 'network-helper.h'\n");
+        return NULL;
+    }
+
+    nsapi_error_t connect_status = network->connect();
+
+    if (connect_status != NSAPI_ERROR_OK) {
+        printf("[NWKH] Failed to connect to network (%d)\n", connect_status);
+        return NULL;
+    }
+
+    printf("[NWKH] Connected to the network\n");
+    printf("[NWKH] IP address: %s\n", network->get_ip_address());
+    return network;
+}
+
+#endif // _MBED_HTTP_EXAMPLE_H_
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/select-demo.h	Thu Aug 05 00:08:53 2021 +0000
@@ -0,0 +1,14 @@
+#ifndef _SELECT_METHOD_H_
+#define _SELECT_METHOD_H_
+
+#define         DEMO_HTTP                   1
+#define         DEMO_HTTP_SOCKET_REUSE      2
+#define         DEMO_HTTP_IPV6              3
+#define         DEMO_HTTPS                  4
+#define         DEMO_HTTPS_SOCKET_REUSE     5
+#define         DEMO_HTTPS_CHUNKED_REQUEST  6
+#define         DEMO_TESTS                  7
+
+#define         DEMO            DEMO_HTTP
+
+#endif // _SELECT_METHOD_H_