Etherios Cloud Connector very first porting for mbed. Tested in an LPC1768

Etherios Cloud Connector for Embedded v2.1.0.3 library for mbed. Early porting.

This port is centered mainly in the platform code. So it should work properly with the provided examples of send_data, device_request, data_points, RCI and firmware_update (stub implementation, not a real one... yet ;-)). Filesystem is not implemented yet, and some examples might need changes.

To run, it needs the following libraries: - mbed - mbed-rtos - EthernetInterface

Find more information (and the source code!) about Etherios Cloud Connector for Embedded here: http://www.etherios.com/products/devicecloud/support/connector and in: http://www.etherios.com

Committer:
spastor
Date:
Tue Dec 03 13:34:02 2013 +0000
Revision:
0:1c358ea10753
Child:
1:908afea5a49d
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spastor 0:1c358ea10753 1 /*
spastor 0:1c358ea10753 2 * Copyright (c) 2013 Digi International Inc.,
spastor 0:1c358ea10753 3 * All rights not expressly granted are reserved.
spastor 0:1c358ea10753 4 *
spastor 0:1c358ea10753 5 * This Source Code Form is subject to the terms of the Mozilla Public
spastor 0:1c358ea10753 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
spastor 0:1c358ea10753 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
spastor 0:1c358ea10753 8 *
spastor 0:1c358ea10753 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
spastor 0:1c358ea10753 10 * =======================================================================
spastor 0:1c358ea10753 11 */
spastor 0:1c358ea10753 12
spastor 0:1c358ea10753 13 #include "mbed.h"
spastor 0:1c358ea10753 14 #include "EthernetInterface.h"
spastor 0:1c358ea10753 15 #include "Threads.h"
spastor 0:1c358ea10753 16 extern "C" {
spastor 0:1c358ea10753 17
spastor 0:1c358ea10753 18 #include "connector_api.h"
spastor 0:1c358ea10753 19 #include "ecc_platform.h"
spastor 0:1c358ea10753 20
spastor 0:1c358ea10753 21 }
spastor 0:1c358ea10753 22
spastor 0:1c358ea10753 23 static void connector_run_thread(void const * arg)
spastor 0:1c358ea10753 24 {
spastor 0:1c358ea10753 25
spastor 0:1c358ea10753 26 APP_DEBUG("connector_run thread starts\n");
spastor 0:1c358ea10753 27
spastor 0:1c358ea10753 28 for (;;)
spastor 0:1c358ea10753 29 {
spastor 0:1c358ea10753 30 connector_status_t const status = connector_run((void *)arg);
spastor 0:1c358ea10753 31
spastor 0:1c358ea10753 32 APP_DEBUG("connector_run returns %d\n", status);
spastor 0:1c358ea10753 33
spastor 0:1c358ea10753 34 if (status != connector_open_error) break;
spastor 0:1c358ea10753 35 }
spastor 0:1c358ea10753 36
spastor 0:1c358ea10753 37
spastor 0:1c358ea10753 38 APP_DEBUG("connector_run thread exits\n");
spastor 0:1c358ea10753 39
spastor 0:1c358ea10753 40 }
spastor 0:1c358ea10753 41
spastor 0:1c358ea10753 42 static void application_run_thread(void const * arg)
spastor 0:1c358ea10753 43 {
spastor 0:1c358ea10753 44 int status;
spastor 0:1c358ea10753 45
spastor 0:1c358ea10753 46 APP_DEBUG("application_run thread starts\n");
spastor 0:1c358ea10753 47
spastor 0:1c358ea10753 48 status = application_run((void *)arg);
spastor 0:1c358ea10753 49
spastor 0:1c358ea10753 50 APP_DEBUG("application_run thread exits %d\n", status);
spastor 0:1c358ea10753 51
spastor 0:1c358ea10753 52 }
spastor 0:1c358ea10753 53
spastor 0:1c358ea10753 54 int main (void)
spastor 0:1c358ea10753 55 {
spastor 0:1c358ea10753 56 EthernetInterface interface;
spastor 0:1c358ea10753 57
spastor 0:1c358ea10753 58 connector_handle_t connector_handle;
spastor 0:1c358ea10753 59
spastor 0:1c358ea10753 60 set_time(0);
spastor 0:1c358ea10753 61 printf("Starting Ethernet interface\n");
spastor 0:1c358ea10753 62
spastor 0:1c358ea10753 63 interface.init();
spastor 0:1c358ea10753 64 interface.connect();
spastor 0:1c358ea10753 65 printf("IP Address is %s\n\r", interface.getIPAddress());
spastor 0:1c358ea10753 66
spastor 0:1c358ea10753 67 APP_DEBUG("Start Cloud Connector for Embedded\n");
spastor 0:1c358ea10753 68 connector_handle = connector_init(app_connector_callback);
spastor 0:1c358ea10753 69
spastor 0:1c358ea10753 70 if (connector_handle != NULL)
spastor 0:1c358ea10753 71 {
spastor 0:1c358ea10753 72 ThreadList* my_threads=NULL; //List of all Initialized threads
spastor 0:1c358ea10753 73 ThreadList* connector_thread; //pointer to the last created ThreadList element
spastor 0:1c358ea10753 74 ThreadList* application_thread; //pointer to the last created ThreadList element
spastor 0:1c358ea10753 75
spastor 0:1c358ea10753 76 APP_DEBUG("Initiating CC thread\n");
spastor 0:1c358ea10753 77 if(initThread(&my_threads,connector_run_thread, &connector_thread,2)==0)
spastor 0:1c358ea10753 78 {
spastor 0:1c358ea10753 79 APP_DEBUG("Thread creation failed. \n");
spastor 0:1c358ea10753 80
spastor 0:1c358ea10753 81 }
spastor 0:1c358ea10753 82 else
spastor 0:1c358ea10753 83 {
spastor 0:1c358ea10753 84 //Start the thread and store the id
spastor 0:1c358ea10753 85 connector_thread->id=osThreadCreate(connector_thread->thread, connector_handle);
spastor 0:1c358ea10753 86 }
spastor 0:1c358ea10753 87 APP_DEBUG("Initiating application thread\n");
spastor 0:1c358ea10753 88 if(initThread(&my_threads,application_run_thread, &application_thread,2)==0)
spastor 0:1c358ea10753 89 {
spastor 0:1c358ea10753 90 APP_DEBUG("Thread creation failed. \n");
spastor 0:1c358ea10753 91
spastor 0:1c358ea10753 92 }
spastor 0:1c358ea10753 93 else
spastor 0:1c358ea10753 94 {
spastor 0:1c358ea10753 95 //Start the thread and store the id
spastor 0:1c358ea10753 96 application_thread->id=osThreadCreate(application_thread->thread, connector_handle);
spastor 0:1c358ea10753 97 }
spastor 0:1c358ea10753 98 }
spastor 0:1c358ea10753 99 else
spastor 0:1c358ea10753 100 {
spastor 0:1c358ea10753 101 APP_DEBUG("Unable to initialize the connector\n");
spastor 0:1c358ea10753 102 }
spastor 0:1c358ea10753 103
spastor 0:1c358ea10753 104 {
spastor 0:1c358ea10753 105 DigitalOut myled(LED1);
spastor 0:1c358ea10753 106 for(;;)
spastor 0:1c358ea10753 107 {
spastor 0:1c358ea10753 108 myled = 1;
spastor 0:1c358ea10753 109 wait(0.2);
spastor 0:1c358ea10753 110 myled = 0;
spastor 0:1c358ea10753 111 wait(0.2);
spastor 0:1c358ea10753 112 }
spastor 0:1c358ea10753 113 }
spastor 0:1c358ea10753 114
spastor 0:1c358ea10753 115 return 0;
spastor 0:1c358ea10753 116 }
spastor 0:1c358ea10753 117