Skip to content

Commit

Permalink
Merge pull request #77 from PelionIoT/release-4.7.1
Browse files Browse the repository at this point in the history
mbed-cloud-client-example 4.7.1
  • Loading branch information
teetak01 authored Jan 28, 2021
2 parents d0bc734 + 4f4c103 commit e9c83cf
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 60 deletions.
15 changes: 11 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog for Pelion Device Management Client example application

## Release 4.7.1 (28.01.2021)

- [Mbed OS] Updated ISM43362 Wi-Fi driver to #3813a4b with fixes for logging and UDP socket handling.
- Updated to Pelion end-to-end test library v0.2.8.
- Added a `requirements.txt` file for the application.
- The application and tooling now supports [manifest-tool v2.1.0](https://github.com/PelionIoT/manifest-tool/releases/tag/v2.1.0) or later with manifest version 1.

## Release 4.7.0 (07.12.2020)

* Updated to Mbed OS 6.5.0.
Expand Down Expand Up @@ -46,7 +53,7 @@
* Updated to Pelion E2E test library v0.2.6.
* Added a network error counter that resets the device if too many errors have occurred
* Added sleeping device example that is enabled with `MBED_CLOUD_CLIENT_TRANSPORT_MODE_UDP_QUEUE` option. The sleepy device will `pause` the client when client goes to sleep,
whenever application will try to send notification, if the client is `paused` then application will first `resume` client and then send notification.
whenever application will try to send notification, if the client is `paused` then application will first `resume` client and then send notification.
* Added support for Device Sentry feature for Mbed OS and Linux.
* Mbed OS - the feature is enabled for K66F board.
* Linux - the feature is enabled by passing the `ENABLE_DEVICE_SENTRY` CMake flag.
Expand Down Expand Up @@ -127,7 +134,7 @@ No changes.

* Added PSA configuration for K66F (`configs-psa/eth_v4.json`).
* Updated usage of new Update Authorization API, which takes in priority as well, `set_update_authorize_priority_handler` instead of `set_update_authorize_handler`.
* Use `set_message_delivery_status_cb` as part of unregister resource triggering to make sure device does not close the network connection before client is able to send the final ACK to server.
* Use `set_message_delivery_status_cb` as part of unregister resource triggering to make sure device does not close the network connection before client is able to send the final ACK to server.
* [Linux] Updated Mbed TLS to 2.18.1.
* [Mbed OS] Removed the legacy ESFS-SOTP configurations from the applications. Only KVstore is supported for client storage.

Expand Down Expand Up @@ -182,7 +189,7 @@ No changes.

* Updated to Mbed OS 5.12.0.
* [Mbed OS] Use asyncronous DNS by default for all targets.
* [Mbed OS] Preview support for Platform Security Architecture (PSA) enabled boards.
* [Mbed OS] Preview support for Platform Security Architecture (PSA) enabled boards.
* PSA configuration for PSA-enabled Cypress PSoC6 and NXP LPC55S69 boards. Configuration is in the `configs-psa/` folder.
* Both PSA-enabled boards use ESP8266 Wi-Fi.
* PSA configuration for K64F board.
Expand Down Expand Up @@ -296,7 +303,7 @@ No changes.

* Linux: Converted all timers to use signal-based timer (`SIGEV_SIGNAL`) instead of (`SIGEV_THREAD`).
* This fixes the Valgrind warnings for possible memory leaks caused by LIBC's internal timer helper thread.

<span class="notes">**Note**: If the client application is creating a pthread before instantiating MbedCloudClient,
it needs to block the `PAL_TIMER_SIGNAL` from it. Otherwise, the thread may get an exception caused
by the default signal handler with a message such as "Process terminating with default action
Expand Down
2 changes: 1 addition & 1 deletion TESTS/pelion-e2e-python-test-library.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/PelionIoT/pelion-e2e-python-test-library/#39e118e03dc89f1800922f3a91d219b25c45cb1a
https://github.com/PelionIoT/pelion-e2e-python-test-library/#b1254f39b5d4fe4a5805642f109bd6d6f27adaaa
2 changes: 1 addition & 1 deletion drivers/COMPONENT_WIFI_ISM43362.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/wifi-ism43362/#1978369b2310ea3955715b67869b717fd224a74c
https://github.com/ARMmbed/wifi-ism43362/#3813a4bb8623cc9b0525978748581f60d47142fa
13 changes: 10 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,22 @@ void main_application(void)
mcc_platform_sw_build_info();

// Initialize network
int timeout_ms = 1000;
int timeout_ms = 5000;
int retry_counter = 0;
while (-1 == mcc_platform_interface_connect()){
// Will try to connect using mcc_platform_interface_connect forever.
// Will try to connect using mcc_platform_interface_connect forever.
// wait timeout is always doubled
printf("Network connect failed. Try again after %d milliseconds.\n",timeout_ms);
mcc_platform_do_wait(timeout_ms);
timeout_ms *= 2;

if (++retry_counter == MAX_PDMC_CLIENT_CONNECTION_ERROR_COUNT) {
printf("Max error count %d reached, rebooting.\n\n", MAX_PDMC_CLIENT_CONNECTION_ERROR_COUNT);
mcc_platform_do_wait(1000);
mcc_platform_reboot();
}
}
printf("Network initialized, registering...\r\n");
printf("Network initialized, registering...\r\n");

#ifdef MEMORY_TESTS_HEAP
printf("Client initialized\r\n");
Expand Down
2 changes: 1 addition & 1 deletion mbed-cloud-client.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/PelionIoT/mbed-cloud-client/#f277bdc5cf8f5dee22063a5d293c03d76a0a8da2
https://github.com/PelionIoT/mbed-cloud-client/#37db00350da7ae48cc7bab895ecfd75219854a18
2 changes: 1 addition & 1 deletion mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"target.app_offset" : "0x11400",
"target.components_add" : ["QSPIF", "WIFI_ISM43362"],
"bootloader-size" : "(36*1024)",
"ism43362.read-thread-stack-size" : 1024,
"ism43362.read-thread-stack-size" : 2048,
"led-pinname" : "LED1",
"mbed-client.sn-coap-max-blockwise-payload-size" : 256,
"mbed-client-pal.pal-max-frag-len" : 1,
Expand Down
24 changes: 24 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ----------------------------------------------------------------------------
# Copyright 2021 Pelion
#
# 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 lists Pelion device management client requirements.
# Install the requirements by calling
# pip install -r requirements.txt

manifest-tool>=2.0.0
1 change: 1 addition & 0 deletions source/platform/.mbedignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ NXP/*
KEIL/*
Renesas_EK_RA6M3/*
Renesas_RX65N-CK/*
Nanosimulator/*
7 changes: 3 additions & 4 deletions source/platform/include/mcc_common_config.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Copyright 2018-2019 ARM Ltd.
//
// SPDX-License-Identifier: Apache-2.0
Expand All @@ -22,12 +22,11 @@
/* #define PLATFORM_ENABLE_BUTTON 1 for enabling button.*/
#ifndef PLATFORM_ENABLE_BUTTON
#define PLATFORM_ENABLE_BUTTON 0
#endif
#endif

/* #define PLATFORM_ENABLE_LED 1 for enabling led.*/
#ifndef PLATFORM_ENABLE_LED
#define PLATFORM_ENABLE_LED 0
#define PLATFORM_ENABLE_LED 0
#endif

#endif /* MCC_COMMON_CONFIG_H */

4 changes: 4 additions & 0 deletions source/platform/include/mcc_common_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ int mcc_platform_init(void);
int mcc_platform_interface_connect(void);

// Initialize network interface pointer.
#ifdef __NANOSIMULATOR__
int mcc_platform_interface_init(int8_t rf_driver, int8_t app_tasklet_id);
#else
void mcc_platform_interface_init(void);
#endif // __NANOSIMULATOR__

// Close network interface.
int mcc_platform_interface_close(void);
Expand Down
105 changes: 75 additions & 30 deletions source/platform/mbed-os/mcc_common_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ static void network_status_callback(nsapi_event_t status, intptr_t param);
*/
static bool interface_connected = false;

#ifdef MCC_USE_MBED_EVENTS
static bool volatile async_connect = false;
#endif

////////////////////////////////
// SETUP_COMMON.H IMPLEMENTATION
////////////////////////////////
Expand Down Expand Up @@ -116,7 +120,7 @@ int mcc_platform_interface_connect(void) {

printf("mcc_platform_interface_connect()\n");
network_interface = NetworkInterface::get_default_instance();
if(network_interface == NULL) {
if (network_interface == NULL) {
printf("ERROR: No NetworkInterface found!\n");
return -1;
}
Expand All @@ -125,47 +129,87 @@ int mcc_platform_interface_connect(void) {
network_interface->add_event_listener(mbed::callback(&network_status_callback));
printf("Connecting with interface: %s\n", network_type(network_interface));
interface_connected = false;

#ifdef MCC_USE_MBED_EVENTS
network_interface->set_blocking(false);
bool blocking_interface = false;

if (network_interface->connect() != NSAPI_ERROR_OK) {
return -1;
if (network_interface->set_blocking(false) != NSAPI_ERROR_OK) {
printf("WARN: Could not set non-blocking interface\n");
blocking_interface = true;
}

// Stay here until we get a connection
EventQueue *queue = mbed::mbed_event_queue();
queue->dispatch_forever();
if (interface_connected) {
err = network_interface->get_ip_address(&sa);
if (err != NSAPI_ERROR_OK) {
printf("get_ip_address() - failed, status %d\n", err);
return -1;
if (!blocking_interface) {
for (int i = 1; i <= MCC_PLATFORM_CONNECTION_RETRY_COUNT; i++) {
err = network_interface->connect();
printf("network_interface->connect(): %d\n", err);
if (err == NSAPI_ERROR_IS_CONNECTED) {
interface_connected = true;
} else if (err != NSAPI_ERROR_OK) {
return -1;
} else {
async_connect = true;
mbed_event_queue()->dispatch_forever();
async_connect = false;
}

if (interface_connected) {
err = network_interface->get_ip_address(&sa);
if (err != NSAPI_ERROR_OK) {
printf("get_ip_address() - failed, status %d\n", err);
interface_connected = false;
} else {
printf("IP: %s\n", (sa.get_ip_address() ? sa.get_ip_address() : "None"));
printf("MAC address: %s\n", (network_interface->get_mac_address() ? network_interface->get_mac_address() : "None"));
return 0;
}
}
printf("Failed to connect! Retry %d/%d\n", i, MCC_PLATFORM_CONNECTION_RETRY_COUNT);
err = network_interface->disconnect();
printf("network_interface->disconnect(): %d\n", err);
mcc_platform_do_wait(MCC_PLATFORM_CONNECTION_RETRY_TIMEOUT * i);
}
printf("IP: %s\n", sa.get_ip_address() ? sa.get_ip_address() : "None");
return 0;
} else {
return -1;
for (int i = 1; i <= MCC_PLATFORM_CONNECTION_RETRY_COUNT; i++) {
err = network_interface->connect();
if (err == NSAPI_ERROR_OK || err == NSAPI_ERROR_IS_CONNECTED) {
err = network_interface->get_ip_address(&sa);
if (err != NSAPI_ERROR_OK) {
printf("get_ip_address() - failed, status %d\n", err);
} else {
printf("IP: %s\n", (sa.get_ip_address() ? sa.get_ip_address() : "None"));
printf("MAC address: %s\n", (network_interface->get_mac_address() ? network_interface->get_mac_address() : "None"));
interface_connected = true;
return 0;
}
}
printf("Failed to connect! error=%d. Retry %d/%d\n", err, i, MCC_PLATFORM_CONNECTION_RETRY_COUNT);
err = network_interface->disconnect();
printf("network_interface->disconnect(): %d\n", err);
mcc_platform_do_wait(MCC_PLATFORM_CONNECTION_RETRY_TIMEOUT * i);
}
}
#else
for (int i=1; i <= MCC_PLATFORM_CONNECTION_RETRY_COUNT; i++) {
for (int i = 1; i <= MCC_PLATFORM_CONNECTION_RETRY_COUNT; i++) {
err = network_interface->connect();
if (err == NSAPI_ERROR_OK || err == NSAPI_ERROR_IS_CONNECTED) {
err = network_interface->get_ip_address(&sa);
if (err != NSAPI_ERROR_OK) {
printf("get_ip_address() - failed, status %d\n", err);
goto retry;
} else {
printf("IP: %s\n", (sa.get_ip_address() ? sa.get_ip_address() : "None"));
printf("MAC address: %s\n", (network_interface->get_mac_address() ? network_interface->get_mac_address() : "None"));
interface_connected = true;
return 0;
}
printf("IP: %s\n", sa.get_ip_address() ? sa.get_ip_address() : "None");
interface_connected = true;
return 0;
}
printf("Failed to connect! error=%d. Retry %d/%d\n", err, i, MCC_PLATFORM_CONNECTION_RETRY_COUNT);
retry:
(void) network_interface->disconnect();
err = network_interface->disconnect();
printf("network_interface->disconnect(): %d\n", err);
mcc_platform_do_wait(MCC_PLATFORM_CONNECTION_RETRY_TIMEOUT * i);
}
return -1;
#endif

return -1;
}

int mcc_platform_interface_close(void) {
Expand All @@ -191,19 +235,15 @@ void* mcc_platform_interface_get(void) {

void network_status_callback(nsapi_event_t status, intptr_t param)
{
#ifdef MCC_USE_MBED_EVENTS
EventQueue *queue = mbed::mbed_event_queue();
#endif
if (status == NSAPI_EVENT_CONNECTION_STATUS_CHANGE) {
switch(param) {
case NSAPI_STATUS_GLOBAL_UP:
#ifdef MCC_USE_MBED_EVENTS
if (!interface_connected) {
queue->break_dispatch();
if (!interface_connected && async_connect) {
mbed_event_queue()->break_dispatch();
}
#endif
interface_connected = true;

#endif
#if MBED_CONF_MBED_TRACE_ENABLE
tr_info("NSAPI_STATUS_GLOBAL_UP");
#else
Expand All @@ -223,7 +263,12 @@ void network_status_callback(nsapi_event_t status, intptr_t param)
#else
printf("NSAPI_STATUS_DISCONNECTED\n");
#endif
#ifdef MCC_USE_MBED_EVENTS
if (network_interface && !async_connect) {
mbed_event_queue()->break_dispatch();
}
interface_connected = false;
#endif
break;
case NSAPI_STATUS_CONNECTING:
#if MBED_CONF_MBED_TRACE_ENABLE
Expand Down
Loading

0 comments on commit e9c83cf

Please sign in to comment.