Starter project for class and hackathon
Dependencies: Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork
Revision 0:a7458d25d9c9, committed 2015-04-16
- Comitter:
- michaeljkoster
- Date:
- Thu Apr 16 13:56:23 2015 +0000
- Commit message:
- Demo for class and hackathon
Changed in this revision
diff -r 000000000000 -r a7458d25d9c9 Chainable_RGB_LED.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Chainable_RGB_LED.lib Thu Apr 16 13:56:23 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/seeed/code/Chainable_RGB_LED/#24631ceaa38a
diff -r 000000000000 -r a7458d25d9c9 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Apr 16 13:56:23 2015 +0000 @@ -0,0 +1,114 @@ +/** + * @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 "SliderResource.h" +SliderResource slider(&logger,"3202/0/5600", true); /* true if observable */ + +// Set our own unique endpoint name +#define MY_ENDPOINT_NAME "Changeme-LED-demo" + +// My NSP Domain +#define MY_NSP_DOMAIN "domain2" + +// 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] = {108,201,184,41}; /* smartobjectservice.com */ +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..."); + slider.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(&slider, 10000) + .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 a7458d25d9c9 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Apr 16 13:56:23 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0 \ No newline at end of file
diff -r 000000000000 -r a7458d25d9c9 mbedConnectorInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbedConnectorInterface.lib Thu Apr 16 13:56:23 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/ansond/code/mbedConnectorInterface/#aaf84e56c422
diff -r 000000000000 -r a7458d25d9c9 mbedEndpointNetwork.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbedEndpointNetwork.lib Thu Apr 16 13:56:23 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/ansond/code/mbedEndpointNetwork/#3bec96f0e572
diff -r 000000000000 -r a7458d25d9c9 mbedEndpointResources/LightResource.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbedEndpointResources/LightResource.h Thu Apr 16 13:56:23 2015 +0000 @@ -0,0 +1,104 @@ +/** + * @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(D4, D5, LED_COUNT); + +static char * led_value = {"0000000"}; //RRGGBBII + +void set_led_array(char * color_string) +{ + static uint8_t red, green, blue, index; + int color_int; + + sscanf(color_string, "%X", &color_int); + + index = color_int & 255; + blue = color_int >> 8 & 255; + green = color_int >> 16 & 255; + red = color_int >> 24 & 255; + + if(index > 0 and index <= LED_COUNT) { + led_chain.setColorRGB(index-1, red, green, blue); + } + else if(index == 0){ + for(int i = 0; i < LED_COUNT; i++){ + led_chain.setColorRGB(i, red, green, blue); + } + } +} + +/** 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("00000000"); + wait(0.5); + set_led_array("FF000000"); + wait(0.5); + set_led_array("00FF0000"); + wait(0.5); + set_led_array("0000FF00"); + 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 a7458d25d9c9 mbedEndpointResources/OnBoardLED.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbedEndpointResources/OnBoardLED.h Thu Apr 16 13:56:23 2015 +0000 @@ -0,0 +1,100 @@ +/** + * @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 = {"0000000"}; //RRGGBBII + +void LED_set_color(char * color_string) +{ + static uint8_t red, green, blue, index; + int color_int; + + sscanf(color_string, "%X", &color_int); + + index = color_int & 255; + blue = color_int >> 8 & 255; + green = color_int >> 16 & 255; + red = color_int >> 24 & 255; + + if(index == 0) { + 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("00000000"); + wait(0.5); + LED_set_color("FF000000"); + wait(0.5); + LED_set_color("00FF0000"); + wait(0.5); + LED_set_color("0000FF00"); + 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 a7458d25d9c9 mbedEndpointResources/SliderResource.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbedEndpointResources/SliderResource.h Thu Apr 16 13:56:23 2015 +0000 @@ -0,0 +1,58 @@ +/** + * @file SliderResource.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 __SLIDER_RESOURCE_H__ +#define __SLIDER_RESOURCE_H__ + +// Base class +#include "DynamicResource.h" + +// Slide Potentiometer connected to A0 +AnalogIn slider_in(A0); + +/** TemperatureResource class + */ +class SliderResource : 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) + */ + SliderResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Slider", SN_GRS_GET_ALLOWED,observable) { + } + + /** + Get the value of the slide potentiometer + @returns string containing the slider value from 0-1.00 + */ + virtual string get() { + char slider_pos[7]; + memset(slider_pos,0,7); + sprintf(slider_pos,"%3.2f", slider_in.read()); + return string(slider_pos); + } +}; + +#endif // __SLIDER_RESOURCE_H__
diff -r 000000000000 -r a7458d25d9c9 nsp_configuration.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nsp_configuration.h Thu Apr 16 13:56:23 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