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)
Revision 1:a50c1e691ff1, committed 2018-12-11
- Comitter:
- screamer
- Date:
- Tue Dec 11 00:39:31 2018 +0000
- Parent:
- 0:a076a1bbe630
- Child:
- 2:18e78518ee6f
- Commit message:
- Hide sensors under ENABLE_SENSORS macro until the underlying ST target reiceves ADC temp and vref pin descriptions
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Dec 10 21:58:43 2018 +0000 +++ b/main.cpp Tue Dec 11 00:39:31 2018 +0000 @@ -35,21 +35,26 @@ LittleFileSystem fs("fs", &sd); // Default User button for GET example -InterruptIn button(USER_BUTTON); +InterruptIn button(BUTTON1); // Default LED to use for PUT/POST example DigitalOut led(LED1); + +#ifdef ENABLE_SENSORS // Default temperature reading from microcontroller AnalogIn adc_temp(ADC_TEMP); // Voltage reference from microcontroller AnalogIn adc_vref(ADC_VREF); #define SENSORS_POLL_INTERVAL 1.0 +#endif /* ENABLE_SENSORS */ // Declaring pointers for access to Pelion Client resources outside of main() MbedCloudClientResource *res_button; MbedCloudClientResource *res_led; +#ifdef ENABLE_SENSORS MbedCloudClientResource *res_temperature; MbedCloudClientResource *res_voltage; +#endif /* ENABLE_SENSORS */ // When the device is registered, this variable will be used to access various useful information, like device ID etc. static const ConnectorClientEndpointInfo* endpointInfo; @@ -107,6 +112,7 @@ * Update sensors and report their values. * This function is called periodically. */ +#ifdef ENABLE_SENSORS void sensors_update() { float temp = adc_temp.read()*100; float vref = adc_vref.read(); @@ -116,6 +122,7 @@ res_voltage->set_value(vref); } } +#endif /* ENABLE_SENSORS */ int main(void) { @@ -123,7 +130,7 @@ // If the User button is pressed ons start, then format storage. const int PRESSED = 1; - DigitalIn *user_button = new DigitalIn(USER_BUTTON); + 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); @@ -181,6 +188,7 @@ res_led->methods(M2MMethod::GET | M2MMethod::PUT); res_led->attach_put_callback(led_put_callback); +#ifdef ENABLE_SENSORS // Sensor resources res_temperature = client.create_resource("3303/0/5700", "temperature"); res_temperature->set_value(0); @@ -191,6 +199,7 @@ res_voltage->set_value(0); res_voltage->methods(M2MMethod::GET); res_voltage->observable(true); +#endif /* ENABLE_SENSORS */ printf("Initialized Pelion Client. Registering...\n"); @@ -207,9 +216,11 @@ button.fall(eventQueue.event(&button_press)); +#ifdef ENABLE_SENSORS // The timer fires on an interrupt context, but debounces it to the eventqueue, so it's safe to do network operations Ticker timer; timer.attach(eventQueue.event(&sensors_update), SENSORS_POLL_INTERVAL); +#endif /* ENABLE_SENSORS */ // You can easily run the eventQueue in a separate thread if required eventQueue.dispatch_forever();