Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LM75B mbed mbedConnectorInterface mbedEndpointNetwork_Ublox
main.cpp@6:15431341f373, 2015-07-23 (annotated)
- Committer:
- ansond
- Date:
- Thu Jul 23 19:42:38 2015 +0000
- Revision:
- 6:15431341f373
- Parent:
- 4:c022c5e05347
- Child:
- 7:68f1eadf4a63
updates for ublox radios
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| ansond | 0:a507bbd93e47 | 1 | /** | 
| ansond | 0:a507bbd93e47 | 2 | * @file main.cpp | 
| ansond | 0:a507bbd93e47 | 3 | * @brief mbed Connected Home Endpoint main entry point | 
| ansond | 0:a507bbd93e47 | 4 | * @author Doug Anson | 
| ansond | 0:a507bbd93e47 | 5 | * @version 1.0 | 
| ansond | 0:a507bbd93e47 | 6 | * @see | 
| ansond | 0:a507bbd93e47 | 7 | * | 
| ansond | 0:a507bbd93e47 | 8 | * Copyright (c) 2014 | 
| ansond | 0:a507bbd93e47 | 9 | * | 
| ansond | 0:a507bbd93e47 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
| ansond | 0:a507bbd93e47 | 11 | * you may not use this file except in compliance with the License. | 
| ansond | 0:a507bbd93e47 | 12 | * You may obtain a copy of the License at | 
| ansond | 0:a507bbd93e47 | 13 | * | 
| ansond | 0:a507bbd93e47 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 | 
| ansond | 0:a507bbd93e47 | 15 | * | 
| ansond | 0:a507bbd93e47 | 16 | * Unless required by applicable law or agreed to in writing, software | 
| ansond | 0:a507bbd93e47 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, | 
| ansond | 0:a507bbd93e47 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| ansond | 0:a507bbd93e47 | 19 | * See the License for the specific language governing permissions and | 
| ansond | 0:a507bbd93e47 | 20 | * limitations under the License. | 
| ansond | 0:a507bbd93e47 | 21 | */ | 
| ansond | 0:a507bbd93e47 | 22 | |
| ansond | 0:a507bbd93e47 | 23 | // mbed Connector Interface (configuration) | 
| ansond | 0:a507bbd93e47 | 24 | #include "mbedConnectorInterface.h" | 
| ansond | 0:a507bbd93e47 | 25 | |
| ansond | 0:a507bbd93e47 | 26 | // U-Blox Cellular Support | 
| ansond | 0:a507bbd93e47 | 27 | #include "MBEDUbloxCellRadio.h" | 
| ansond | 6:15431341f373 | 28 | MDMSerial modem; | 
| ansond | 0:a507bbd93e47 | 29 | MBEDUbloxCellRadio cellular((void *)&modem); | 
| ansond | 0:a507bbd93e47 | 30 | |
| ansond | 0:a507bbd93e47 | 31 | // mbed Connector Endpoint includes | 
| ansond | 0:a507bbd93e47 | 32 | #include "ConnectorEndpoint.h" | 
| ansond | 0:a507bbd93e47 | 33 | #include "OptionsBuilder.h" | 
| ansond | 0:a507bbd93e47 | 34 | |
| ansond | 0:a507bbd93e47 | 35 | // USB Serial port access for debugging/logging | 
| ansond | 0:a507bbd93e47 | 36 | RawSerial pc(USBTX,USBRX); | 
| ansond | 0:a507bbd93e47 | 37 | |
| ansond | 0:a507bbd93e47 | 38 | // Logging facility | 
| ansond | 0:a507bbd93e47 | 39 | Logger logger(&pc); | 
| ansond | 0:a507bbd93e47 | 40 | |
| ansond | 0:a507bbd93e47 | 41 | // Static Resources | 
| ansond | 0:a507bbd93e47 | 42 | #include "StaticResource.h" | 
| ansond | 2:36bc50ce23f2 | 43 | StaticResource mfg(&logger,"dev/mfg","U-blox"); | 
| ansond | 2:36bc50ce23f2 | 44 | StaticResource model(&logger,"dev/mdl","mbed cellular node"); | 
| ansond | 0:a507bbd93e47 | 45 | |
| ansond | 0:a507bbd93e47 | 46 | // | 
| ansond | 0:a507bbd93e47 | 47 | // Dynamic Resource Note: | 
| ansond | 0:a507bbd93e47 | 48 | // | 
| ansond | 0:a507bbd93e47 | 49 | // mbedConnectorInterface supports up to IPT_MAX_ENTRIES | 
| ansond | 0:a507bbd93e47 | 50 | // (currently 5) independent dynamic resources. | 
| ansond | 0:a507bbd93e47 | 51 | // | 
| ansond | 0:a507bbd93e47 | 52 | // You can increase this (at the cost of memory) | 
| ansond | 0:a507bbd93e47 | 53 | // in mbedConnectorinterface.h | 
| ansond | 0:a507bbd93e47 | 54 | // | 
| ansond | 0:a507bbd93e47 | 55 | |
| ansond | 0:a507bbd93e47 | 56 | // Sample Dynamic Resource | 
| ansond | 0:a507bbd93e47 | 57 | #include "SampleDynamicResource.h" | 
| ansond | 0:a507bbd93e47 | 58 | SampleDynamicResource sample(&logger,"999/999/9999"); | 
| ansond | 0:a507bbd93e47 | 59 | |
| ansond | 0:a507bbd93e47 | 60 | // Light Resource | 
| ansond | 0:a507bbd93e47 | 61 | #include "LightResource.h" | 
| ansond | 0:a507bbd93e47 | 62 | LightResource light(&logger,"311/0/5850"); | 
| ansond | 0:a507bbd93e47 | 63 | |
| ansond | 0:a507bbd93e47 | 64 | // Temperature Resource | 
| ansond | 0:a507bbd93e47 | 65 | #include "TemperatureResource.h" | 
| ansond | 6:15431341f373 | 66 | TemperatureResource temperature(&logger,"303/0/5700",true); | 
| ansond | 0:a507bbd93e47 | 67 | |
| ansond | 0:a507bbd93e47 | 68 | // Set our own unique endpoint name | 
| ansond | 2:36bc50ce23f2 | 69 | #define MY_ENDPOINT_NAME "mbed-ublox-endpoint" | 
| ansond | 0:a507bbd93e47 | 70 | |
| ansond | 0:a507bbd93e47 | 71 | // My NSP Domain | 
| ansond | 6:15431341f373 | 72 | #define MY_NSP_DOMAIN "domain" | 
| ansond | 0:a507bbd93e47 | 73 | |
| ansond | 4:c022c5e05347 | 74 | // Customization Example: My custom NSP IPv4 address and NSP CoAP port | 
| ansond | 6:15431341f373 | 75 | uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {23,99,29,171}; // connector (api.connector.mbed.org) | 
| ansond | 0:a507bbd93e47 | 76 | int my_nsp_coap_port = 5683; | 
| ansond | 0:a507bbd93e47 | 77 | |
| ansond | 0:a507bbd93e47 | 78 | // called from the Endpoint::start() below to create resources and the endpoint internals... | 
| ansond | 0:a507bbd93e47 | 79 | Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) | 
| ansond | 0:a507bbd93e47 | 80 | { | 
| ansond | 0:a507bbd93e47 | 81 | // Build the endpoint configuration parameters | 
| ansond | 0:a507bbd93e47 | 82 | logger.log("configure_endpoint: building endpoint configuration..."); | 
| ansond | 0:a507bbd93e47 | 83 | return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name | 
| ansond | 0:a507bbd93e47 | 84 | .setNSPAddress(my_nsp_address) // custom NSP address | 
| ansond | 0:a507bbd93e47 | 85 | .setDomain(MY_NSP_DOMAIN) // custom NSP domain | 
| ansond | 0:a507bbd93e47 | 86 | .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port | 
| ansond | 0:a507bbd93e47 | 87 | |
| ansond | 4:c022c5e05347 | 88 | // enable or disable(default) immediate observationing control | 
| ansond | 4:c022c5e05347 | 89 | .setImmedateObservationEnabled(true) | 
| ansond | 4:c022c5e05347 | 90 | |
| ansond | 4:c022c5e05347 | 91 | // enable or disable(default) GET-based observation control | 
| ansond | 4:c022c5e05347 | 92 | .setEnableGETObservationControl(false) | 
| ansond | 4:c022c5e05347 | 93 | |
| ansond | 0:a507bbd93e47 | 94 | // add the static resource representing this endpoint | 
| ansond | 0:a507bbd93e47 | 95 | .addResource(&mfg) | 
| ansond | 0:a507bbd93e47 | 96 | .addResource(&model) | 
| ansond | 0:a507bbd93e47 | 97 | |
| ansond | 0:a507bbd93e47 | 98 | // add a Sample Dynamic Resource | 
| ansond | 0:a507bbd93e47 | 99 | .addResource(&sample) | 
| ansond | 0:a507bbd93e47 | 100 | |
| ansond | 0:a507bbd93e47 | 101 | // Add my specific physical dynamic resources... | 
| ansond | 0:a507bbd93e47 | 102 | .addResource(&light) | 
| ansond | 0:a507bbd93e47 | 103 | .addResource(&temperature) | 
| ansond | 0:a507bbd93e47 | 104 | |
| ansond | 0:a507bbd93e47 | 105 | // finalize the configuration... | 
| ansond | 0:a507bbd93e47 | 106 | .build(); | 
| ansond | 0:a507bbd93e47 | 107 | } | 
| ansond | 0:a507bbd93e47 | 108 | |
| ansond | 0:a507bbd93e47 | 109 | // main entry point... | 
| ansond | 0:a507bbd93e47 | 110 | int main() | 
| ansond | 0:a507bbd93e47 | 111 | { | 
| ansond | 0:a507bbd93e47 | 112 | // Announce | 
| ansond | 2:36bc50ce23f2 | 113 | logger.log("\r\n\r\nmbed mDS Sample Endpoint v1.0 (U-blox Cellular)"); | 
| ansond | 0:a507bbd93e47 | 114 | |
| ansond | 0:a507bbd93e47 | 115 | // we have to plumb our network first | 
| ansond | 0:a507bbd93e47 | 116 | Connector::Endpoint::plumbNetwork(); | 
| ansond | 0:a507bbd93e47 | 117 | |
| ansond | 0:a507bbd93e47 | 118 | // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events... | 
| ansond | 0:a507bbd93e47 | 119 | logger.log("Start the endpoint to finish setup and enter the main loop..."); | 
| ansond | 0:a507bbd93e47 | 120 | Connector::Endpoint::start(); | 
| ansond | 0:a507bbd93e47 | 121 | } |