Specific Pelion ready example using features of Uhuru RAVEN board including Wi-Fi and SPI flash

DEPRECATED

This example application is not maintained and not recommended. It uses an old version of Mbed OS, Pelion DM, and Arm toolchain. It doesn't work with Mbed Studio.

Please use: https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-pelion/

This example is known to work great on the following platforms:
Uhuru RAVEN over Wi-Fi and using onboard SPI flash.

/media/uploads/MACRUM/raven.jpg

Follow the Quick-Start instructions: https://cloud.mbed.com/quick-start

Example functionality

This example showcases the following device functionality:

  • Allow the user to change the state of the board LED from Pelion LWM2M led_state resource and PUT request.

Use this example with Mbed CLI

1. Import the application into your desktop:

mbed import https://os.mbed.com/teams/Uhuru/code/pelion-example-common/

cd pelion-example-common

2. Install the CLOUD_SDK_API_KEY

mbed config -G CLOUD_SDK_API_KEY <PELION_DM_API_KEY>

For instructions on how to generate your API key, please see the documentation.

3. Initialize firmware credentials (done once per repository). You can use the following command:

mbed dm init -d "<your company name in Pelion DM>" --model-name "<product model identifier>" -q --force

If above command do not work for your Mbed CLI, please consider upgrading Mbed CLI to version 1.9.x or above.

Set SSID and password in the mbed_app.json.

            "nsapi.default-wifi-ssid"                   : "\"SSID\"",
            "nsapi.default-wifi-password"               : "\"Password\""

4. Compile and program:

mbed compile -t <toolchain> -m UHURU_RAVEN

(supported toolchains : GCC_ARM / ARM / IAR)

5. You can connect on a virtual terminal/COM port to the platform using:

mbed sterm -b 115200

This should give you an output similar to:

[BOOT] INFO: init - verified SFDP Signature and version Successfully
[BOOT] DEBUG: Erase Type(A) 1 - Inst: 0xFFh, Size: 4096
[BOOT] INFO: Erase Type 1 - Inst: 0x20h, Size: 4096
[BOOT] DEBUG: Erase Type(A) 2 - Inst: 0xFFh, Size: 32768
[BOOT] INFO: Erase Type 2 - Inst: 0x52h, Size: 32768
[BOOT] DEBUG: Erase Type(A) 3 - Inst: 0xFFh, Size: 65536
[BOOT] INFO: Erase Type 3 - Inst: 0xD8h, Size: 65536
[BOOT] DEBUG: Erase Type(A) 4 - Inst: 0xFFh, Size: 1
[BOOT] INFO: Erase Type 4 - Inst: 0xFFh, Size: 1
[BOOT] Mbed Bootloader
[BOOT] ARM: 00000000000000000000
[BOOT] OEM: 00000000000000000000
[BOOT] Layout: 0 80091E0
[BOOT] Active firmware integrity check:
[BOOT] SHA256: DC87CF84F7064E58EF0FD011C1768ADFA4803BA1F6758808972680605CBB2C9B
[BOOT] Version: 1558427552
[BOOT] INFO Read - Inst: 0x3h
[BOOT] Slot 0 is empty
[BOOT] Active firmware up-to-date
[BOOT] Application's start address: 0x8010400
[BOOT] Application's jump address: 0x80108F9
[BOOT] Application's stack address: 0x20080000
[BOOT] Forwarding to application...
..¿<.
Starting Simple Pelion Device Management Client example
You can hold the user button during boot to format the storage and change the device identity.
Connecting to the network using the default network interface...
Connected to the network successfully. IP address: 192.168.11.20
Initializing Pelion Device Management Client...
Initialized Pelion Device Management Client. Registering...
Simulating button press every 5 seconds...
Registered to Pelion Device Management. Endpoint Name: 016ad986878400000000000100xxxxxx
Button clicked 1 times
Button clicked 2 times
Button clicked 3 times
Committer:
MACRUM
Date:
Tue May 21 17:19:38 2019 +0900
Revision:
0:16957896f9cd
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:16957896f9cd 1 # Pelion Device Ready example - template application
MACRUM 0:16957896f9cd 2
MACRUM 0:16957896f9cd 3 (aka Simple Mbed Cloud Client template)
MACRUM 0:16957896f9cd 4
MACRUM 0:16957896f9cd 5 ## Overview
MACRUM 0:16957896f9cd 6
MACRUM 0:16957896f9cd 7 This is a template application to showcase device management capabilities. It demonstrates how to create a simple application that can connect to the Pelion IoT Platform service, register resources and get ready to receive a firmware update.
MACRUM 0:16957896f9cd 8
MACRUM 0:16957896f9cd 9 It's intended to be forked and customized to add platform-specific features (such as sensors and actuators) and configure the connectivity and storage to work **out-of-the-box**. The template application works in **developer mode** by default.
MACRUM 0:16957896f9cd 10
MACRUM 0:16957896f9cd 11 There is a mirror version of the stable (master) template application on [this location](https://os.mbed.com/teams/mbed-os-examples/code/pelion-ready-example) to facilitate the fork and publish on https://os.mbed.com.
MACRUM 0:16957896f9cd 12
MACRUM 0:16957896f9cd 13 ## Board specific example applications
MACRUM 0:16957896f9cd 14
MACRUM 0:16957896f9cd 15 There are a number of applications that make usage of the Simple Pelion DM Client library.
MACRUM 0:16957896f9cd 16
MACRUM 0:16957896f9cd 17 The Pelion [Quick-Start](https://cloud.mbed.com/quick-start) is an initiative to support Mbed Partner's platforms while delivering a great User Experience to Mbed Developers.
MACRUM 0:16957896f9cd 18
MACRUM 0:16957896f9cd 19 ## Getting started with the application
MACRUM 0:16957896f9cd 20
MACRUM 0:16957896f9cd 21 This is a summary of the process for developers to get started and get a device connected to Pelion Device Management.
MACRUM 0:16957896f9cd 22
MACRUM 0:16957896f9cd 23 ### Using Mbed Online IDE
MACRUM 0:16957896f9cd 24
MACRUM 0:16957896f9cd 25 1. Import the application into the Online IDE.
MACRUM 0:16957896f9cd 26 2. Add the API key to establish connection.
MACRUM 0:16957896f9cd 27 3. Install the developer certificate.
MACRUM 0:16957896f9cd 28 4. Compile and program.
MACRUM 0:16957896f9cd 29
MACRUM 0:16957896f9cd 30 ### Using Mbed CLI
MACRUM 0:16957896f9cd 31
MACRUM 0:16957896f9cd 32 1. Import the application into your desktop:
MACRUM 0:16957896f9cd 33
MACRUM 0:16957896f9cd 34 ```
MACRUM 0:16957896f9cd 35 mbed import https://github.com/ARMmbed/pelion-ready-example
MACRUM 0:16957896f9cd 36 cd pelion-ready-example
MACRUM 0:16957896f9cd 37 ```
MACRUM 0:16957896f9cd 38
MACRUM 0:16957896f9cd 39 2. Configure the API key for your Pelion Portal account.
MACRUM 0:16957896f9cd 40
MACRUM 0:16957896f9cd 41 If you don't have an API key available, then login in [Pelion IoT Platform portal](https://portal.mbedcloud.com/), navigate to 'Access Management', 'API keys' and create a new one. Then specify the API key as global `mbed` configuration:
MACRUM 0:16957896f9cd 42
MACRUM 0:16957896f9cd 43 ```
MACRUM 0:16957896f9cd 44 mbed config -G CLOUD_SDK_API_KEY <your-api-key>
MACRUM 0:16957896f9cd 45 ```
MACRUM 0:16957896f9cd 46
MACRUM 0:16957896f9cd 47 3. Install the device management certificate:
MACRUM 0:16957896f9cd 48
MACRUM 0:16957896f9cd 49 ```
MACRUM 0:16957896f9cd 50 mbed dm init -d "company.com" --model-name "product-model" -q --force
MACRUM 0:16957896f9cd 51 ```
MACRUM 0:16957896f9cd 52
MACRUM 0:16957896f9cd 53 4. Compile and program:
MACRUM 0:16957896f9cd 54
MACRUM 0:16957896f9cd 55 ```
MACRUM 0:16957896f9cd 56 mbed compile -t <toolchain> -m <target> -f
MACRUM 0:16957896f9cd 57 ```
MACRUM 0:16957896f9cd 58
MACRUM 0:16957896f9cd 59 #### Update the application logic
MACRUM 0:16957896f9cd 60
MACRUM 0:16957896f9cd 61 The template example uses a ticker object to periodically fire a software interrupt to simulate button presses. Let’s say you want to make an actual button press.
MACRUM 0:16957896f9cd 62
MACRUM 0:16957896f9cd 63 By default, there is a Ticker object, which fires every five seconds and invokes a callback function:
MACRUM 0:16957896f9cd 64
MACRUM 0:16957896f9cd 65 ```cpp
MACRUM 0:16957896f9cd 66 Ticker timer;
MACRUM 0:16957896f9cd 67 timer.attach(eventQueue.event(&fake_button_press), 5.0);
MACRUM 0:16957896f9cd 68 ```
MACRUM 0:16957896f9cd 69
MACRUM 0:16957896f9cd 70 This callback function changes the `button_res` resource:
MACRUM 0:16957896f9cd 71
MACRUM 0:16957896f9cd 72 ```cpp
MACRUM 0:16957896f9cd 73 void fake_button_press() {
MACRUM 0:16957896f9cd 74 int v = button_res->get_value_int() + 1;
MACRUM 0:16957896f9cd 75
MACRUM 0:16957896f9cd 76 button_res->set_value(v);
MACRUM 0:16957896f9cd 77
MACRUM 0:16957896f9cd 78 printf("Simulated button clicked %d times\n", v);
MACRUM 0:16957896f9cd 79 }
MACRUM 0:16957896f9cd 80 ```
MACRUM 0:16957896f9cd 81
MACRUM 0:16957896f9cd 82 If you want to change this to an actual button, here is how to do it:
MACRUM 0:16957896f9cd 83
MACRUM 0:16957896f9cd 84 1. Remove:
MACRUM 0:16957896f9cd 85
MACRUM 0:16957896f9cd 86 ```cpp
MACRUM 0:16957896f9cd 87 Ticker timer;
MACRUM 0:16957896f9cd 88 timer.attach(eventQueue.event(&fake_button_press), 5.0);
MACRUM 0:16957896f9cd 89 ```
MACRUM 0:16957896f9cd 90
MACRUM 0:16957896f9cd 91 2. Declare an `InterruptIn` object on the button, and attach the callback function to the `fall` handler:
MACRUM 0:16957896f9cd 92
MACRUM 0:16957896f9cd 93 ```cpp
MACRUM 0:16957896f9cd 94 InterruptIn btn(BUTTON1);
MACRUM 0:16957896f9cd 95 btn.fall(eventQueue.event(&fake_button_press), 5.0);
MACRUM 0:16957896f9cd 96 ```
MACRUM 0:16957896f9cd 97
MACRUM 0:16957896f9cd 98 3. Rename `fake_button_press` to `real_button_press`.
MACRUM 0:16957896f9cd 99
MACRUM 0:16957896f9cd 100 ## Enabling firmware updates
MACRUM 0:16957896f9cd 101
MACRUM 0:16957896f9cd 102 Mbed OS 5.10 and Mbed CLI 1.9 simplifies the process to enable and perform Firmware Updates. Here is a summary on how to configure the device and verify its correct behaviour.
MACRUM 0:16957896f9cd 103
MACRUM 0:16957896f9cd 104 For full documentation about bootloaders and firmware update, read the following documents:
MACRUM 0:16957896f9cd 105
MACRUM 0:16957896f9cd 106 - [Introduccion to bootloaders](https://os.mbed.com/docs/latest/porting/bootloader.html)
MACRUM 0:16957896f9cd 107 - [Creating and using a bootloader](https://os.mbed.com/docs/latest/tutorials/bootloader.html)
MACRUM 0:16957896f9cd 108 - [Bootloader configuration in Mbed OS](https://os.mbed.com/docs/latest/tools/configuring-tools.html)
MACRUM 0:16957896f9cd 109 - [Mbed Bootloader for Pelion Device Management Client](https://github.com/ARMmbed/mbed-bootloader)
MACRUM 0:16957896f9cd 110 - [Updating devices with Arm Mbed CLI](https://os.mbed.com/docs/latest/tools/cli-update.html)
MACRUM 0:16957896f9cd 111
MACRUM 0:16957896f9cd 112 This is a summary to use Arm Mbed OS managed bootloaders.
MACRUM 0:16957896f9cd 113
MACRUM 0:16957896f9cd 114 #### Verifying that firmware update works
MACRUM 0:16957896f9cd 115
MACRUM 0:16957896f9cd 116 Follow these steps to generate a manifest, compile and perform a firmware update of your device:
MACRUM 0:16957896f9cd 117
MACRUM 0:16957896f9cd 118 1. Configure the API key for your Pelion account.
MACRUM 0:16957896f9cd 119
MACRUM 0:16957896f9cd 120 If you don't have an API key available, then login in [Pelion IoT Platform portal](https://portal.mbedcloud.com/), navigate to 'Access Management', 'API keys' and create a new one. Then specify the API key as global `mbed` configuration:
MACRUM 0:16957896f9cd 121
MACRUM 0:16957896f9cd 122 ```
MACRUM 0:16957896f9cd 123 mbed config -G CLOUD_SDK_API_KEY <your-api-key>
MACRUM 0:16957896f9cd 124 ```
MACRUM 0:16957896f9cd 125
MACRUM 0:16957896f9cd 126 2. Initialize the device management feature:
MACRUM 0:16957896f9cd 127
MACRUM 0:16957896f9cd 128 ```
MACRUM 0:16957896f9cd 129 mbed dm init -d "company.com" --model-name "product-model" -q --force
MACRUM 0:16957896f9cd 130 ```
MACRUM 0:16957896f9cd 131
MACRUM 0:16957896f9cd 132 3. Compile the application, include the firware update credentials generated before, merge with the bootloader and program the device:
MACRUM 0:16957896f9cd 133
MACRUM 0:16957896f9cd 134 ```
MACRUM 0:16957896f9cd 135 mbed compile -t <toolchain> -m <target> -c -f
MACRUM 0:16957896f9cd 136 ```
MACRUM 0:16957896f9cd 137
MACRUM 0:16957896f9cd 138 4. Open a serial terminal, verify the application boots and is able to register to the Device Management service. Write down the `<endpoint ID>`, as it's required to identify the device to perform a firmware update.
MACRUM 0:16957896f9cd 139
MACRUM 0:16957896f9cd 140 5. Update the firmware of the device through Mbed CLI:
MACRUM 0:16957896f9cd 141
MACRUM 0:16957896f9cd 142 ```
MACRUM 0:16957896f9cd 143 mbed dm update device -D <device ID> -t <toolchain> -m <target>
MACRUM 0:16957896f9cd 144 ```
MACRUM 0:16957896f9cd 145
MACRUM 0:16957896f9cd 146 Inspect the logs on the device to see the update progress. It should look similar to:
MACRUM 0:16957896f9cd 147
MACRUM 0:16957896f9cd 148 ```
MACRUM 0:16957896f9cd 149 Firmware download requested
MACRUM 0:16957896f9cd 150 Authorization granted
MACRUM 0:16957896f9cd 151 Downloading: [+++- ] 6 %
MACRUM 0:16957896f9cd 152 ```
MACRUM 0:16957896f9cd 153
MACRUM 0:16957896f9cd 154 When the download completes, the firmware is verified. If everything is OK, the firmware update is applied, the device reboots and attemps to connect to the Device Management service again. The `<endpoint ID>` should be preserved.
MACRUM 0:16957896f9cd 155
MACRUM 0:16957896f9cd 156 ## Automated testing
MACRUM 0:16957896f9cd 157
MACRUM 0:16957896f9cd 158 The Simple Pelion Client provides Greentea tests to confirm your platform works as expected. The network and storage configuration is already defined in Mbed OS 5.10, but you may want to override the configuration in `mbed_app.json`.
MACRUM 0:16957896f9cd 159
MACRUM 0:16957896f9cd 160 For details on Simple Pelion Client testing, refer to the documentation [here](https://github.com/ARMmbed/simple-mbed-cloud-client#testing).
MACRUM 0:16957896f9cd 161
MACRUM 0:16957896f9cd 162 This template application contains a working application and tests passing for the `K64F` and `K66F` platforms.