Dreamforce 2015 BLE-based mDS HeartRate Monitor Endpoint
Dependencies: GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork_BLE
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","Nordic Semi"); 00032 StaticResource model(&logger,"dev/mdl","nRF51822"); 00033 00034 // Heartrate Resource 00035 #include "HeartrateResource.h" 00036 HeartrateResource hr(&logger,"888/0/5850",true); // observable 00037 00038 // Enable BLE-based Location 00039 #define ENABLE_BLE_LOCATION false // true - enable BLELocation from Proxy (experimental!!). false - use default location below 00040 00041 // Location Resource 00042 #include "LocationResource.h" 00043 LocationResource location(&logger,"999/0/1234",true); // observable 00044 00045 // LED Light Resource 00046 #include "LightResource.h" 00047 LightResource light(&logger,"311/0/5850"); 00048 00049 // My Endpoint Name 00050 #define MY_ENDPOINT_NAME "mbed-ble-hrm-XX" // replace "XX" with your number 00051 00052 // My NSP Domain 00053 #define MY_NSP_DOMAIN "dfbridgeXX" // replace "XX" with your number 00054 00055 // Customization Example: My custom NSP IPv4 address and NSP CoAP port 00056 uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {129,41,134,116}; // bluemix vm v2.3 00057 int my_nsp_coap_port = 5683; 00058 00059 // called from the Endpoint::start() below to create resources and the endpoint internals... 00060 Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) 00061 { 00062 // Build the endpoint configuration parameters 00063 logger.log("configure_endpoint: building endpoint configuration..."); 00064 return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name 00065 .setNSPAddress(my_nsp_address) // custom NSP address 00066 .setDomain(MY_NSP_DOMAIN) // custom NSP domain 00067 .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port 00068 00069 // enable or disable(default) immediate observationing control 00070 .setImmedateObservationEnabled(true) 00071 00072 // enable or disable(default) GET-based observation control 00073 .setEnableGETObservationControl(false) 00074 00075 // add the static resource representing this endpoint 00076 .addResource(&mfg) 00077 .addResource(&model) 00078 00079 // add the heartrate resource 00080 .addResource(&light) 00081 .addResource(&hr) // Resource implements its own observationing... 00082 .addResource(&location,13245) // observe every 13.245 seconds 00083 00084 // finalize the configuration... 00085 .build(); 00086 } 00087 00088 // main entry point... 00089 int main() 00090 { 00091 // Announce 00092 logger.log("\r\n\r\nmbed mDS BLE Heartrate Endpoint"); 00093 00094 // we have to plumb our network first 00095 Connector::Endpoint::plumbNetwork(); 00096 00097 // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events... 00098 logger.log("Start the endpoint to finish setup and enter the main loop..."); 00099 Connector::Endpoint::start(); 00100 }
Generated on Thu Jul 21 2022 02:55:03 by 1.7.2