mbed Ethernet-based CoAP heartrate endpoint for Dreamforce 2015
Dependencies: GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork
main.cpp
00001 /** 00002 * @file main.cpp 00003 * @brief mbed Connected Home Endpoint main entry point 00004 * @author Doug Anson 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2014 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 // mbed Connector Interface (configuration) 00024 #include "mbedConnectorInterface.h" 00025 00026 // mbed Network Endpoint 00027 #include "mbedEndpointNetwork.h" 00028 00029 // Static Resources 00030 #include "StaticResource.h" 00031 StaticResource mfg(&logger,"dev/mfg","Freescale"); 00032 StaticResource model(&logger,"dev/mdl","K64F"); 00033 00034 // Heartrate Resource 00035 #include "HeartrateResource.h" 00036 HeartrateResource hr(&logger,"888/0/5850",true); // observable 00037 00038 // Location Resource 00039 #include "LocationResource.h" 00040 LocationResource location(&logger,"999/0/1234",true); // observable 00041 00042 // LED Light Resource 00043 #include "LightResource.h" 00044 LightResource light(&logger,"311/0/5850"); 00045 00046 // My Endpoint Name 00047 #define MY_ENDPOINT_NAME "mbed-eth-hrm-X" // replace "XX" with your number 00048 00049 // My NSP Domain 00050 #define MY_NSP_DOMAIN "dfbridgeXX" // replace "XX" with your number 00051 00052 // Customization Example: My custom NSP IPv4 address and NSP CoAP port 00053 uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {129,41,134,116}; // bluemix vm v2.3 00054 int my_nsp_coap_port = 5683; 00055 00056 // called from the Endpoint::start() below to create resources and the endpoint internals... 00057 Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) 00058 { 00059 // Build the endpoint configuration parameters 00060 logger.log("configure_endpoint: building endpoint configuration..."); 00061 return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name 00062 .setNSPAddress(my_nsp_address) // custom NSP address 00063 .setDomain(MY_NSP_DOMAIN) // custom NSP domain 00064 .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port 00065 00066 // enable or disable(default) immediate observationing control 00067 .setImmedateObservationEnabled(true) 00068 00069 // enable or disable(default) GET-based observation control 00070 .setEnableGETObservationControl(false) 00071 00072 // add the static resource representing this endpoint 00073 .addResource(&mfg) 00074 .addResource(&model) 00075 00076 // add the heartrate resource 00077 .addResource(&light) 00078 .addResource(&hr,4765) // observe every 4.765 seconds 00079 .addResource(&location,11316) // observe every 11.316 seconds (its currently static...) 00080 00081 // finalize the configuration... 00082 .build(); 00083 } 00084 00085 // main entry point... 00086 int main() 00087 { 00088 // Announce 00089 logger.log("\r\n\r\nmbed mDS Ethernet Heartrate Endpoint"); 00090 00091 // we have to plumb our network first 00092 Connector::Endpoint::plumbNetwork(); 00093 00094 // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events... 00095 logger.log("Start the endpoint to finish setup and enter the main loop..."); 00096 Connector::Endpoint::start(); 00097 }
Generated on Thu Jul 14 2022 21:41:08 by 1.7.2