pelion-example-common
Dependencies: ublox-at-cellular-interface ublox-cellular-base
Revision 3:3b2db67b206e, committed 2018-12-16
- Comitter:
- screamer
- Date:
- Sun Dec 16 15:03:49 2018 +0000
- Parent:
- 2:18e78518ee6f
- Child:
- 4:dc1c3cb4d143
- Commit message:
- Updated main application for pin names and inline documentation
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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