Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXAS21002 FXOS8700Q
This example is known to work great on the following platforms:
- FRDM-K64F - onboard Ethernet and onboard SD card holder.
- FRDM-K66F - onboard Ethernet and onboard SD card holder.
Follow the Quick-Start instructions: https://cloud.mbed.com/quick-start

Example functionality
This example showcases the following device functionality:
- Read onboard FXOS8700Q accelerometer and magnetometer, and report the values as Pelion LWM2M resources (see image below).
- (FRDM-K66F only) Read onboard FXAS21002 gyroscope and report the values as Pelion LWM2M resources.
- 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.

Use this example with Mbed CLI
1. Import the application into your desktop:
mbed import https://os.mbed.com/teams/NXP/code/pelion-example-frdm cd pelion-example-frdm
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.
4. Compile and program:
mbed compile -t <toolchain> -m <TARGET_BOARD>
(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: 00000000000000000000 [BOOT] OEM: 00000000000000000000 [BOOT] Layout: 0 8374 [BOOT] Active firmware integrity check: [BOOT] SHA256: 411F422DE8FF545E2D3C373E87D5328162A129314A655AEC32B9A167DE29177E [BOOT] Version: 1553606618 [BOOT] Slot 0 is empty [BOOT] Active firmware up-to-date [BOOT] Application's start address: 0x10400 [BOOT] Application's jump address: 0x112C1 [BOOT] Application's stack address: 0x20030000 [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. Sensors configuration: FXOS8700Q accelerometer = 0xC7 FXOS8700Q magnetometer = 0xC7 FXAS21002 gyroscope = 0xB7 Connecting to the network using the default network interface... Connected to the network successfully. IP address: 10.2.202.65 Initializing Pelion Device Management Client... Initialized Pelion Device Management Client. Registering... Press the user button to increment the LwM2M resource value... FXOS8700Q mag: 0.312 x, 0.039 y, -1.625 z [gauss] FXOS8700Q acc: 0.139 x, -0.123 y, 4.260 z [g] FXAS21002 gryo: 13.089 x, 13.089 y, 13.089 z [dps]
Revision 5:f2123dc31d30, committed 2019-03-27
- Comitter:
- screamer
- Date:
- Wed Mar 27 17:49:40 2019 +0000
- Parent:
- 4:ec3c125c37bf
- Commit message:
- Improve inline documentation
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r ec3c125c37bf -r f2123dc31d30 main.cpp
--- a/main.cpp Tue Mar 26 13:56:38 2019 +0000
+++ b/main.cpp Wed Mar 27 17:49:40 2019 +0000
@@ -21,6 +21,33 @@
#include "simple-mbed-cloud-client.h"
#include "FATFileSystem.h"
#include "LittleFileSystem.h"
+
+// Default network interface object. Don't forget to change the WiFi SSID/password in mbed_app.json if you're using WiFi.
+NetworkInterface *net = NetworkInterface::get_default_instance();
+
+// Default block device available on the target board
+BlockDevice *bd = BlockDevice::get_default_instance();
+
+#if COMPONENT_SD || COMPONENT_NUSD
+// Use FATFileSystem for SD card type blockdevices
+FATFileSystem fs("fs");
+#else
+// Use LittleFileSystem for non-SD block devices to enable wear leveling and other functions
+LittleFileSystem fs("fs");
+#endif
+
+// Default User button for GET example and for resetting the storage
+InterruptIn button(BUTTON1);
+// Default LED to use for PUT/POST example
+DigitalOut led(LED1, 0);
+
+// How often to fetch sensor data (in seconds)
+#define SENSORS_POLL_INTERVAL 3.0
+
+// Send all sensor data or just limited (useful for when running out of memory)
+//#define SEND_ALL_SENSORS
+
+// Sensors related includes and initialization
#include "FXOS8700Q.h"
#include "FXAS21002.h"
@@ -36,34 +63,12 @@
FXAS21002 sens_gyro(PTD9, PTD8, 0x20);
#endif /* TARGET_K66F */
-#define SENSORS_POLL_INTERVAL 3.0
-#define SEND_ALL_SENSORS
-
-// Default network interface object. Don't forget to change the WiFi SSID/password in mbed_app.json if you're using WiFi.
-NetworkInterface *net = NetworkInterface::get_default_instance();
-
-// Default block device available on the target board
-BlockDevice *bd = BlockDevice::get_default_instance();
-
-#if COMPONENT_SD || COMPONENT_NUSD
-// Use FATFileSystem for SD card type blockdevices
-FATFileSystem fs("fs");
-#else
-// Use LittleFileSystem for non-SD block devices to enable wear leveling and other functions
-LittleFileSystem fs("fs");
-#endif
-
-#if USE_BUTTON == 1
-InterruptIn button(BUTTON1);
-#endif /* USE_BUTTON */
-
-// Default LED to use for PUT/POST example
-DigitalOut led(LED1);
-
// Declaring pointers for access to Pelion Device Management Client resources outside of main()
MbedCloudClientResource *res_button;
MbedCloudClientResource *res_led;
MbedCloudClientResource *res_post;
+
+// Additional resources for sensor readings
#ifdef SEND_ALL_SENSORS
MbedCloudClientResource *res_magnometer_x;
MbedCloudClientResource *res_magnometer_y;

