fork of chris cause ide is stupid

Dependencies:   Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork

Fork of Trail by Christopher Wu

Committer:
jowil
Date:
Thu May 28 23:25:20 2015 +0000
Revision:
2:f72204758515
Parent:
1:b96a11b680dc
progress;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
michaeljkoster 0:a7458d25d9c9 1 /**
michaeljkoster 0:a7458d25d9c9 2 * @file main.cpp
michaeljkoster 0:a7458d25d9c9 3 * @brief mbed Connected Home Endpoint main entry point
michaeljkoster 0:a7458d25d9c9 4 * @author Doug Anson
michaeljkoster 0:a7458d25d9c9 5 * @version 1.0
michaeljkoster 0:a7458d25d9c9 6 * @see
michaeljkoster 0:a7458d25d9c9 7 *
michaeljkoster 0:a7458d25d9c9 8 * Copyright (c) 2014
michaeljkoster 0:a7458d25d9c9 9 *
michaeljkoster 0:a7458d25d9c9 10 * Licensed under the Apache License, Version 2.0 (the "License");
michaeljkoster 0:a7458d25d9c9 11 * you may not use this file except in compliance with the License.
michaeljkoster 0:a7458d25d9c9 12 * You may obtain a copy of the License at
michaeljkoster 0:a7458d25d9c9 13 *
michaeljkoster 0:a7458d25d9c9 14 * http://www.apache.org/licenses/LICENSE-2.0
michaeljkoster 0:a7458d25d9c9 15 *
michaeljkoster 0:a7458d25d9c9 16 * Unless required by applicable law or agreed to in writing, software
michaeljkoster 0:a7458d25d9c9 17 * distributed under the License is distributed on an "AS IS" BASIS,
michaeljkoster 0:a7458d25d9c9 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michaeljkoster 0:a7458d25d9c9 19 * See the License for the specific language governing permissions and
michaeljkoster 0:a7458d25d9c9 20 * limitations under the License.
michaeljkoster 0:a7458d25d9c9 21 */
michaeljkoster 0:a7458d25d9c9 22 // mbed Connector Interface (configuration)
michaeljkoster 0:a7458d25d9c9 23 #include "mbedConnectorInterface.h"
michaeljkoster 0:a7458d25d9c9 24
michaeljkoster 0:a7458d25d9c9 25 // Ethernet Interface
michaeljkoster 0:a7458d25d9c9 26 #include "EthernetInterface.h"
michaeljkoster 0:a7458d25d9c9 27 EthernetInterface ethernet;
michaeljkoster 0:a7458d25d9c9 28
michaeljkoster 0:a7458d25d9c9 29 // mbed Connector Endpoint includes
michaeljkoster 0:a7458d25d9c9 30 #include "ConnectorEndpoint.h"
michaeljkoster 0:a7458d25d9c9 31 #include "OptionsBuilder.h"
michaeljkoster 0:a7458d25d9c9 32
michaeljkoster 0:a7458d25d9c9 33 // USB Serial port access for debugging/logging
michaeljkoster 0:a7458d25d9c9 34 RawSerial pc(USBTX,USBRX);
michaeljkoster 0:a7458d25d9c9 35
michaeljkoster 0:a7458d25d9c9 36 // Logging facility
michaeljkoster 0:a7458d25d9c9 37 Logger logger(&pc);
michaeljkoster 0:a7458d25d9c9 38
michaeljkoster 0:a7458d25d9c9 39 // Static Resources
michaeljkoster 0:a7458d25d9c9 40 #include "StaticResource.h"
michaeljkoster 0:a7458d25d9c9 41 StaticResource mfg(&logger,"3/0/0","Freescale");
michaeljkoster 0:a7458d25d9c9 42 StaticResource model(&logger,"3/0/1","K64F mbed Ethernet demo");
michaeljkoster 0:a7458d25d9c9 43
michaeljkoster 0:a7458d25d9c9 44 //
michaeljkoster 0:a7458d25d9c9 45 // Dynamic Resource Note:
michaeljkoster 0:a7458d25d9c9 46 //
michaeljkoster 0:a7458d25d9c9 47 // mbedConnectorInterface supports up to IPT_MAX_ENTRIES
michaeljkoster 0:a7458d25d9c9 48 // (currently 5) independent dynamic resources.
michaeljkoster 0:a7458d25d9c9 49 //
michaeljkoster 0:a7458d25d9c9 50 // You can increase this (at the cost of memory)
michaeljkoster 0:a7458d25d9c9 51 // in mbedConnectorinterface.h
michaeljkoster 0:a7458d25d9c9 52 //
michaeljkoster 0:a7458d25d9c9 53
michaeljkoster 0:a7458d25d9c9 54 // Light Resource
michaeljkoster 0:a7458d25d9c9 55 #include "LightResource.h"
michaeljkoster 0:a7458d25d9c9 56 LightResource light(&logger,"3311/0/5706");
michaeljkoster 0:a7458d25d9c9 57
michaeljkoster 0:a7458d25d9c9 58 // LED Resource
michaeljkoster 0:a7458d25d9c9 59 #include "OnBoardLED.h"
michaeljkoster 0:a7458d25d9c9 60 LEDResource led(&logger,"3311/1/5706");
michaeljkoster 0:a7458d25d9c9 61
michaeljkoster 0:a7458d25d9c9 62 // SLide control Resource
michaeljkoster 0:a7458d25d9c9 63 #include "SliderResource.h"
michaeljkoster 0:a7458d25d9c9 64 SliderResource slider(&logger,"3202/0/5600", true); /* true if observable */
michaeljkoster 0:a7458d25d9c9 65
jowil 2:f72204758515 66 // 3203 is analogue output
cjwu15 1:b96a11b680dc 67 #include "UV.h"
jowil 2:f72204758515 68 UVResource uv(&logger,"uv");
cjwu15 1:b96a11b680dc 69
jowil 2:f72204758515 70 // 3303 is temperature IPSO
cjwu15 1:b96a11b680dc 71 #include "Temp.h"
jowil 2:f72204758515 72 TempResource temp(&logger, "temp");
cjwu15 1:b96a11b680dc 73
jowil 2:f72204758515 74 // 3201 is digital output
cjwu15 1:b96a11b680dc 75 #include "Motion.h"
jowil 2:f72204758515 76 MotionResource motion(&logger, "motion");
cjwu15 1:b96a11b680dc 77
cjwu15 1:b96a11b680dc 78 #include "mbed.h"
cjwu15 1:b96a11b680dc 79
michaeljkoster 0:a7458d25d9c9 80 // Set our own unique endpoint name
jowil 2:f72204758515 81 #define MY_ENDPOINT_NAME "trailtraffic"
michaeljkoster 0:a7458d25d9c9 82
michaeljkoster 0:a7458d25d9c9 83 // My NSP Domain
cjwu15 1:b96a11b680dc 84 #define MY_NSP_DOMAIN "trail"
michaeljkoster 0:a7458d25d9c9 85
michaeljkoster 0:a7458d25d9c9 86 // Customization Example: My custom NSP IPv4 or IPv6 address and NSP CoAP port
michaeljkoster 0:a7458d25d9c9 87 //uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {192,168,1,199}; /* local */
cjwu15 1:b96a11b680dc 88 uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {54,191,98,247}; /* smartobjectservice.com */
michaeljkoster 0:a7458d25d9c9 89 int my_nsp_coap_port = 5683;
michaeljkoster 0:a7458d25d9c9 90
michaeljkoster 0:a7458d25d9c9 91 // called from the Endpoint::start() below to create resources and the endpoint internals...
michaeljkoster 0:a7458d25d9c9 92 Connector::Options *configure_endpoint(Connector::OptionsBuilder &config)
michaeljkoster 0:a7458d25d9c9 93 {
michaeljkoster 0:a7458d25d9c9 94 // Build the endpoint configuration parameters
michaeljkoster 0:a7458d25d9c9 95 logger.log("configure_endpoint: building endpoint configuration...");
jowil 2:f72204758515 96 /* MaxAge = 0 to disable caching of the slide value in the Device Server */
jowil 2:f72204758515 97 temp.setMaxAge(0);
jowil 2:f72204758515 98 uv.setMaxAge(0);
jowil 2:f72204758515 99 motion.setMaxAge(0);
michaeljkoster 0:a7458d25d9c9 100 return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name
michaeljkoster 0:a7458d25d9c9 101 .setNSPAddress(my_nsp_address) // custom NSP address
michaeljkoster 0:a7458d25d9c9 102 .setDomain(MY_NSP_DOMAIN) // custom NSP domain
michaeljkoster 0:a7458d25d9c9 103 .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port
michaeljkoster 0:a7458d25d9c9 104
michaeljkoster 0:a7458d25d9c9 105 // add the static resource representing this endpoint
michaeljkoster 0:a7458d25d9c9 106 .addResource(&mfg)
michaeljkoster 0:a7458d25d9c9 107 .addResource(&model)
michaeljkoster 0:a7458d25d9c9 108
jowil 2:f72204758515 109 // Add my specific physical dynamic resources
cjwu15 1:b96a11b680dc 110 .addResource(&temp)
cjwu15 1:b96a11b680dc 111 .addResource(&uv)
cjwu15 1:b96a11b680dc 112 .addResource(&motion)
michaeljkoster 0:a7458d25d9c9 113 // finalize the configuration...
michaeljkoster 0:a7458d25d9c9 114 .build();
michaeljkoster 0:a7458d25d9c9 115 }
michaeljkoster 0:a7458d25d9c9 116
michaeljkoster 0:a7458d25d9c9 117 // main entry point...
michaeljkoster 0:a7458d25d9c9 118 int main()
michaeljkoster 0:a7458d25d9c9 119 {
michaeljkoster 0:a7458d25d9c9 120 // Announce
michaeljkoster 0:a7458d25d9c9 121 logger.log("\r\n\r\nmbed mDS Sample Endpoint v1.0 (Ethernet)");
michaeljkoster 0:a7458d25d9c9 122
michaeljkoster 0:a7458d25d9c9 123 // we have to plumb our network first
michaeljkoster 0:a7458d25d9c9 124 Connector::Endpoint::plumbNetwork();
michaeljkoster 0:a7458d25d9c9 125
michaeljkoster 0:a7458d25d9c9 126 // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events...
michaeljkoster 0:a7458d25d9c9 127 logger.log("Start the endpoint to finish setup and enter the main loop...");
cjwu15 1:b96a11b680dc 128 Connector::Endpoint::start();
michaeljkoster 0:a7458d25d9c9 129 }
cjwu15 1:b96a11b680dc 130
cjwu15 1:b96a11b680dc 131 // jameco sensor motion pir 3-5VOC 120 19.5ft dist dist/hold time adj