TrailTraffic

Dependencies:   Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork

Fork of IoT_LED_demo by MBED_DEMOS

Committer:
cjwu15
Date:
Fri May 22 00:39:20 2015 +0000
Revision:
1:b96a11b680dc
Parent:
0:a7458d25d9c9
Share;

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
cjwu15 1:b96a11b680dc 66 #include "UV.h"
cjwu15 1:b96a11b680dc 67 UVResource uv(&logger,"3311/2/5706");
cjwu15 1:b96a11b680dc 68
cjwu15 1:b96a11b680dc 69 #include "Temp.h"
cjwu15 1:b96a11b680dc 70 TempResource temp(&logger, "3311/3/5706");
cjwu15 1:b96a11b680dc 71
cjwu15 1:b96a11b680dc 72 #include "Motion.h"
cjwu15 1:b96a11b680dc 73 MotionResource motion(&logger, "3311/4/5706");
cjwu15 1:b96a11b680dc 74
cjwu15 1:b96a11b680dc 75 #include "mbed.h"
cjwu15 1:b96a11b680dc 76
cjwu15 1:b96a11b680dc 77
michaeljkoster 0:a7458d25d9c9 78 // Set our own unique endpoint name
cjwu15 1:b96a11b680dc 79 #define MY_ENDPOINT_NAME "TrailTraffic"
michaeljkoster 0:a7458d25d9c9 80
michaeljkoster 0:a7458d25d9c9 81 // My NSP Domain
cjwu15 1:b96a11b680dc 82 #define MY_NSP_DOMAIN "trail"
michaeljkoster 0:a7458d25d9c9 83
michaeljkoster 0:a7458d25d9c9 84 // Customization Example: My custom NSP IPv4 or IPv6 address and NSP CoAP port
michaeljkoster 0:a7458d25d9c9 85 //uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {192,168,1,199}; /* local */
cjwu15 1:b96a11b680dc 86 uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {54,191,98,247}; /* smartobjectservice.com */
michaeljkoster 0:a7458d25d9c9 87 int my_nsp_coap_port = 5683;
michaeljkoster 0:a7458d25d9c9 88
michaeljkoster 0:a7458d25d9c9 89 // called from the Endpoint::start() below to create resources and the endpoint internals...
michaeljkoster 0:a7458d25d9c9 90 Connector::Options *configure_endpoint(Connector::OptionsBuilder &config)
michaeljkoster 0:a7458d25d9c9 91 {
michaeljkoster 0:a7458d25d9c9 92 // Build the endpoint configuration parameters
michaeljkoster 0:a7458d25d9c9 93 logger.log("configure_endpoint: building endpoint configuration...");
michaeljkoster 0:a7458d25d9c9 94 slider.setMaxAge(0); /* MaxAge = 0 to disable caching of the slide value in the Device Server */
michaeljkoster 0:a7458d25d9c9 95 return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name
michaeljkoster 0:a7458d25d9c9 96 .setNSPAddress(my_nsp_address) // custom NSP address
michaeljkoster 0:a7458d25d9c9 97 .setDomain(MY_NSP_DOMAIN) // custom NSP domain
michaeljkoster 0:a7458d25d9c9 98 .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port
michaeljkoster 0:a7458d25d9c9 99
michaeljkoster 0:a7458d25d9c9 100 // add the static resource representing this endpoint
michaeljkoster 0:a7458d25d9c9 101 .addResource(&mfg)
michaeljkoster 0:a7458d25d9c9 102 .addResource(&model)
michaeljkoster 0:a7458d25d9c9 103
michaeljkoster 0:a7458d25d9c9 104 // Add my specific physical dynamic resources...
michaeljkoster 0:a7458d25d9c9 105 .addResource(&light)
michaeljkoster 0:a7458d25d9c9 106 .addResource(&slider, 10000)
michaeljkoster 0:a7458d25d9c9 107 .addResource(&led)
cjwu15 1:b96a11b680dc 108 .addResource(&temp)
cjwu15 1:b96a11b680dc 109 .addResource(&uv)
cjwu15 1:b96a11b680dc 110 .addResource(&motion)
michaeljkoster 0:a7458d25d9c9 111 // finalize the configuration...
michaeljkoster 0:a7458d25d9c9 112 .build();
michaeljkoster 0:a7458d25d9c9 113 }
michaeljkoster 0:a7458d25d9c9 114
cjwu15 1:b96a11b680dc 115
michaeljkoster 0:a7458d25d9c9 116 // main entry point...
michaeljkoster 0:a7458d25d9c9 117 int main()
michaeljkoster 0:a7458d25d9c9 118 {
michaeljkoster 0:a7458d25d9c9 119 // Announce
michaeljkoster 0:a7458d25d9c9 120 logger.log("\r\n\r\nmbed mDS Sample Endpoint v1.0 (Ethernet)");
michaeljkoster 0:a7458d25d9c9 121
michaeljkoster 0:a7458d25d9c9 122 // we have to plumb our network first
michaeljkoster 0:a7458d25d9c9 123 Connector::Endpoint::plumbNetwork();
michaeljkoster 0:a7458d25d9c9 124
michaeljkoster 0:a7458d25d9c9 125 // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events...
michaeljkoster 0:a7458d25d9c9 126 logger.log("Start the endpoint to finish setup and enter the main loop...");
cjwu15 1:b96a11b680dc 127 Connector::Endpoint::start();
michaeljkoster 0:a7458d25d9c9 128 }
cjwu15 1:b96a11b680dc 129
cjwu15 1:b96a11b680dc 130 // jameco sensor motion pir 3-5VOC 120 19.5ft dist dist/hold time adj