ST
/
example-IDW01M1-mbed-Cloud-connect
Generic example for any board with IDMW0xM1 shield
Diff: main.cpp
- Revision:
- 18:04813dfab243
- Parent:
- 17:ada41201c642
- Child:
- 19:5dd1ec7fdf0d
--- a/main.cpp Tue Feb 20 14:25:34 2018 +0100 +++ b/main.cpp Tue Feb 20 15:09:08 2018 +0100 @@ -28,6 +28,7 @@ #include "SpwfSAInterface.h" #define LED_OFF 1 +#define LED_RED LED1 // betzw: `LED1` conflicts with SPI, mayber better use `NC` DigitalOut led(LED_RED, LED_OFF); InterruptIn button(BUTTON1); @@ -45,12 +46,15 @@ } void pattern_updated(const char *) { - printf("PUT received, new value: %s\n", pattern_ptr->get_value()); + printf("PUT received, new value: %s\n", pattern_ptr->get_value().c_str()); + // Placeholder for PUT action } void blink_callback(void *) { - const char *pattern = pattern_ptr->get_value(); - printf("LED pattern = %s\n", pattern); + String pattern_str = pattern_ptr->get_value(); + const char *pattern = pattern_str.c_str(); + printf("POST received. LED pattern = %s\n", pattern); + // Placeholder for POST action // The pattern is something like 500:200:500, so parse that. // LED blinking is done while parsing. led = !led; @@ -130,14 +134,17 @@ // EthernetInterface net; SpwfSAInterface wifi(MBED_CONF_APP_WIFI_TX, MBED_CONF_APP_WIFI_RX); +#if 0 // betzw SDBlockDevice sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS); FATFileSystem fs("sd"); +#endif printf("Start Simple Mbed Cloud Client\n"); // Initialize button interrupt button.fall(&button_press); +#if 0 // betzw // Initialize SD card int status = sd.init(); if (status != BD_ERROR_OK) { @@ -158,6 +165,9 @@ printf("Reformat and mount complete\r\n"); } } +#else + int status; +#endif printf("Connecting to the network using WiFi...\n"); @@ -188,25 +198,25 @@ button->set_value("0"); button->methods(M2MMethod::GET); button->observable(true); - button->attach_notification(M2MMethod::GET, (void*)button_notification_status_callback); + button->attach_notification_callback(button_notification_status_callback); MbedCloudClientResource *pattern = mbedClient.create_resource("3201/0/5853", "pattern_resource"); pattern->set_value("500:500:500:500"); pattern->methods(M2MMethod::GET | M2MMethod::PUT); - pattern->attach(M2MMethod::PUT, (void*)pattern_updated); + pattern->attach_put_callback(pattern_updated); pattern_ptr = pattern; MbedCloudClientResource *blink = mbedClient.create_resource("3201/0/5850", "blink_resource"); blink->methods(M2MMethod::POST); - blink->attach(M2MMethod::POST, (void*)blink_callback); + blink->attach_post_callback(blink_callback); MbedCloudClientResource *unregister = mbedClient.create_resource("5000/0/1", "unregister"); unregister->methods(M2MMethod::POST); - unregister->attach(M2MMethod::POST, (void*)unregister_cb); + unregister->attach_post_callback(unregister_cb); MbedCloudClientResource *factoryReset = mbedClient.create_resource("5000/0/2", "factory_reset"); factoryReset->methods(M2MMethod::POST); - factoryReset->attach(M2MMethod::POST, (void*)factory_reset_cb); + factoryReset->attach_post_callback(factory_reset_cb); mbedClient.register_and_connect();