Christos Vasilakis
/
pelion-example-common-DISCO_F413ZH
pelion-example-common-DISCO_F413ZH
Diff: main.cpp
- Revision:
- 7:24d524c2bdcc
- Parent:
- 5:766c011942b4
- Child:
- 8:579904ba4ba1
--- a/main.cpp Sun Dec 16 11:58:40 2018 +0000 +++ b/main.cpp Sun Dec 16 12:02:30 2018 +0000 @@ -29,18 +29,24 @@ // Default network interface object 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 // Default User button for GET example InterruptIn button(BUTTON1); // Default LED to use for PUT/POST example DigitalOut led(LED1); -// Default temperature reading from microcontroller +// Temperature reading from microcontroller AnalogIn adc_temp(ADC_TEMP); -// Voltage reference from microcontroller +// Voltage reference reading from microcontroller AnalogIn adc_vref(ADC_VREF); #define SENSORS_POLL_INTERVAL 1.0 @@ -99,7 +105,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; } @@ -122,14 +128,19 @@ printf("Starting Simple Pelion Device Management Client example\n"); // If the User button is pressed ons start, then format storage. + DigitalIn *user_button = new DigitalIn(BUTTON1); +#if TARGET_DISCO_L475VG_IOT01A + // The user button on DISCO_L475VG_IOT01A works the other way around + const int PRESSED = 0; +#else const int PRESSED = 1; - DigitalIn *user_button = new DigitalIn(BUTTON1); +#endif 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"); } @@ -161,6 +172,8 @@ printf("Connected to the network successfully. IP address: %s\n", net->get_ip_address()); + printf("Initializing Pelion Device Management Client..."); + // SimpleMbedCloudClient handles registering over LwM2M to Pelion DM SimpleMbedCloudClient client(net, bd, &fs); int client_status = client.init(); @@ -200,7 +213,7 @@ // 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); }