Simple Mbed Cloud Client application using features of K64 & K66
Connect to Mbed Cloud!
This example was customized a bit for FRDM-K66 and FRDM-K64F.
It depends on having an SD Card plugged in for storage of credentials. It could be changed later to use a SPI flash or other storage on a shield or wired in.
The app keeps track of how many times switch 2 (SW2) is pressed. The value can be retrieved via a GET request to Mbed Cloud.
Also, it will blink a pattern based on milisecond (ms) timing values that can be sent from Mbed Cloud. The pattern can be sent with a PUT request and the blinking sequence can be triggered by a POST request.
Diff: main.cpp
- Revision:
- 13:49062a0d117e
- Parent:
- 9:ae1f6fe932dc
diff -r 0a894bf1f5f2 -r 49062a0d117e main.cpp
--- a/main.cpp Fri May 18 21:28:25 2018 +0000
+++ b/main.cpp Fri Oct 05 13:11:30 2018 -0500
@@ -18,22 +18,22 @@
#include "mbed.h"
#include "simple-mbed-cloud-client.h"
-#include "SDBlockDevice.h"
#include "FATFileSystem.h"
-#include "EthernetInterface.h"
// An event queue is a very useful structure to debounce information between contexts (e.g. ISR and normal threads)
// 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;
Thread thread1;
-// Storage implementation definition, currently using SDBlockDevice (SPI flash, DataFlash, and internal flash are also available)
-/* K64 & K66 */
+// Default block device
+BlockDevice* bd = BlockDevice::get_default_instance();
+FATFileSystem fs("sd", bd);
+
+// Default network interface object
+NetworkInterface *net;
+
InterruptIn sw2(SW2);
DigitalOut led2(LED2);
-/* K64 & K66 */
-SDBlockDevice sd(PTE3, PTE1, PTE2, PTE4);
-FATFileSystem fs("sd", &sd);
// Declaring pointers for access to Mbed Cloud Client resources outside of main()
MbedCloudClientResource *button_res;
@@ -109,18 +109,19 @@
printf("Connecting to the network using Ethernet...\n");
// Connect to the internet (DHCP is expected to be on)
- EthernetInterface net;
- nsapi_error_t status = net.connect();
+ net = NetworkInterface::get_default_instance();
- if (status != 0) {
+ nsapi_error_t status = net->connect();
+
+ if (status != NSAPI_ERROR_OK) {
printf("Connecting to the network failed %d!\n", status);
return -1;
}
- printf("Connected to the network successfully. IP address: %s\n", net.get_ip_address());
+ printf("Connected to the network successfully. IP address: %s\n", net->get_ip_address());
// SimpleMbedCloudClient handles registering over LwM2M to Mbed Cloud
- SimpleMbedCloudClient client(&net, &sd, &fs);
+ SimpleMbedCloudClient client(net, bd, &fs);
int client_status = client.init();
if (client_status != 0) {
printf("Initializing Mbed Cloud Client failed (%d)\n", client_status);