Demo project for IoT World Hackathon

Dependencies:   Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork

Files at this revision

API Documentation at this revision

Comitter:
michaeljkoster
Date:
Tue May 12 00:51:01 2015 +0000
Commit message:
Initial Fork

Changed in this revision

Chainable_RGB_LED.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mbedConnectorInterface.lib Show annotated file Show diff for this revision Revisions of this file
mbedEndpointNetwork.lib Show annotated file Show diff for this revision Revisions of this file
mbedEndpointResources/LightResource.h Show annotated file Show diff for this revision Revisions of this file
mbedEndpointResources/OnBoardLED.h Show annotated file Show diff for this revision Revisions of this file
mbedEndpointResources/TempResource.h Show annotated file Show diff for this revision Revisions of this file
nsp_configuration.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a9025db1ac76 Chainable_RGB_LED.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Chainable_RGB_LED.lib	Tue May 12 00:51:01 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/seeed/code/Chainable_RGB_LED/#50d0a66599e1
diff -r 000000000000 -r a9025db1ac76 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 12 00:51:01 2015 +0000
@@ -0,0 +1,116 @@
+/**
+ * @file    main.cpp
+ * @brief   mbed Connected Home Endpoint main entry point
+ * @author  Doug Anson
+ * @version 1.0
+ * @see
+ *
+ * Copyright (c) 2014
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// mbed Connector Interface (configuration)
+#include "mbedConnectorInterface.h"
+
+// Ethernet Interface
+#include "EthernetInterface.h"
+EthernetInterface ethernet;
+
+// mbed Connector Endpoint includes
+#include "ConnectorEndpoint.h"
+#include "OptionsBuilder.h"
+
+// USB Serial port access for debugging/logging
+RawSerial pc(USBTX,USBRX);
+
+// Logging facility
+Logger logger(&pc);
+
+// Static Resources
+#include "StaticResource.h"
+StaticResource mfg(&logger,"3/0/0","Freescale");
+StaticResource model(&logger,"3/0/1","K64F mbed Ethernet demo");
+
+//
+// Dynamic Resource Note:
+//
+//  mbedConnectorInterface supports up to IPT_MAX_ENTRIES 
+//  (currently 5) independent dynamic resources.
+//
+//  You can increase this (at the cost of memory) 
+//  in mbedConnectorinterface.h
+//
+
+// Light Resource
+#include "LightResource.h"
+LightResource light(&logger,"3311/0/5706");
+
+// LED Resource
+#include "OnBoardLED.h"
+LEDResource led(&logger,"3311/1/5706");
+
+// Slide control Resource
+#include "TempResource.h"
+TempResource temp(&logger,"3303/0/5700", true); /* true if observable */
+
+// Set our own unique endpoint name
+#define MY_ENDPOINT_NAME                       "Changeme-LED-demo"
+
+// My NSP Domain
+#define MY_NSP_DOMAIN                          "domain1"                               
+
+// Customization Example: My custom NSP IPv4 or IPv6 address and NSP CoAP port 
+//uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {192,168,1,199}; /* local */
+//uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {54,191,98,247}; /* Dew Mobility EC2 Instance */
+//uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {108,201,184,41}; /* smartobjectservice.com */
+uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {104,210,36,5}; /* iot-hack-mds.cloudapp.net */
+int my_nsp_coap_port                          = 5683;
+
+// called from the Endpoint::start() below to create resources and the endpoint internals...
+Connector::Options *configure_endpoint(Connector::OptionsBuilder &config)
+{
+    // Build the endpoint configuration parameters
+    logger.log("configure_endpoint: building endpoint configuration...");
+    temp.setMaxAge(0); /* MaxAge = 0 to disable caching of the slide value in the Device Server */
+    return config.setEndpointNodename(MY_ENDPOINT_NAME)                   // custom endpoint name
+                 .setNSPAddress(my_nsp_address)                           // custom NSP address
+                 .setDomain(MY_NSP_DOMAIN)                                // custom NSP domain
+                 .setNSPPortNumber(my_nsp_coap_port)                      // custom NSP CoAP port
+                 
+                 // add the static resource representing this endpoint
+                 .addResource(&mfg)
+                 .addResource(&model)
+                                    
+                 // Add my specific physical dynamic resources...
+                 .addResource(&light)
+                 .addResource(&temp, 1000)
+                 .addResource(&led)
+                   
+                 // finalize the configuration...
+                 .build();
+}
+
+// main entry point...
+int main()
+{
+    // Announce
+    logger.log("\r\n\r\nmbed mDS Sample Endpoint v1.0 (Ethernet)");
+
+    // we have to plumb our network first
+    Connector::Endpoint::plumbNetwork();
+     
+    // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events...
+    logger.log("Start the endpoint to finish setup and enter the main loop...");
+    Connector::Endpoint::start();
+}
diff -r 000000000000 -r a9025db1ac76 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue May 12 00:51:01 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889
\ No newline at end of file
diff -r 000000000000 -r a9025db1ac76 mbedConnectorInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbedConnectorInterface.lib	Tue May 12 00:51:01 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/ansond/code/mbedConnectorInterface/#aaf84e56c422
diff -r 000000000000 -r a9025db1ac76 mbedEndpointNetwork.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbedEndpointNetwork.lib	Tue May 12 00:51:01 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/ansond/code/mbedEndpointNetwork/#4beaffb6468f
diff -r 000000000000 -r a9025db1ac76 mbedEndpointResources/LightResource.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbedEndpointResources/LightResource.h	Tue May 12 00:51:01 2015 +0000
@@ -0,0 +1,91 @@
+/**
+ * @file    LightResource.h
+ * @brief   mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
+ * @author  Doug Anson, Michael Koster
+ * @version 1.0
+ * @see
+ *
+ * Copyright (c) 2014
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LIGHT_RESOURCE_H__
+#define __LIGHT_RESOURCE_H__
+
+
+// Base class
+#include "DynamicResource.h"
+
+// our Light
+#include "ChainableLED.h"
+#define LED_COUNT 1
+
+ChainableLED led_chain(D3, D4, LED_COUNT);
+
+static char * led_value = {"00000"}; //RRGGBB
+
+void set_led_array(char * color_string)
+{
+    int color_int;
+
+    sscanf(color_string, "%X", &color_int);
+    
+    led_chain.setColorRGB(0, (color_int >> 16 & 255), (color_int >> 8 & 255), (color_int & 255) );    
+}
+
+/** LightResource class
+ */
+class LightResource : public DynamicResource
+{
+
+public:
+    /**
+    Default constructor
+    @param logger input logger instance for this resource
+    @param name input the Light resource name
+    @param observable input the resource is Observable (default: FALSE)
+    */
+    LightResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Light",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) {
+    set_led_array("000000");
+    wait(0.5);
+    set_led_array("FF0000");
+    wait(0.5);
+    set_led_array("00FF00");
+    wait(0.5);
+    set_led_array("0000FF");
+    wait(0.5);
+    set_led_array(led_value);
+    }
+
+    /**
+    Get the value of the Light
+    @returns string containing either "0" (light off) or "1" (light on)
+    */
+    virtual string get() {
+        return(led_value);
+    }
+
+    /**
+    Set the value of the Light
+    @param string input the string containing "0" (light off) or "1" (light on)
+    */
+    virtual void put(const string value) {
+        if( sizeof(value) == sizeof(led_value) ){
+            led_value = (char *)value.c_str();
+            set_led_array(led_value);
+        }
+    }
+};
+
+#endif // __LIGHT_RESOURCE_H__
diff -r 000000000000 -r a9025db1ac76 mbedEndpointResources/OnBoardLED.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbedEndpointResources/OnBoardLED.h	Tue May 12 00:51:01 2015 +0000
@@ -0,0 +1,97 @@
+/**
+ * @file    LightResource.h
+ * @brief   mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
+ * @author  Doug Anson, Michael Koster
+ * @version 1.0
+ * @see
+ *
+ * Copyright (c) 2014
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LED_RESOURCE_H__
+#define __LED_RESOURCE_H__
+
+
+// Base class
+#include "DynamicResource.h"
+
+// our Light
+DigitalOut LED_red(LED1);
+DigitalOut LED_green(LED2);
+DigitalOut LED_blue(LED3);
+
+static char * LED_color_value = {"00000"}; //RRGGBBII
+
+void LED_set_color(char * color_string)
+{
+    static uint8_t red, green, blue;
+    int color_int;
+
+    sscanf(color_string, "%X", &color_int);
+    
+    blue = color_int & 255;
+    green = color_int >> 8 & 255;
+    red = color_int >> 16 & 255;
+        
+    LED_red = !(red & 1);    
+    LED_green = !(green & 1);    
+    LED_blue = !(blue & 1);    
+}
+
+/** LightResource class
+ */
+class LEDResource : public DynamicResource
+{
+
+public:
+    /**
+    Default constructor
+    @param logger input logger instance for this resource
+    @param name input the Light resource name
+    @param observable input the resource is Observable (default: FALSE)
+    */
+    LEDResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"OnBoardLED",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) {
+    LED_set_color("000000");
+    wait(0.5);
+    LED_set_color("FF0000");
+    wait(0.5);
+    LED_set_color("00FF00");
+    wait(0.5);
+    LED_set_color("0000FF");
+    wait(0.5);
+    LED_set_color(LED_color_value);
+    }
+
+    /**
+    Get the value of the LED
+    @returns string containing the last setting
+    */
+    virtual string get() {
+        return(LED_color_value);
+    }
+
+    /**
+    Set the value of the LED
+    @param string input the string containing the desired setting
+    */
+    virtual void put(const string value) {
+        if( sizeof(value) == sizeof(LED_color_value) ){
+            LED_color_value = (char *)value.c_str();
+            LED_set_color(LED_color_value);
+        }
+    }
+};
+
+#endif // __LED_RESOURCE_H__
diff -r 000000000000 -r a9025db1ac76 mbedEndpointResources/TempResource.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbedEndpointResources/TempResource.h	Tue May 12 00:51:01 2015 +0000
@@ -0,0 +1,64 @@
+/**
+ * @file    TempResource.h
+ * @brief   mbed CoAP Endpoint
+ * @author  Michael Koster
+ * @version 1.0
+ * @see
+ *
+ * Copyright (c) 2015
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TEMP_RESOURCE_H__
+#define __TEMP_RESOURCE_H__
+
+// Base class
+#include "DynamicResource.h"
+
+// Temp Sensor connected to A0
+AnalogIn temp_in(A0);
+
+/** TempResource class
+ */
+class TempResource : public DynamicResource
+{
+public:
+    /**
+    Default constructor
+    @param logger input logger instance for this resource
+    @param name input the resource name
+    @param observable input the resource is Observable (default: FALSE)
+    */
+    TempResource(const Logger *logger,const char *name,const bool observable = false) : 
+        DynamicResource(logger,name,"Temperature", SN_GRS_GET_ALLOWED,observable) {
+    }
+
+    /**
+    Get the value of the Temperature Sensor
+    @returns string containing the temperature value in Fahrenheit
+    */
+    virtual string get() {
+        char temp_str[8];
+        int B = 3975;
+        memset(temp_str,0,8);
+        float temp_read = temp_in.read();
+        float resistance = (1-temp_read) * 10000/temp_read; //get the resistance of the sensor;
+        float temp_c = 1/( logf(resistance/10000)/B + 1/298.15 ) - 273.15;//convert to temperature via datasheet ;
+        float temp_f = (1.8 * (double) temp_c) + 32;
+        sprintf(temp_str,"%8.2f", temp_f);
+        return string(temp_str);
+    }
+};
+
+#endif // __TEMP_RESOURCE_H__
diff -r 000000000000 -r a9025db1ac76 nsp_configuration.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nsp_configuration.h	Tue May 12 00:51:01 2015 +0000
@@ -0,0 +1,42 @@
+/**
+ * @file    nsp_configuration.h
+ * @brief   mbed Connector Interface NSP configuration header
+ * @author  Doug Anson
+ * @version 1.0
+ * @see
+ *
+ * Copyright (c) 2014
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+ #ifndef __NSP_CONFIGURATION_H__
+ #define __NSP_CONFIGURATION_H__
+ 
+ // NSP node name
+ #define NODE_NAME_LENGTH         24
+ #define NODE_NAME                "mbed-eth-endpoint"
+ 
+ // NSP Address (4 bytes for IPV4, 16 bytes for IPV6)
+ #define NSP_IP_ADDRESS_LENGTH    4
+ #define NSP_IP_ADDRESS           {192,168,1,199}
+ 
+ // NSP Endpoint Type specification
+ #define NSP_ENDPOINT_TYPE_LENGTH 24
+ #define NSP_ENDPOINT_TYPE        "mbed-eth-device"
+ 
+ // NSP Domain used
+ #define NSP_DOMAIN_LENGTH        24
+ #define NSP_DOMAIN               "domain"
+
+ #endif // __NSP_CONFIGURATION_H__
\ No newline at end of file