Dreamforce 2015 BLE-based mDS HeartRate Monitor Endpoint
Dependencies: GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork_BLE
main.cpp@53:d22af3b91e4c, 2015-09-07 (annotated)
- Committer:
- ansond
- Date:
- Mon Sep 07 04:52:10 2015 +0000
- Revision:
- 53:d22af3b91e4c
- Parent:
- 52:bd3177c6d7fd
updates and tweaks for static location option and android 5.x
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:6b414fe5f8db | 1 | /** |
ansond | 0:6b414fe5f8db | 2 | * @file main.cpp |
ansond | 0:6b414fe5f8db | 3 | * @brief mbed Connected Home Endpoint main entry point |
ansond | 0:6b414fe5f8db | 4 | * @author Doug Anson |
ansond | 0:6b414fe5f8db | 5 | * @version 1.0 |
ansond | 0:6b414fe5f8db | 6 | * @see |
ansond | 0:6b414fe5f8db | 7 | * |
ansond | 0:6b414fe5f8db | 8 | * Copyright (c) 2014 |
ansond | 0:6b414fe5f8db | 9 | * |
ansond | 0:6b414fe5f8db | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 0:6b414fe5f8db | 11 | * you may not use this file except in compliance with the License. |
ansond | 0:6b414fe5f8db | 12 | * You may obtain a copy of the License at |
ansond | 0:6b414fe5f8db | 13 | * |
ansond | 0:6b414fe5f8db | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 0:6b414fe5f8db | 15 | * |
ansond | 0:6b414fe5f8db | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 0:6b414fe5f8db | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 0:6b414fe5f8db | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 0:6b414fe5f8db | 19 | * See the License for the specific language governing permissions and |
ansond | 0:6b414fe5f8db | 20 | * limitations under the License. |
ansond | 0:6b414fe5f8db | 21 | */ |
ansond | 0:6b414fe5f8db | 22 | |
ansond | 0:6b414fe5f8db | 23 | // mbed Connector Interface (configuration) |
ansond | 0:6b414fe5f8db | 24 | #include "mbedConnectorInterface.h" |
ansond | 0:6b414fe5f8db | 25 | |
ansond | 43:0c80682b673d | 26 | // mbed Network Endpoint |
ansond | 43:0c80682b673d | 27 | #include "mbedEndpointNetwork.h" |
ansond | 0:6b414fe5f8db | 28 | |
ansond | 0:6b414fe5f8db | 29 | // Static Resources |
ansond | 0:6b414fe5f8db | 30 | #include "StaticResource.h" |
ansond | 0:6b414fe5f8db | 31 | StaticResource mfg(&logger,"dev/mfg","Nordic Semi"); |
ansond | 47:5e57fdac6765 | 32 | StaticResource model(&logger,"dev/mdl","nRF51822"); |
ansond | 0:6b414fe5f8db | 33 | |
ansond | 0:6b414fe5f8db | 34 | // Heartrate Resource |
ansond | 0:6b414fe5f8db | 35 | #include "HeartrateResource.h" |
ansond | 53:d22af3b91e4c | 36 | HeartrateResource hr(&logger,"888/0/5850",true); // observable |
ansond | 53:d22af3b91e4c | 37 | |
ansond | 53:d22af3b91e4c | 38 | // Enable BLE-based Location |
ansond | 53:d22af3b91e4c | 39 | #define ENABLE_BLE_LOCATION false // true - enable BLELocation from Proxy (experimental!!). false - use default location below |
ansond | 0:6b414fe5f8db | 40 | |
ansond | 42:9741365cff35 | 41 | // Location Resource |
ansond | 42:9741365cff35 | 42 | #include "LocationResource.h" |
ansond | 42:9741365cff35 | 43 | LocationResource location(&logger,"999/0/1234",true); // observable |
ansond | 42:9741365cff35 | 44 | |
ansond | 47:5e57fdac6765 | 45 | // LED Light Resource |
ansond | 45:425c86379f12 | 46 | #include "LightResource.h" |
ansond | 45:425c86379f12 | 47 | LightResource light(&logger,"311/0/5850"); |
ansond | 45:425c86379f12 | 48 | |
ansond | 47:5e57fdac6765 | 49 | // My Endpoint Name |
ansond | 52:bd3177c6d7fd | 50 | #define MY_ENDPOINT_NAME "mbed-ble-hrm-XX" // replace "XX" with your number |
ansond | 47:5e57fdac6765 | 51 | |
ansond | 0:6b414fe5f8db | 52 | // My NSP Domain |
ansond | 51:a75eb7caf855 | 53 | #define MY_NSP_DOMAIN "dfbridgeXX" // replace "XX" with your number |
ansond | 0:6b414fe5f8db | 54 | |
ansond | 37:55a66b48199a | 55 | // Customization Example: My custom NSP IPv4 address and NSP CoAP port |
ansond | 49:1588c1faba50 | 56 | uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {129,41,134,116}; // bluemix vm v2.3 |
ansond | 35:4adef21fd8b6 | 57 | int my_nsp_coap_port = 5683; |
ansond | 0:6b414fe5f8db | 58 | |
ansond | 0:6b414fe5f8db | 59 | // called from the Endpoint::start() below to create resources and the endpoint internals... |
ansond | 0:6b414fe5f8db | 60 | Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) |
ansond | 0:6b414fe5f8db | 61 | { |
ansond | 0:6b414fe5f8db | 62 | // Build the endpoint configuration parameters |
ansond | 0:6b414fe5f8db | 63 | logger.log("configure_endpoint: building endpoint configuration..."); |
ansond | 0:6b414fe5f8db | 64 | return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name |
ansond | 0:6b414fe5f8db | 65 | .setNSPAddress(my_nsp_address) // custom NSP address |
ansond | 0:6b414fe5f8db | 66 | .setDomain(MY_NSP_DOMAIN) // custom NSP domain |
ansond | 0:6b414fe5f8db | 67 | .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port |
ansond | 0:6b414fe5f8db | 68 | |
ansond | 35:4adef21fd8b6 | 69 | // enable or disable(default) immediate observationing control |
ansond | 35:4adef21fd8b6 | 70 | .setImmedateObservationEnabled(true) |
ansond | 35:4adef21fd8b6 | 71 | |
ansond | 35:4adef21fd8b6 | 72 | // enable or disable(default) GET-based observation control |
ansond | 35:4adef21fd8b6 | 73 | .setEnableGETObservationControl(false) |
ansond | 35:4adef21fd8b6 | 74 | |
ansond | 0:6b414fe5f8db | 75 | // add the static resource representing this endpoint |
ansond | 0:6b414fe5f8db | 76 | .addResource(&mfg) |
ansond | 0:6b414fe5f8db | 77 | .addResource(&model) |
ansond | 0:6b414fe5f8db | 78 | |
ansond | 0:6b414fe5f8db | 79 | // add the heartrate resource |
ansond | 45:425c86379f12 | 80 | .addResource(&light) |
ansond | 53:d22af3b91e4c | 81 | .addResource(&hr) // Resource implements its own observationing... |
ansond | 53:d22af3b91e4c | 82 | .addResource(&location,13245) // observe every 13.245 seconds |
ansond | 0:6b414fe5f8db | 83 | |
ansond | 0:6b414fe5f8db | 84 | // finalize the configuration... |
ansond | 0:6b414fe5f8db | 85 | .build(); |
ansond | 0:6b414fe5f8db | 86 | } |
ansond | 0:6b414fe5f8db | 87 | |
ansond | 0:6b414fe5f8db | 88 | // main entry point... |
ansond | 0:6b414fe5f8db | 89 | int main() |
ansond | 0:6b414fe5f8db | 90 | { |
ansond | 0:6b414fe5f8db | 91 | // Announce |
ansond | 0:6b414fe5f8db | 92 | logger.log("\r\n\r\nmbed mDS BLE Heartrate Endpoint"); |
ansond | 53:d22af3b91e4c | 93 | |
ansond | 0:6b414fe5f8db | 94 | // we have to plumb our network first |
ansond | 0:6b414fe5f8db | 95 | Connector::Endpoint::plumbNetwork(); |
ansond | 0:6b414fe5f8db | 96 | |
ansond | 0:6b414fe5f8db | 97 | // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events... |
ansond | 0:6b414fe5f8db | 98 | logger.log("Start the endpoint to finish setup and enter the main loop..."); |
ansond | 0:6b414fe5f8db | 99 | Connector::Endpoint::start(); |
ansond | 5:4609a86755be | 100 | } |