Dreamforce 2015 BLE-based mDS HeartRate Monitor Endpoint

Dependencies:   GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork_BLE

Committer:
ansond
Date:
Mon Jul 27 03:05:35 2015 +0000
Revision:
44:6171d54fed45
Parent:
43:0c80682b673d
Child:
45:425c86379f12
updates

Who changed what in which revision?

UserRevisionLine numberNew 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 37:55a66b48199a 29 // Only Nordic boards are supported...
ansond 5:4609a86755be 30 #ifdef TARGET_NRF51_DK
ansond 5:4609a86755be 31 #define NORDIC_MODEL "nRF51822-DK"
ansond 39:45355870bead 32 #define MY_ENDPOINT_NAME "mbed-ble-hrm-dk"
ansond 38:80c070ecdb64 33 #define NORDIC_SDA SDA
ansond 38:80c070ecdb64 34 #define NORDIC_SCL SCL
ansond 2:9d7c4bad311e 35 #endif
ansond 5:4609a86755be 36 #ifdef TARGET_NRF51_DONGLE
ansond 5:4609a86755be 37 #define NORDIC_MODEL "nRF51822-DONGLE"
ansond 39:45355870bead 38 #define MY_ENDPOINT_NAME "mbed-ble-hrm-dongle"
ansond 5:4609a86755be 39 #define NORDIC_SDA P0_20
ansond 5:4609a86755be 40 #define NORDIC_SCL P0_19
ansond 2:9d7c4bad311e 41 #endif
ansond 5:4609a86755be 42 #ifdef TARGET_NRF51_MKIT
ansond 5:4609a86755be 43 #define NORDIC_MODEL "nRF51822-MKIT"
ansond 39:45355870bead 44 #define MY_ENDPOINT_NAME "mbed-ble-hrm-mkit"
ansond 5:4609a86755be 45 #define NORDIC_SDA P0_22
ansond 5:4609a86755be 46 #define NORDIC_SCL P0_20
ansond 2:9d7c4bad311e 47 #endif
ansond 2:9d7c4bad311e 48
ansond 0:6b414fe5f8db 49 // Static Resources
ansond 0:6b414fe5f8db 50 #include "StaticResource.h"
ansond 0:6b414fe5f8db 51 StaticResource mfg(&logger,"dev/mfg","Nordic Semi");
ansond 2:9d7c4bad311e 52 StaticResource model(&logger,"dev/mdl",NORDIC_MODEL);
ansond 0:6b414fe5f8db 53
ansond 0:6b414fe5f8db 54 //
ansond 0:6b414fe5f8db 55 // Dynamic Resource Note:
ansond 0:6b414fe5f8db 56 //
ansond 0:6b414fe5f8db 57 // mbedConnectorInterface supports up to IPT_MAX_ENTRIES
ansond 0:6b414fe5f8db 58 // (currently 5) independent dynamic resources.
ansond 0:6b414fe5f8db 59 //
ansond 0:6b414fe5f8db 60 // You can increase this (at the cost of memory) in
ansond 0:6b414fe5f8db 61 // mbedConnectorinterface.h
ansond 0:6b414fe5f8db 62 //
ansond 0:6b414fe5f8db 63
ansond 0:6b414fe5f8db 64 // Heartrate Resource
ansond 0:6b414fe5f8db 65 #include "HeartrateResource.h"
ansond 3:b0eb973cddda 66 HeartrateResource hr(&logger,"888/0/5850",true); // observable
ansond 0:6b414fe5f8db 67
ansond 42:9741365cff35 68 // Location Resource
ansond 42:9741365cff35 69 #include "LocationResource.h"
ansond 42:9741365cff35 70 LocationResource location(&logger,"999/0/1234",true); // observable
ansond 42:9741365cff35 71
ansond 0:6b414fe5f8db 72 // My NSP Domain
ansond 37:55a66b48199a 73 #define MY_NSP_DOMAIN "domain"
ansond 0:6b414fe5f8db 74
ansond 37:55a66b48199a 75 // Customization Example: My custom NSP IPv4 address and NSP CoAP port
ansond 42:9741365cff35 76 uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {23,99,29,171}; // connector (api.connector.mbed.org)
ansond 35:4adef21fd8b6 77 int my_nsp_coap_port = 5683;
ansond 0:6b414fe5f8db 78
ansond 0:6b414fe5f8db 79 // called from the Endpoint::start() below to create resources and the endpoint internals...
ansond 0:6b414fe5f8db 80 Connector::Options *configure_endpoint(Connector::OptionsBuilder &config)
ansond 0:6b414fe5f8db 81 {
ansond 0:6b414fe5f8db 82 // Build the endpoint configuration parameters
ansond 0:6b414fe5f8db 83 logger.log("configure_endpoint: building endpoint configuration...");
ansond 0:6b414fe5f8db 84 return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name
ansond 0:6b414fe5f8db 85 .setNSPAddress(my_nsp_address) // custom NSP address
ansond 0:6b414fe5f8db 86 .setDomain(MY_NSP_DOMAIN) // custom NSP domain
ansond 0:6b414fe5f8db 87 .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port
ansond 0:6b414fe5f8db 88
ansond 35:4adef21fd8b6 89 // enable or disable(default) immediate observationing control
ansond 35:4adef21fd8b6 90 .setImmedateObservationEnabled(true)
ansond 35:4adef21fd8b6 91
ansond 35:4adef21fd8b6 92 // enable or disable(default) GET-based observation control
ansond 35:4adef21fd8b6 93 .setEnableGETObservationControl(false)
ansond 35:4adef21fd8b6 94
ansond 0:6b414fe5f8db 95 // add the static resource representing this endpoint
ansond 0:6b414fe5f8db 96 .addResource(&mfg)
ansond 0:6b414fe5f8db 97 .addResource(&model)
ansond 0:6b414fe5f8db 98
ansond 0:6b414fe5f8db 99 // add the heartrate resource
ansond 42:9741365cff35 100 .addResource(&hr) // Resource implements its own observationing...
ansond 43:0c80682b673d 101 .addResource(&location,22000) // observe every 22 seconds
ansond 0:6b414fe5f8db 102
ansond 0:6b414fe5f8db 103 // finalize the configuration...
ansond 0:6b414fe5f8db 104 .build();
ansond 0:6b414fe5f8db 105 }
ansond 0:6b414fe5f8db 106
ansond 0:6b414fe5f8db 107 // main entry point...
ansond 0:6b414fe5f8db 108 int main()
ansond 0:6b414fe5f8db 109 {
ansond 0:6b414fe5f8db 110 // Announce
ansond 0:6b414fe5f8db 111 logger.log("\r\n\r\nmbed mDS BLE Heartrate Endpoint");
ansond 0:6b414fe5f8db 112
ansond 0:6b414fe5f8db 113 // we have to plumb our network first
ansond 0:6b414fe5f8db 114 Connector::Endpoint::plumbNetwork();
ansond 0:6b414fe5f8db 115
ansond 0:6b414fe5f8db 116 // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events...
ansond 0:6b414fe5f8db 117 logger.log("Start the endpoint to finish setup and enter the main loop...");
ansond 0:6b414fe5f8db 118 Connector::Endpoint::start();
ansond 5:4609a86755be 119 }