Michael Koster / Mbed 2 deprecated ipso_interop_mbed1

Dependencies:   Chainable_RGB_LED DHT LED_Bar mbed mbedConnectorInterface mbedEndpointNetwork_mjk_regfix

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

Go to the documentation of this file.
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 
00023 // mbed Connector Interface (configuration)
00024 #include "mbedConnectorInterface.h"
00025 
00026 // mbed Connector Endpoint includes
00027 #include "ConnectorEndpoint.h"
00028 #include "OptionsBuilder.h"
00029 
00030 // USB Serial port access for debugging/logging
00031 RawSerial pc(USBTX,USBRX);
00032 
00033 // Logging facility
00034 Logger logger(&pc);
00035 
00036 // Static Resources
00037 #include "StaticResource.h"
00038 StaticResource mfg(&logger,"3/0/0","ARM-mbed");
00039 StaticResource model(&logger,"3/0/1","mbed-6LoWPAN-demo");
00040 
00041 //
00042 // Dynamic Resource Note:
00043 //
00044 //  mbedConnectorInterface supports up to IPT_MAX_ENTRIES 
00045 //  (currently 5) independent dynamic resources.
00046 //
00047 //  You can increase this (at the cost of memory) 
00048 //  in mbedConnectorinterface.h
00049 //
00050 
00051 // Light Resource
00052 #include "LightResource.h"
00053 //LightResource light(&logger,"3311/0/5706");
00054 
00055 // LED Resource
00056 #include "OnBoardLED.h"
00057 LEDResource led(&logger,"3311/1/5706");
00058 
00059 // Temperature Resource
00060 #include "TempResource.h"
00061 //TempResource temp(&logger,"3303/0/5700", true); /* true if observable */
00062 
00063 // DHT11 Temperature Resource
00064 #include "DHT11_TempResource.h"
00065 //DHT11_TempResource dht_temp(&logger,"3303/0/5700", false); /* true if observable */
00066 
00067 // DHT11 Humidity  Resource
00068 #include "DHT11_HumiResource.h"
00069 //DHT11_HumiResource dht_humi(&logger,"3304/0/5700", true); /* true if observable */
00070 
00071 // Illuminance Resource
00072 #include "IlluminanceResource.h"
00073 //IlluminanceResource illum(&logger,"3301/0/5700", true); /* true if observable */
00074 
00075 // LedBar Resource
00076 #include "LedBarResource.h"
00077 //LedBarResource ledbar(&logger,"3306/0/5853", false); /* true if observable */
00078 
00079 // Button Resource
00080 #include "ButtonResource.h"
00081 ButtonResource button(&logger,"3200/0/5500", true); /* true if observable */
00082 
00083 // Buzzer Resource
00084 #include "BuzzerResource.h"
00085 //BuzzerResource buzzer(&logger,"3201/0/5500", false); /* true if observable */
00086 
00087 // Loudness Resource
00088 #include "LoudnessResource.h"
00089 LoudnessResource loud(&logger,"3324/0/5700", true); /* true if observable */
00090 
00091 // Luminance Resource
00092 #include "LuminanceResource.h"
00093 LuminanceResource lumi(&logger,"3300/0/5700", true); /* true if observable */
00094 
00095 // Presence Resource
00096 #include "PresenceResource.h"
00097 PresenceResource pres(&logger,"3302/0/5700", true); /* true if observable */
00098 
00099 
00100 
00101 // Set our own unique endpoint name
00102 #define MY_ENDPOINT_NAME                       "mbed1"
00103 
00104 // My NSP Domain
00105 #define MY_NSP_DOMAIN                          "domain"                               
00106 
00107 // Customization Example: My custom NSP IPv4 or IPv6 address and NSP CoAP port 
00108 //uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {0x20,0x02,0x0d,0xb4,0x00,0x00,0x00,0x00,0x02,0x0c,0x43,0xff,0xfe,0x87,0x81,0x7c}; 
00109 uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {0x20,0x02,0x0d,0xb4,0x00,0x00,0x00,0x00,0xba,0x27,0xeb,0xff,0xfe,0xc6,0x35,0x38}; 
00110 int my_nsp_coap_port                          = 5683;
00111 
00112 // called from the Endpoint::start() below to create resources and the endpoint internals...
00113 Connector::Options *configure_endpoint(Connector::OptionsBuilder &config)
00114 {
00115     // Build the endpoint configuration parameters
00116     logger.log("configure_endpoint: building endpoint configuration...");
00117 //    temp.setMaxAge(0); /* MaxAge = 0 to disable caching of the value in the Device Server */
00118     button.setMaxAge(0); /* MaxAge = 0 to disable caching of the value in the Device Server */
00119 //    DHT_temp.setMaxAge(0); /* MaxAge = 0 to disable caching of the value in the Device Server */
00120 //    DHT_humi.setMaxAge(0); /* MaxAge = 0 to disable caching of the value in the Device Server */
00121 //    illum.setMaxAge(0); /* MaxAge = 0 to disable caching of the value in the Device Server */
00122     lumi.setMaxAge(0); /* MaxAge = 0 to disable caching of the value in the Device Server */
00123     pres.setMaxAge(0); /* MaxAge = 0 to disable caching of the value in the Device Server */
00124  
00125     return config.setEndpointNodename(MY_ENDPOINT_NAME)                   // custom endpoint name
00126                  .setNSPAddress(my_nsp_address)                           // custom NSP address
00127                  .setDomain(MY_NSP_DOMAIN)                                // custom NSP domain
00128                  .setNSPPortNumber(my_nsp_coap_port)                      // custom NSP CoAP port
00129                  
00130                  // add the static resource representing this endpoint
00131                  .addResource(&mfg)
00132                  .addResource(&model)
00133                                     
00134                  // Add my specific physical dynamic resources...
00135 //                 .addResource(&light)
00136 //                 .addResource(&temp, 1000)
00137                  .addResource(&led)
00138 //                 .addResource(&illum, 1000)
00139                  .addResource(&lumi, 1000)
00140 //                 .addResource(&dht_temp)
00141 //                 .addResource(&dht_humi)
00142 //                 .addResource(&ledbar)
00143                  .addResource(&button, 1000)
00144 //                 .addResource(&buzzer)
00145                  .addResource(&loud, 1000)
00146                  .addResource(&pres, 1000)
00147                    
00148                  // finalize the configuration...
00149                  .build();
00150 }
00151 
00152 // main entry point...
00153 int main()
00154 {
00155     // Announce
00156     logger.log("\r\n\r\nmbed mDS Sample Endpoint v1.0 (6LoWPAN)");
00157 
00158     // we have to plumb our network first
00159     Connector::Endpoint::plumbNetwork();
00160      
00161     // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events...
00162     logger.log("Start the endpoint to finish setup and enter the main loop...");
00163     Connector::Endpoint::start();
00164 }