
This is a simple mbed client example demonstrating, registration of a device with mbed Device Connector and reading and writing values as well as deregistering on different Network Interfaces including Ethernet, WiFi, 6LoWPAN ND and Thread respectively.
Fork of mbed-os-example-client by
Revision 5:b7d7ca715fdb, committed 2016-08-01
- Comitter:
- mbed_official
- Date:
- Mon Aug 01 18:15:14 2016 +0100
- Parent:
- 4:18cb89a026e9
- Child:
- 6:8fff223f3f84
- Commit message:
- Merge pull request #59 from ARMmbed/README-update
Updating README for non K64F platforms.
Commit copied from https://github.com/ARMmbed/mbed-os-example-client
Changed in this revision
--- a/README.md Sat Jul 30 00:00:31 2016 +0100 +++ b/README.md Mon Aug 01 18:15:14 2016 +0100 @@ -200,9 +200,15 @@ After connecting, you should see messages about connecting to mbed Device Connector: ``` -In app_start() -IP address 10.2.15.222 -Device name 6868df22-d353-4150-b90a-a878130859d9 +Starting mbed Client example... +Using <Network Interface> + +Connected to Network successfully +IP address xxx.xxx.xxx.xxx + +SOCKET_MODE : UDP +Connecting to coap://api.connector.mbed.com:5684 + ``` <span class="notes">**Note:** Device name is the endpoint name you will need later on when [testing the application](https://github.com/ARMmbed/mbed-os-example-client#testing-the-application) chapter.</span> @@ -224,6 +230,7 @@ 1. The number of times you pressed `SW2` is shown. 1. Press the `SW3` button to unregister from mbed Device Connector. You should see `Unregistered Object Successfully` printed to the serial port and the LED starts blinking. This will also stop your application. Press the `RESET` button to run the program again. +<span class="notes">**Note:** On non K64F boards, there is no unregistration functionality and button press is simulated through timer ticks incrementing every 15 seconds.</span> 
--- a/main.cpp Sat Jul 30 00:00:31 2016 +0100 +++ b/main.cpp Mon Aug 01 18:15:14 2016 +0100 @@ -68,9 +68,18 @@ // Instantiate the class which implements LWM2M Client API (from simpleclient.h) MbedClient mbed_client(device); + +// In case of K64F board , there is button resource available +// to change resource value and unregister +#ifdef TARGET_K64F // Set up Hardware interrupt button. InterruptIn obs_button(SW2); InterruptIn unreg_button(SW3); +#else +//In non K64F boards , set up a timer to simulate updating resource, +// there is no functionality to unregister. +Ticker timer; +#endif // LED Output DigitalOut led1(LED1); @@ -201,9 +210,11 @@ // up counter counter++; - +#ifdef TARGET_K64F printf("handle_button_click, new value of counter is %d\r\n", counter); - +#else + printf("simulate button_click, new value of counter is %d\r\n", counter); +#endif // serialize the value of counter as a string, and tell connector char buffer[20]; int size = sprintf(buffer,"%d",counter); @@ -292,6 +303,7 @@ ButtonResource button_resource; LedResource led_resource; +#ifdef TARGET_K64F // On press of SW3 button on K64F board, example application // will call unregister API towards mbed Device Connector //unreg_button.fall(&mbed_client,&MbedClient::test_unregister); @@ -299,6 +311,10 @@ // Observation Button (SW2) press will send update of endpoint resource values to connector obs_button.fall(&button_clicked); +#else + // Send update of endpoint resource values to connector every 15 seconds periodically + timer.attach(&button_clicked, 15.0); +#endif // Create endpoint interface to manage register and unregister mbed_client.create_interface(MBED_SERVER_ADDRESS, network_interface);
--- a/mbed_app.json Sat Jul 30 00:00:31 2016 +0100 +++ b/mbed_app.json Mon Aug 01 18:15:14 2016 +0100 @@ -13,6 +13,7 @@ "value": "\"Password\"" } }, + "macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_mbed_client_config.h\""], "target_overrides": { "*": { "target.features_add": ["CLIENT", "COMMON_PAL"],
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbedtls_mbed_client_config.h Mon Aug 01 18:15:14 2016 +0100 @@ -0,0 +1,115 @@ +/* + * Minimal configuration for using mbedtls as part of mbed-client + * + * 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) + */ + + +#ifndef MBEDTLS_CUSTOM_CONFIG_H +#define MBEDTLS_CUSTOM_CONFIG_H + +/* System support */ +#define MBEDTLS_HAVE_ASM + +/* mbed TLS feature support */ +#define MBEDTLS_ECP_DP_SECP256R1_ENABLED +#define MBEDTLS_ECP_NIST_OPTIM +#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH +#define MBEDTLS_SSL_PROTO_TLS1_2 +#define MBEDTLS_SSL_PROTO_DTLS +#define MBEDTLS_SSL_DTLS_ANTI_REPLAY +#define MBEDTLS_SSL_DTLS_HELLO_VERIFY +#define MBEDTLS_SSL_EXPORT_KEYS + +/* mbed TLS modules */ +#define MBEDTLS_AES_C +#define MBEDTLS_ASN1_PARSE_C +#define MBEDTLS_ASN1_WRITE_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_CCM_C +#define MBEDTLS_CIPHER_C +#define MBEDTLS_CTR_DRBG_C +#define MBEDTLS_ECP_C +#define MBEDTLS_ENTROPY_C +#define MBEDTLS_MD_C +#define MBEDTLS_OID_C +#define MBEDTLS_PK_C +#define MBEDTLS_PK_PARSE_C +#define MBEDTLS_SHA256_C +#define MBEDTLS_SSL_COOKIE_C +#define MBEDTLS_SSL_CLI_C +#define MBEDTLS_SSL_SRV_C +#define MBEDTLS_SSL_TLS_C + +// XXX mbedclient needs these: mbedtls_x509_crt_free, mbedtls_x509_crt_init, mbedtls_x509_crt_parse +#define MBEDTLS_X509_USE_C +#define MBEDTLS_X509_CRT_PARSE_C +// a bit wrong way to get mbedtls_ssl_conf_psk: +// XXX: this should be ifdef'd out from client too +#define MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED + +// XXX: clean these up!! +#define MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED +#define MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED +#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED +#define MBEDTLS_SHA512_C +#define MBEDTLS_ECDH_C +#define MBEDTLS_GCM_C +#define MBEDTLS_CCM_C + +#define MBEDTLS_PKCS1_V15 + +#define MBEDTLS_CIPHER_MODE_CBC +#define MBEDTLS_ECDH_C +#define MBEDTLS_ECDSA_C +#define MBEDTLS_X509_CRT_PARSE_C + +// Remove RSA, save 20KB at total +#undef MBEDTLS_RSA_C +#undef MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED + +// Remove error messages, save 10KB of ROM +#undef MBEDTLS_ERROR_C + +// Remove selftesting and save 11KB of ROM +#undef MBEDTLS_SELF_TEST + +#undef MBEDTLS_SSL_COOKIE_C + +// Reduces ROM size by 30 kB +#undef MBEDTLS_ERROR_STRERROR_DUMMY +#undef MBEDTLS_VERSION_FEATURES +#undef MBEDTLS_DEBUG_C + +// needed for parsing the certificates +#define MBEDTLS_PEM_PARSE_C +// dep of the previous +#define MBEDTLS_BASE64_C + +// reduce IO buffer to save RAM, default is 16KB +#define MBEDTLS_SSL_MAX_CONTENT_LEN 2048 + +// define to save 8KB RAM at the expense of ROM +#undef MBEDTLS_AES_ROM_TABLES + +// Save ROM and a few bytes of RAM by specifying our own ciphersuite list +#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 + +#include "mbedtls/check_config.h" + +#endif /* MBEDTLS_CUSTOM_CONFIG_H */