Mbed OS and Pelion Device Management example over WIFI for RHOMBIO_L476DMW1K IoT kit

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:

RHOMBIO_L476DMW1K over WiFI and using onboard QSPI flash.

/media/uploads/galonso/rhombio_l476dmw1k_kit_assembled.png

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

Example functionality

This example showcases the following device functionality:

  • Read onboard MCU ADC temperature and MCU ADC voltage reference, and report them as Pelion LWM2M resources (see image below).
  • On user button click, increment Pelion LWM2M button resource.
  • Allow the user to change the state of the board LED from Pelion LWM2M led_state resource and PUT request.
  • External sensors can be easily added to the kit and then sensor readings reported as Pelion LWM2M resources.

/media/uploads/galonso/temperature_-_sensor_value_-_pelion_device_management_portal.png

Use this example with Mbed CLI

1. Import the application into your desktop:

mbed import https://os.mbed.com/teams/Rhombio/code/pelion-example-rhombio-l476dmw1k

cd pelion-example-rhombio-l476dmw1k

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.8.x or above.

4. Compile and program:

mbed compile -t <toolchain> -m RHOMBIO_L476DMW1K -f

(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] Mbed Bootloader
[BOOT] ARM: 0000000000000000000000000000000000000000
[BOOT] OEM: 0000000000000000000000000000000000000000
[BOOT] Layout: 0 800D24C
[BOOT] Active firmware integrity check:
[BOOT] SHA256: 9036E19F1414720659B2C2FAC8855F621AF533BA211D930119720E7A2BD60BF2
[BOOT] Version: 1558516039
[BOOT] Slot 0 is empty
[BOOT] Active firmware up-to-date
[BOOT] Application's start address: 0x8010400
[BOOT] Application's jump address: 0x8010889
[BOOT] Application's stack address: 0x20018000
[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 Wifi...
Connected to the network successfully. IP address: 192.168.1.201
Initializing Pelion Device Management Client...
Initialized Pelion Client. Registering...
Registered to Pelion Device Management. Endpoint Name: 016a***********************10006d
                                                             
ADC temp: 23.1746 C,  vref: 0.3665 V         
                                                             
ADC temp: 23.2234 C,  vref: 0.3663 V      
Committer:
galonso@rhomb.io
Date:
Tue May 21 18:15:26 2019 +0200
Revision:
0:9ff56a0e4c0d
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
galonso@rhomb.io 0:9ff56a0e4c0d 1 ## Mbed OS Device Management / Pelion Enablement
galonso@rhomb.io 0:9ff56a0e4c0d 2 How to bring up new platforms and run tests successfully (and with ease!)
galonso@rhomb.io 0:9ff56a0e4c0d 3
galonso@rhomb.io 0:9ff56a0e4c0d 4 See porting guide at https://github.com/ARMmbed/simple-mbed-cloud-client#device-management-configuration.
galonso@rhomb.io 0:9ff56a0e4c0d 5
galonso@rhomb.io 0:9ff56a0e4c0d 6 Also validation and testing guide available at https://github.com/ARMmbed/simple-mbed-cloud-client#validation-and-testing
galonso@rhomb.io 0:9ff56a0e4c0d 7
galonso@rhomb.io 0:9ff56a0e4c0d 8 ### Setup your environment
galonso@rhomb.io 0:9ff56a0e4c0d 9
galonso@rhomb.io 0:9ff56a0e4c0d 10 1. Make sure that you have Mbed CLI over 1.9.1
galonso@rhomb.io 0:9ff56a0e4c0d 11 ```
galonso@rhomb.io 0:9ff56a0e4c0d 12 C:\>mbed --version
galonso@rhomb.io 0:9ff56a0e4c0d 13 1.9.1
galonso@rhomb.io 0:9ff56a0e4c0d 14 ```
galonso@rhomb.io 0:9ff56a0e4c0d 15 For instruction on how to upgrade Mbed CLI, please refer to this [link](https://github.com/ARMmbed/mbed-cli).
galonso@rhomb.io 0:9ff56a0e4c0d 16
galonso@rhomb.io 0:9ff56a0e4c0d 17 2. Get the whole test code via `mbed import git@github.com:ARMmbed/pelion-enablement.git`
galonso@rhomb.io 0:9ff56a0e4c0d 18
galonso@rhomb.io 0:9ff56a0e4c0d 19 It will automatically expand dependent libraries in the test SW.
galonso@rhomb.io 0:9ff56a0e4c0d 20
galonso@rhomb.io 0:9ff56a0e4c0d 21 3. Get mbed_cloud_dev_credential.c file from the Pelion portal.
galonso@rhomb.io 0:9ff56a0e4c0d 22
galonso@rhomb.io 0:9ff56a0e4c0d 23 Then overwrite the existing mbed_cloud_dev_credential.c file.
galonso@rhomb.io 0:9ff56a0e4c0d 24
galonso@rhomb.io 0:9ff56a0e4c0d 25 4. Install the `CLOUD_SDK_API_KEY`
galonso@rhomb.io 0:9ff56a0e4c0d 26
galonso@rhomb.io 0:9ff56a0e4c0d 27 `mbed config -G CLOUD_SDK_API_KEY ak_1MDE1...<snip>`
galonso@rhomb.io 0:9ff56a0e4c0d 28
galonso@rhomb.io 0:9ff56a0e4c0d 29 For convenience, this repository uses pre-generated certificates for API key `ak_1MDE1ZjZlMzg4ZTVkMDI0MjBhMDExYjA4MDAwMDAwMDA016617c30d482200d95670ee000000006iCt30Oe5HufoIQbyhTo1ybH00EZviYo`. It's recommended that you generate your own API key as some of the tests (e.g. LWM2M Post) are limited to 1 open active connection to the Pelion DM API server at a time. You should use this key only if you don't have access to Pelion Device Management (which is free to register for any Mbed developer - therefore go register now!).
galonso@rhomb.io 0:9ff56a0e4c0d 30
galonso@rhomb.io 0:9ff56a0e4c0d 31 For instructions on how to generate your API key, please [see the documentation](https://cloud.mbed.com/docs/current/integrate-web-app/api-keys.html#generating-an-api-key).
galonso@rhomb.io 0:9ff56a0e4c0d 32
galonso@rhomb.io 0:9ff56a0e4c0d 33 5. Initialize firmware credentials (optional)
galonso@rhomb.io 0:9ff56a0e4c0d 34
galonso@rhomb.io 0:9ff56a0e4c0d 35 Simple Pelion DM Client provides Greentea tests to test your porting efforts. Before running these tests, it's recommended that you run the `mbed dm init` command, which will install all needed credentials for both Connect and Update Pelion DM features. You can use the following command:
galonso@rhomb.io 0:9ff56a0e4c0d 36 ```
galonso@rhomb.io 0:9ff56a0e4c0d 37 $ cd pelion-enablement
galonso@rhomb.io 0:9ff56a0e4c0d 38 $ mbed dm init -d "<your company name in Pelion DM>" --model-name "<product model identifier>" -q --force
galonso@rhomb.io 0:9ff56a0e4c0d 39 ```
galonso@rhomb.io 0:9ff56a0e4c0d 40 If above command do not work for your mbed-cli, please consider upgrading Mbed CLI.
galonso@rhomb.io 0:9ff56a0e4c0d 41
galonso@rhomb.io 0:9ff56a0e4c0d 42 6. (Optional) If you already compiled your bootloader for your specific target device
galonso@rhomb.io 0:9ff56a0e4c0d 43
galonso@rhomb.io 0:9ff56a0e4c0d 44 If so, please update your bootloader to mbed-os.
galonso@rhomb.io 0:9ff56a0e4c0d 45
galonso@rhomb.io 0:9ff56a0e4c0d 46 ### Known problems
galonso@rhomb.io 0:9ff56a0e4c0d 47
galonso@rhomb.io 0:9ff56a0e4c0d 48 1. On Windows and when using `GCC_ARM`, you're likely to hit the Path limit. The workaround is running following commands:
galonso@rhomb.io 0:9ff56a0e4c0d 49 - Move the repo directory close to `C:\`
galonso@rhomb.io 0:9ff56a0e4c0d 50
galonso@rhomb.io 0:9ff56a0e4c0d 51 `move C:\...\pelion-enablement C:\P`
galonso@rhomb.io 0:9ff56a0e4c0d 52 - Rename simple-mbed-cloud-client foler and lib file
galonso@rhomb.io 0:9ff56a0e4c0d 53
galonso@rhomb.io 0:9ff56a0e4c0d 54 `move simple-mbed-cloud-client spdmc`
galonso@rhomb.io 0:9ff56a0e4c0d 55
galonso@rhomb.io 0:9ff56a0e4c0d 56 `move simple-mbed-cloud-client.lib spdmc.lib`
galonso@rhomb.io 0:9ff56a0e4c0d 57 - Compile and run with changed test name prefix of `spdmc-`.
galonso@rhomb.io 0:9ff56a0e4c0d 58
galonso@rhomb.io 0:9ff56a0e4c0d 59 `mbed test -t <TOOLCHAIN> -m <TARGET> -n spdmc-tests-* --compile`
galonso@rhomb.io 0:9ff56a0e4c0d 60
galonso@rhomb.io 0:9ff56a0e4c0d 61 `mbed test -t <TOOLCHAIN> -m <TARGET> -n spdmc-tests-* --run -v`