Generic Pelion Device Management example for various U-blox-based boards.
Dependencies: ublox-at-cellular-interface ublox-cellular-base
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:
- UBLOX_C030_R412M over Cellular and using SD card.
- UBLOX_C030_U201 over Cellular and using SD card.
For Odin-W2 please go to Repository link
Follow the Quick-Start instructions: https://cloud.mbed.com/quick-start
Example functionality
This example showcases the following device functionality:
- 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.
- (currently disabled)
Read ADC temperature and ADC vref, and report them as Pelion LWM2M resources.
Use this example with Mbed CLI
1. Import the application into your desktop:
mbed import https://os.mbed.com/teams/ublox/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.8.x or above.
4. Compile and program:
mbed compile -t <toolchain> -m <TARGET_BOARD>
(supported toolchains : GCC_ARM / ARM / IAR)
Diff: main.cpp
- Revision:
- 3:3b2db67b206e
- Parent:
- 1:a50c1e691ff1
- Child:
- 6:2fb5057c0e42
--- a/main.cpp Sun Dec 16 15:03:28 2018 +0000 +++ b/main.cpp Sun Dec 16 15:03:49 2018 +0000 @@ -26,19 +26,31 @@ // 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; -// Default network interface object +// 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 +// Default block device available on the target board BlockDevice *bd = BlockDevice::get_default_instance(); -SlicingBlockDevice sd(bd, 0, 2*1024*1024); -LittleFileSystem fs("fs", &sd); + +#if COMPONENT_SD || COMPONENT_NUSD +// Use FATFileSystem for SD card type blockdevices +FATFileSystem fs("fs", bd); +#else +// Use LittleFileSystem for non-SD block devices to enable wear leveling and other functions +LittleFileSystem fs("fs", bd); +#endif + +// Fix for older versions of Mbed OS where BUTTON1 is undefined +#if TARGET_UBLOX_C030 +#define BUTTON1 PC_13 +#endif // Default User button for GET example InterruptIn button(BUTTON1); // Default LED to use for PUT/POST example DigitalOut led(LED1); +// Currently disabled until ADC sensors are introduced for U-blox targets. #ifdef ENABLE_SENSORS // Default temperature reading from microcontroller AnalogIn adc_temp(ADC_TEMP); @@ -65,7 +77,7 @@ * @param newValue Updated value for the resource */ void led_put_callback(MbedCloudClientResource *resource, m2m::String newValue) { - printf("PUT received, new value: %s\n", newValue.c_str()); + printf("PUT received. New value: %s\n", newValue.c_str()); led = atoi(newValue.c_str()); } @@ -77,7 +89,7 @@ * @param size Size of the body */ void led_post_callback(MbedCloudClientResource *resource, const uint8_t *buffer, uint16_t size) { - printf("POST received. Going to blink LED pattern: %s\n", res_led->get_value().c_str()); + printf("POST received. Payload: %s\n", res_led->get_value().c_str()); led = atoi(res_led->get_value().c_str()); } @@ -104,7 +116,7 @@ * @param endpoint Information about the registered endpoint such as the name (so you can find it back in portal) */ void registered(const ConnectorClientEndpointInfo *endpoint) { - printf("Connected to Pelion Device Management. Endpoint Name: %s\n", endpoint->internal_endpoint_name.c_str()); + printf("Registered to Pelion Device Management. Endpoint Name: %s\n", endpoint->internal_endpoint_name.c_str()); endpointInfo = endpoint; } @@ -126,17 +138,17 @@ int main(void) { - printf("Starting Simple Pelion Device Management Client example\n"); + printf("\nStarting Simple Pelion Device Management Client example\n"); // If the User button is pressed ons start, then format storage. + DigitalIn *user_button = new DigitalIn(BUTTON1); const int PRESSED = 1; - DigitalIn *user_button = new DigitalIn(BUTTON1); if (user_button->read() == PRESSED) { printf("User button is pushed on start. Formatting the storage...\n"); - int storage_status = fs.reformat(&sd); + int storage_status = fs.reformat(bd); if (storage_status != 0) { - if (sd.erase(0, sd.size()) == 0) { - if (fs.format(&sd) == 0) { + if (bd->erase(0, bd->size()) == 0) { + if (fs.format(bd) == 0) { storage_status = 0; printf("The storage reformatted successfully.\n"); } @@ -145,10 +157,12 @@ if (storage_status != 0) { printf("ERROR: Failed to reformat the storage (%d).\n", storage_status); } + } else { + printf("You can hold the user button during boot to format the storage and change the device identity.\n"); } // Connect to the internet (DHCP is expected to be on) - printf("Connecting to the network using Wifi...\n"); + printf("Connecting to the network using default network interface...\n"); net = NetworkInterface::get_default_instance(); nsapi_error_t net_status = -1; @@ -209,12 +223,13 @@ // Register with Pelion DM client.register_and_connect(); - int i = 600; // wait 60 seconds + int i = 600; // wait up 60 seconds before attaching sensors and button events while (i-- > 0 && !client.is_client_registered()) { wait_ms(100); } button.fall(eventQueue.event(&button_press)); + printf("Press the user button to increment the LwM2M resource value...\n"); #ifdef ENABLE_SENSORS // The timer fires on an interrupt context, but debounces it to the eventqueue, so it's safe to do network operations