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: mbed mbedConnectorInterface mbedEndpointNetwork
main.cpp@2:6eb88bd81529, 2015-04-27 (annotated)
- Committer:
- jiwu14
- Date:
- Mon Apr 27 20:11:09 2015 +0000
- Revision:
- 2:6eb88bd81529
- Parent:
- 1:6178b6411293
- Child:
- 3:3281ef00910f
Small fix to MoistureResource constructor.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| JasonSwanson | 0:6af0e7b187d9 | 1 | /** |
| JasonSwanson | 0:6af0e7b187d9 | 2 | * @file main.cpp |
| JasonSwanson | 0:6af0e7b187d9 | 3 | * @brief mbed Connected Home Endpoint main entry point |
| JasonSwanson | 0:6af0e7b187d9 | 4 | * @author Doug Anson |
| JasonSwanson | 0:6af0e7b187d9 | 5 | * @version 1.0 |
| JasonSwanson | 0:6af0e7b187d9 | 6 | * @see |
| JasonSwanson | 0:6af0e7b187d9 | 7 | * |
| JasonSwanson | 0:6af0e7b187d9 | 8 | * Copyright (c) 2014 |
| JasonSwanson | 0:6af0e7b187d9 | 9 | * |
| JasonSwanson | 0:6af0e7b187d9 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| JasonSwanson | 0:6af0e7b187d9 | 11 | * you may not use this file except in compliance with the License. |
| JasonSwanson | 0:6af0e7b187d9 | 12 | * You may obtain a copy of the License at |
| JasonSwanson | 0:6af0e7b187d9 | 13 | * |
| JasonSwanson | 0:6af0e7b187d9 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| JasonSwanson | 0:6af0e7b187d9 | 15 | * |
| JasonSwanson | 0:6af0e7b187d9 | 16 | * Unless required by applicable law or agreed to in writing, software |
| JasonSwanson | 0:6af0e7b187d9 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
| JasonSwanson | 0:6af0e7b187d9 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| JasonSwanson | 0:6af0e7b187d9 | 19 | * See the License for the specific language governing permissions and |
| JasonSwanson | 0:6af0e7b187d9 | 20 | * limitations under the License. |
| JasonSwanson | 0:6af0e7b187d9 | 21 | */ |
| JasonSwanson | 0:6af0e7b187d9 | 22 | |
| JasonSwanson | 0:6af0e7b187d9 | 23 | // mbed Connector Interface (configuration) |
| JasonSwanson | 0:6af0e7b187d9 | 24 | #include "mbedConnectorInterface.h" |
| JasonSwanson | 0:6af0e7b187d9 | 25 | |
| JasonSwanson | 0:6af0e7b187d9 | 26 | // Ethernet Interface |
| JasonSwanson | 0:6af0e7b187d9 | 27 | #include "EthernetInterface.h" |
| JasonSwanson | 0:6af0e7b187d9 | 28 | EthernetInterface ethernet; |
| JasonSwanson | 0:6af0e7b187d9 | 29 | |
| JasonSwanson | 0:6af0e7b187d9 | 30 | // mbed Connector Endpoint includes |
| JasonSwanson | 0:6af0e7b187d9 | 31 | #include "ConnectorEndpoint.h" |
| JasonSwanson | 0:6af0e7b187d9 | 32 | #include "OptionsBuilder.h" |
| JasonSwanson | 0:6af0e7b187d9 | 33 | |
| JasonSwanson | 0:6af0e7b187d9 | 34 | // USB Serial port access for debugging/logging |
| JasonSwanson | 0:6af0e7b187d9 | 35 | RawSerial pc(USBTX,USBRX); |
| JasonSwanson | 0:6af0e7b187d9 | 36 | |
| JasonSwanson | 0:6af0e7b187d9 | 37 | // Logging facility |
| JasonSwanson | 0:6af0e7b187d9 | 38 | Logger logger(&pc); |
| JasonSwanson | 0:6af0e7b187d9 | 39 | |
| JasonSwanson | 0:6af0e7b187d9 | 40 | // Static Resources |
| JasonSwanson | 0:6af0e7b187d9 | 41 | #include "StaticResource.h" |
| JasonSwanson | 0:6af0e7b187d9 | 42 | StaticResource mfg(&logger,"3/0/0","Freescale"); |
| jiwu14 | 2:6eb88bd81529 | 43 | StaticResource model(&logger,"3/0/1","K64F mbed WateringBoard"); |
| JasonSwanson | 0:6af0e7b187d9 | 44 | |
| JasonSwanson | 0:6af0e7b187d9 | 45 | // |
| JasonSwanson | 0:6af0e7b187d9 | 46 | // Dynamic Resource Note: |
| JasonSwanson | 0:6af0e7b187d9 | 47 | // |
| JasonSwanson | 0:6af0e7b187d9 | 48 | // mbedConnectorInterface supports up to IPT_MAX_ENTRIES |
| JasonSwanson | 0:6af0e7b187d9 | 49 | // (currently 5) independent dynamic resources. |
| JasonSwanson | 0:6af0e7b187d9 | 50 | // |
| JasonSwanson | 0:6af0e7b187d9 | 51 | // You can increase this (at the cost of memory) |
| JasonSwanson | 0:6af0e7b187d9 | 52 | // in mbedConnectorinterface.h |
| JasonSwanson | 0:6af0e7b187d9 | 53 | // |
| JasonSwanson | 0:6af0e7b187d9 | 54 | |
| JasonSwanson | 0:6af0e7b187d9 | 55 | // Light Resource |
| jiwu14 | 1:6178b6411293 | 56 | //#include "LightResource.h" |
| jiwu14 | 1:6178b6411293 | 57 | //LightResource light(&logger,"3311/0/5706"); |
| JasonSwanson | 0:6af0e7b187d9 | 58 | |
| JasonSwanson | 0:6af0e7b187d9 | 59 | // LED Resource |
| JasonSwanson | 0:6af0e7b187d9 | 60 | #include "OnBoardLED.h" |
| JasonSwanson | 0:6af0e7b187d9 | 61 | LEDResource led(&logger,"3311/1/5706"); |
| JasonSwanson | 0:6af0e7b187d9 | 62 | |
| JasonSwanson | 0:6af0e7b187d9 | 63 | // SLide control Resource |
| jiwu14 | 1:6178b6411293 | 64 | //#include "SliderResource.h" |
| jiwu14 | 1:6178b6411293 | 65 | //SliderResource slider(&logger,"3202/0/5600", true); /* true if observable */ |
| jiwu14 | 1:6178b6411293 | 66 | |
| jiwu14 | 1:6178b6411293 | 67 | // Moisture Resource |
| jiwu14 | 1:6178b6411293 | 68 | #include "MoistureResource.h" |
| jiwu14 | 1:6178b6411293 | 69 | MoistureResource moisture(&logger, "3304/0/5600", true); /* true for observable */ |
| JasonSwanson | 0:6af0e7b187d9 | 70 | |
| JasonSwanson | 0:6af0e7b187d9 | 71 | // Set our own unique endpoint name |
| JasonSwanson | 0:6af0e7b187d9 | 72 | #define MY_ENDPOINT_NAME "WateringBoard" |
| JasonSwanson | 0:6af0e7b187d9 | 73 | |
| JasonSwanson | 0:6af0e7b187d9 | 74 | // My NSP Domain |
| JasonSwanson | 0:6af0e7b187d9 | 75 | #define MY_NSP_DOMAIN "water" |
| JasonSwanson | 0:6af0e7b187d9 | 76 | |
| JasonSwanson | 0:6af0e7b187d9 | 77 | // Customization Example: My custom NSP IPv4 or IPv6 address and NSP CoAP port |
| JasonSwanson | 0:6af0e7b187d9 | 78 | //uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {192,168,1,199}; /* local */ |
| JasonSwanson | 0:6af0e7b187d9 | 79 | uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {54,191,98,247}; /* smartobjectservice.com */ |
| JasonSwanson | 0:6af0e7b187d9 | 80 | int my_nsp_coap_port = 5683; |
| JasonSwanson | 0:6af0e7b187d9 | 81 | |
| JasonSwanson | 0:6af0e7b187d9 | 82 | // called from the Endpoint::start() below to create resources and the endpoint internals... |
| JasonSwanson | 0:6af0e7b187d9 | 83 | Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) |
| JasonSwanson | 0:6af0e7b187d9 | 84 | { |
| JasonSwanson | 0:6af0e7b187d9 | 85 | // Build the endpoint configuration parameters |
| JasonSwanson | 0:6af0e7b187d9 | 86 | logger.log("configure_endpoint: building endpoint configuration..."); |
| jiwu14 | 1:6178b6411293 | 87 | //slider.setMaxAge(0); /* MaxAge = 0 to disable caching of the slide value in the Device Server */ |
| jiwu14 | 1:6178b6411293 | 88 | moisture.setMaxAge(0); |
| JasonSwanson | 0:6af0e7b187d9 | 89 | return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name |
| JasonSwanson | 0:6af0e7b187d9 | 90 | .setNSPAddress(my_nsp_address) // custom NSP address |
| JasonSwanson | 0:6af0e7b187d9 | 91 | .setDomain(MY_NSP_DOMAIN) // custom NSP domain |
| JasonSwanson | 0:6af0e7b187d9 | 92 | .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port |
| JasonSwanson | 0:6af0e7b187d9 | 93 | |
| JasonSwanson | 0:6af0e7b187d9 | 94 | // add the static resource representing this endpoint |
| JasonSwanson | 0:6af0e7b187d9 | 95 | .addResource(&mfg) |
| JasonSwanson | 0:6af0e7b187d9 | 96 | .addResource(&model) |
| JasonSwanson | 0:6af0e7b187d9 | 97 | |
| JasonSwanson | 0:6af0e7b187d9 | 98 | // Add my specific physical dynamic resources... |
| jiwu14 | 1:6178b6411293 | 99 | //.addResource(&light) |
| jiwu14 | 1:6178b6411293 | 100 | //.addResource(&slider, 10000) |
| JasonSwanson | 0:6af0e7b187d9 | 101 | .addResource(&led) |
| jiwu14 | 1:6178b6411293 | 102 | .addResource(&moisture, 10000) |
| JasonSwanson | 0:6af0e7b187d9 | 103 | |
| JasonSwanson | 0:6af0e7b187d9 | 104 | // finalize the configuration... |
| JasonSwanson | 0:6af0e7b187d9 | 105 | .build(); |
| JasonSwanson | 0:6af0e7b187d9 | 106 | } |
| JasonSwanson | 0:6af0e7b187d9 | 107 | |
| JasonSwanson | 0:6af0e7b187d9 | 108 | // main entry point... |
| JasonSwanson | 0:6af0e7b187d9 | 109 | int main() |
| JasonSwanson | 0:6af0e7b187d9 | 110 | { |
| JasonSwanson | 0:6af0e7b187d9 | 111 | // Announce |
| JasonSwanson | 0:6af0e7b187d9 | 112 | logger.log("\r\n\r\nmbed mDS Sample Endpoint v1.0 (Ethernet)"); |
| JasonSwanson | 0:6af0e7b187d9 | 113 | |
| JasonSwanson | 0:6af0e7b187d9 | 114 | // we have to plumb our network first |
| JasonSwanson | 0:6af0e7b187d9 | 115 | Connector::Endpoint::plumbNetwork(); |
| JasonSwanson | 0:6af0e7b187d9 | 116 | |
| JasonSwanson | 0:6af0e7b187d9 | 117 | // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events... |
| JasonSwanson | 0:6af0e7b187d9 | 118 | logger.log("Start the endpoint to finish setup and enter the main loop..."); |
| JasonSwanson | 0:6af0e7b187d9 | 119 | Connector::Endpoint::start(); |
| JasonSwanson | 0:6af0e7b187d9 | 120 | } |
