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: Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork
Fork of IoT_LED_demo by
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 // mbed Connector Interface (configuration) 00023 #include "mbedConnectorInterface.h" 00024 00025 // Ethernet Interface 00026 #include "EthernetInterface.h" 00027 EthernetInterface ethernet; 00028 00029 // mbed Connector Endpoint includes 00030 #include "ConnectorEndpoint.h" 00031 #include "OptionsBuilder.h" 00032 00033 // USB Serial port access for debugging/logging 00034 RawSerial pc(USBTX,USBRX); 00035 00036 // Logging facility 00037 Logger logger(&pc); 00038 00039 // Static Resources 00040 #include "StaticResource.h" 00041 StaticResource mfg(&logger,"3/0/0","Freescale"); 00042 StaticResource model(&logger,"3/0/1","K64F mbed Ethernet demo"); 00043 00044 // 00045 // Dynamic Resource Note: 00046 // 00047 // mbedConnectorInterface supports up to IPT_MAX_ENTRIES 00048 // (currently 5) independent dynamic resources. 00049 // 00050 // You can increase this (at the cost of memory) 00051 // in mbedConnectorinterface.h 00052 // 00053 00054 // Light Resource 00055 #include "LightResource.h" 00056 LightResource light(&logger,"3311/0/5706"); 00057 00058 // LED Resource 00059 #include "OnBoardLED.h" 00060 LEDResource led(&logger,"3311/1/5706"); 00061 00062 // SLide control Resource 00063 #include "SliderResource.h" 00064 SliderResource slider(&logger,"3202/0/5600", true); /* true if observable */ 00065 00066 #include "UV.h" 00067 UVResource uv(&logger,"3311/2/5706"); 00068 00069 #include "Temp.h" 00070 TempResource temp(&logger, "3311/3/5706"); 00071 00072 #include "Motion.h" 00073 MotionResource motion(&logger, "3311/4/5706"); 00074 00075 #include "mbed.h" 00076 00077 00078 // Set our own unique endpoint name 00079 #define MY_ENDPOINT_NAME "TrailTraffic" 00080 00081 // My NSP Domain 00082 #define MY_NSP_DOMAIN "trail" 00083 00084 // Customization Example: My custom NSP IPv4 or IPv6 address and NSP CoAP port 00085 //uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {192,168,1,199}; /* local */ 00086 uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {54,191,98,247}; /* smartobjectservice.com */ 00087 int my_nsp_coap_port = 5683; 00088 00089 // called from the Endpoint::start() below to create resources and the endpoint internals... 00090 Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) 00091 { 00092 // Build the endpoint configuration parameters 00093 logger.log("configure_endpoint: building endpoint configuration..."); 00094 slider.setMaxAge(0); /* MaxAge = 0 to disable caching of the slide value in the Device Server */ 00095 return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name 00096 .setNSPAddress(my_nsp_address) // custom NSP address 00097 .setDomain(MY_NSP_DOMAIN) // custom NSP domain 00098 .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port 00099 00100 // add the static resource representing this endpoint 00101 .addResource(&mfg) 00102 .addResource(&model) 00103 00104 // Add my specific physical dynamic resources... 00105 .addResource(&light) 00106 .addResource(&slider, 10000) 00107 .addResource(&led) 00108 .addResource(&temp) 00109 .addResource(&uv) 00110 .addResource(&motion) 00111 // finalize the configuration... 00112 .build(); 00113 } 00114 00115 00116 // main entry point... 00117 int main() 00118 { 00119 // Announce 00120 logger.log("\r\n\r\nmbed mDS Sample Endpoint v1.0 (Ethernet)"); 00121 00122 // we have to plumb our network first 00123 Connector::Endpoint::plumbNetwork(); 00124 00125 // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events... 00126 logger.log("Start the endpoint to finish setup and enter the main loop..."); 00127 Connector::Endpoint::start(); 00128 } 00129 00130 // jameco sensor motion pir 3-5VOC 120 19.5ft dist dist/hold time adj
Generated on Tue Jul 12 2022 20:37:45 by
1.7.2
