Pelion Device Management example over 15.4 Thread for Thunderboard Sense 2 board

Dependencies:   ICM20648 BMP280 Si1133 Si7210 AMS_CCS811_gas_sensor SI7021

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:

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

Thunderboard Sense 2

Example functionality

This example showcases the following device functionality:

  • Read onboard sensors, and report them as Pelion LWM2M resources:
    • Barometric Pressure and Temperature (BMP280)
    • Relative Humidity and Temperature (Si7021)
    • Air quality - CO2 and tVOC (CCS811)
    • Light intensity and UV level (Si1133)
    • Hall effect and Temperature (Si7210)
    • Accelerometer and Gyroscope (ICM20648)
  • It also exposes the RGB LEDs for triggering flashes in a specific color
  • On user button click, increment Pelion LWM2M button resource.

/media/uploads/screamer/pelion_st_humidity_reading.png?v=2

15.4 Thread setup

This example program requires that a Thread Border Router is available. A Border Router is a network gateway between a wireless 6LoWPAN mesh network and a backhaul network. It controls and relays traffic between the two networks. In a typical setup, a 6LoWPAN border router is connected to another router in the backhaul network (over Ethernet or a serial line) which in turn forwards traffic to/from the internet or a private company LAN, for instance.

https://raw.githubusercontent.com/ARMmbed/nanostack-border-router/f8bf21aac12c9926afba252187e2adf2525bf1eb/images/br_role.png

Instructions how to set up a Thread Border Router

Use this example with Mbed CLI

1. Import the application into your desktop:

mbed import https://os.mbed.com/teams/SiliconLabs/code/pelion-example-tbsense2

cd pelion-example-tbsense2

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 TB_SENSE_2

(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 90AC
[BOOT] Active firmware integrity check:
[BOOT] SHA256: 615A11A7F03B1F048573E2CB51D8C9A5DD4E6F17A7F8E79C4B64E3241FF78974
[BOOT] Version: 1553594998
[BOOT] Slot 0 is empty
[BOOT] Active firmware up-to-date
[BOOT] Application's start address: 0x10400
[BOOT] Application's jump address: 0x10FBD
[BOOT] Application's stack address: 0x20040000
[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 802.15.4...
Connected to the network successfully. IP address: 2001:****:****:****:****:****:****:73bc
Initializing Pelion Device Management Client...
Si7021 Electronic Serial Number:                0         15b5ffff, firmware rev 20
Registered to Pelion Device Management. Endpoint Name: 0169b91a********************01a0
                                                                 
BMP280 temp:     32.750 C,   pressure: 1030.750 [mbar]            
Si7021 temp:     27.529 C,   humidity:   24.842 %                 
Si7210 temp:     34.484 C,   field:      -0.076 [mT]              
Si1133 light:  1258.574 lux, UV level:    0.031                       
CCS811 CO2:           0 ppm, VoC:             0 ppb                   
ICM20648 acc:    -0.093 x,  -0.057 y,     0.969 z [mg]            
ICM20648 gyro:   -1.503 x,   0.122 y,    -0.771 z [mdps]          
    
Revision:
6:ec491c9aae8f
Parent:
4:0b54e0395ac1
Child:
7:c5ebecef1a84
--- a/main.cpp	Wed Mar 27 17:04:04 2019 +0000
+++ b/main.cpp	Wed Mar 27 17:50:52 2019 +0000
@@ -3,7 +3,6 @@
 #include "BlockDevice.h"
 #include "LittleFileSystem.h"
 #include "NetworkInterface.h"
-#include "mbed_trace.h"
 #include "Nanostack.h"
 #include "ns_file_system.h"
 
@@ -16,16 +15,25 @@
 // Currently, this split is at 256/768 for FS/upgrade.
 BlockDevice* bd = BlockDevice::get_default_instance();
 SlicingBlockDevice sd(bd, 0, MBED_CONF_UPDATE_CLIENT_STORAGE_ADDRESS);
-LittleFileSystem fs("fs", &sd);
 
-// An event queue is a very useful structure to debounce information between contexts (e.g. ISR and normal threads)
-// This is great because things such as network operations are illegal in ISR, so updating a resource in a button's fall() function is not allowed.
-EventQueue eventQueue;
+#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(BTN0);
 
-//------------------------------------------------------------------------------
-// Includes and declarations for our sensor array
+// 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 "BMP280.h"
 #include "Si1133.h"
 #include "SI7021.h"
@@ -33,10 +41,6 @@
 #include "AMS_CCS811.h"
 #include "ICM20648.h"
 
-// Define measurement intervals in seconds
-#define SENSORS_POLL_INTERVAL 3.0
-#define SEND_ALL_SENSORS
-
 /* Turn on power supply to ENV sensor suite */
 DigitalOut env_en(PF9, 1);
 /* Turn on power to CCS811 sensor */
@@ -61,6 +65,7 @@
 MbedCloudClientResource *res_button;
 MbedCloudClientResource *res_led;
 
+// Additional resources for sensor readings
 #ifdef SEND_ALL_SENSORS
 MbedCloudClientResource *res_light;
 MbedCloudClientResource *res_pressure;
@@ -80,10 +85,20 @@
 MbedCloudClientResource *res_temperature4;
 #endif /* SEND_ALL_SENSORS */
 
+// An event queue is a very useful structure to debounce information between contexts (e.g. ISR and normal threads)
+// This is great because things such as network operations are illegal in ISR, so updating a resource in a button's fall() function is not allowed.
+EventQueue eventQueue;
+
 // When the device is registered, this variable will be used to access various useful information, like device ID etc.
 static const ConnectorClientEndpointInfo* endpointInfo;
 
-
+/**
+ * POST handler - prints the content of the payload
+ * @param resource The resource that triggered the callback
+ * @param buffer If a body was passed to the POST function, this contains the data.
+ *               Note that the buffer is deallocated after leaving this function, so copy it if you need it longer.
+ * @param size Size of the body
+ */
 void blink_callback(MbedCloudClientResource *resource, const uint8_t *buffer, uint16_t size) {
     static int num_count = 0;
     static int event = 0;
@@ -335,7 +350,6 @@
     if (storage_status != 0) {
         printf("Storage mounting failed.\n");
     }
-
 #if USE_BUTTON == 1
     // If the User button is pressed ons start, then format storage.
     bool btn_pressed = (button.read() == MBED_CONF_APP_BUTTON_PRESSED_STATE);
@@ -356,6 +370,8 @@
         printf("You can hold the user button during boot to format the storage and change the device identity.\n");
     }
 
+    sensors_init();
+
     Nanostack::get_instance(); // ensure Nanostack is initialised
     ns_file_system_set_root_path("/fs/");
 
@@ -490,8 +506,6 @@
     res_temperature4->methods(M2MMethod::GET);
 #endif /* SEND_ALL_SENSORS */
 
-    sensors_init();
-
     // Callback that fires when registering is complete
     client.on_registered(&registered);