Sample program showing how to connect GR-PEACH into Watson IoT through mbed Connector and Watson's Connector Bridge

Dependencies:   AsciiFont DisplayApp GR-PEACH_video LCD_shield_config LWIPBP3595Interface_STA_for_mbed-os USBDevice

Overview

This sample program shows how to connect GR-PEACH into Watson IoT through mbed Connector and Watson's Connector Bridge. Note that this program is derived from https://github.com/ARMmbed/mbed-ethernet-sample-techcon2016.

In this program, at first, the barcode data input from camera is decoded on GR-PEACH using ZXing which is an open-source, multi-format 1D/2D barcode image processing library. Then, the decoded string is sent to Watson IoT via mbed Device Connector and Watson's Connector Bridge. At last, the delivered string is confirmed via NodeRED flow.

Required hardware

Application setup

  1. Select the connection type. For details, please refer to the following wiki:
    https://developer.mbed.org/teams/Renesas/code/mbed-os_Watson-IoT_ZXing_sample/wiki/Connection-type.
  2. Set the client credentials. For details, please refer to the following wiki:
    https://developer.mbed.org/teams/Renesas/code/mbed-os_Watson-IoT_ZXing_sample/wiki/Client-credentials.
  3. Change Ethernet settings. For details, please refer to the following wiki:
    https://developer.mbed.org/teams/Renesas/code/mbed-os_Watson-IoT_ZXing_sample/wiki/Ethernet-settings.
  4. Change Wifi settings. For details, please refer to the following wiki:
    https://developer.mbed.org/teams/Renesas/code/mbed-os_Watson-IoT_ZXing_sample/wiki/Wifi-settings.

Building this sample program

  1. Import this sample program onto mbed Compiler.
  2. Configure this sample program in accordance with Application setup.
  3. Compile the example on mbed Compiler and download the resultant binary file.
  4. Plug the Ethernet cable into GR-PEACH if you are using Ethernet mode. /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen7.png
  5. Plug the micro-USB cable into the OpenSDA port with lies on the next to the RESET button.
  6. Copy the binary previously downloaded to your PC to GR-PEACH to flash this sample program. When the copy is successfully completed, the board is ready to work.
  7. Press the RESET button on the board to run this sample program.
  8. For verification, please refer to the following wiki:
    https://developer.mbed.org/teams/Renesas/code/mbed-os_Watson-IoT_ZXing_sample/wiki/Monitoring-the-application.

Application resources

This sample program exposes two resources listed below:

  1. /311/0/5850 : Trigger to toggle LED on GR-PEACH (PUT). When "1" is sent to this resource by PUT method, LED should be turned off. Otherwise, LED should be turned on.
  2. /888/0/7700: Decode result of barcode data input from camera (GET)

Setup of Watson IoT

  1. You should create Watson IoT Instance by the following procedure:
    • Login IBM Bluemix from https://console.ng.bluemix.net/ and login it.
    • Select Services as follows: /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen6.png
    • Select Internet of Things" as follows: /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen7_1.png
    • Press Get Started as follows: /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen8.png
    • Configure Watson IoT Instance
      • Leave unbound /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen9.png
      • Select the Free plan, then click Create /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen10.png

  2. You should create Watson IoT Application Credentials Once you successfully create Watson IoT Instance, you should see the following Watson IoT dashboard: /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen11.png
    • On dashboard, launch the Connect your devices dashboard /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen12.png
    • Click APPS /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen13.png
    • Click Generate API Key /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen14_1.png
    • Record the API Key and Authenticatoin Token. Then click Generate after adding a comment /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen15.png Note that these two values will be needed in the later step.
  3. Watson IoT NodeRED Application should be created in accordance with the following procedure:
    • Go back to your Bluemix Dashboard: https://console.ng.bluemix.net
    • Click Create Application /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen16.png
    • Select Node-RED Starter /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen17.png
    • Enter a unique App name and Click Create /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen18.png
    • Application will Stage after a few minutes
    • Application will report app is running when the staging has completed
  4. Watson NodeRED Application should be binded to Watson IoT instance
    • You can now see the dashboard below: /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen19.png
    • Click Connections. Then, press Connect Existing /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen20.png
    • Click on Watson IoT Instance badge. Then, press Connect /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen21.png
    • NodeRED application will restage. This will take a while. Please wait for Your app is running state /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen22.png /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen23.png
  5. You should acquire mbed Device Connector DOMAIN value
    • Go to the mbed Device Connector Dashboard: https://connector.mbed.com and log in /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen41.png
    • Select Access Key in order to create a new token /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen42.png
    • Click CREATE NEW ACCESS KEY and enter a unique name. Then, push ADD bution /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen43.png
    • an API token is generated. Need to save the generated string for later steps /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen44.png
  1. You should configure Watson IoT ARM mbed Connector Bridge
    • Go back to the Watson IoT Dashboard and select Extensions /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen24.png
    • Press Add Extension /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen25.png
    • Add ARM mbed Connector /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen26_1.png
    • Setup the bridge /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen27.png
    • Enter your Connector API Token to Access Key and MBED_DOMAIN to Domain Id, respectively. Then, click Check Connection /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen28.png
    • If the connection is successfully established, you can see Connection Established. Then, press Done /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen29.png
  2. NodeRED Flow Example should be imported
    • Open NODEFLOW_GR-PEACH.txt
    • Navigate to the URL that you recorded earlier for your Watson IoT NodeRED Application (i.e. http://<app name>.mybluemix.net) and Select Go to your NodeRED flow editor /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen30.png
    • Select menu, Import and Clipboard /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen31.png
    • Paste the entire contents of JSON code described in NODEFLOW_GR-PEACH.txt and click Import /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen32.png
  3. Watson IoT Application Node Flow should be configured
    • Double-click input node and link them to your Watson IoT instance. /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen33.png
    • Click on the edit button /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen34.png
    • First enter arbitrary name. Then, Watson API Key and Watson Auth Token previously acquired. Finally, press Add to save /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen35.png
    • Enter MBED_ENDPOINT_NAME in security.h as Device ID. Then, press Done to save /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen36.png
    • Double-click output node /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen37.png
    • Edit API Key and Device Id in the same manner as that for input node
    • Click LED OFF and LED ON node and replace MBED_ENDPOINT_NAME_GOES_HERE with MBED_ENDPOINT_NAME as shown below: /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen38.png
    • Click Deproy to deploy NodeRED application /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen39.png
  4. Invoke sample program
    • Press the reset button on GR-PEACH
    • The decode result of barcode data should be shown in debug window /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen40_1.png
    • Also, you can toggle LED by clicking Turn LED OFF and Turn LED ON injection node /media/uploads/HinoNaka/mbed-os_watson-iot_zxing_sample_screen40_2.png
Committer:
Osamu Nakamura
Date:
Thu Nov 24 13:59:16 2016 +0900
Revision:
0:ad834d403a8c
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Osamu Nakamura 0:ad834d403a8c 1 /**
Osamu Nakamura 0:ad834d403a8c 2 * @file ConnectorEndpoint.cpp
Osamu Nakamura 0:ad834d403a8c 3 * @brief mbed CoAP Endpoint base class
Osamu Nakamura 0:ad834d403a8c 4 * @author Doug Anson/Chris Paola
Osamu Nakamura 0:ad834d403a8c 5 * @version 1.0
Osamu Nakamura 0:ad834d403a8c 6 * @see
Osamu Nakamura 0:ad834d403a8c 7 *
Osamu Nakamura 0:ad834d403a8c 8 * Copyright (c) 2014
Osamu Nakamura 0:ad834d403a8c 9 *
Osamu Nakamura 0:ad834d403a8c 10 * Licensed under the Apache License, Version 2.0 (the "License");
Osamu Nakamura 0:ad834d403a8c 11 * you may not use this file except in compliance with the License.
Osamu Nakamura 0:ad834d403a8c 12 * You may obtain a copy of the License at
Osamu Nakamura 0:ad834d403a8c 13 *
Osamu Nakamura 0:ad834d403a8c 14 * http://www.apache.org/licenses/LICENSE-2.0
Osamu Nakamura 0:ad834d403a8c 15 *
Osamu Nakamura 0:ad834d403a8c 16 * Unless required by applicable law or agreed to in writing, software
Osamu Nakamura 0:ad834d403a8c 17 * distributed under the License is distributed on an "AS IS" BASIS,
Osamu Nakamura 0:ad834d403a8c 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Osamu Nakamura 0:ad834d403a8c 19 * See the License for the specific language governing permissions and
Osamu Nakamura 0:ad834d403a8c 20 * limitations under the License.
Osamu Nakamura 0:ad834d403a8c 21 */
Osamu Nakamura 0:ad834d403a8c 22
Osamu Nakamura 0:ad834d403a8c 23 // Lower level Network
Osamu Nakamura 0:ad834d403a8c 24 #include "mbed-connector-interface/mbedEndpointNetwork.h"
Osamu Nakamura 0:ad834d403a8c 25
Osamu Nakamura 0:ad834d403a8c 26 // ConnectorEndpoint
Osamu Nakamura 0:ad834d403a8c 27 #include "mbed-connector-interface/ConnectorEndpoint.h"
Osamu Nakamura 0:ad834d403a8c 28
Osamu Nakamura 0:ad834d403a8c 29 // Utils support
Osamu Nakamura 0:ad834d403a8c 30 #include "mbed-connector-interface/Utils.h"
Osamu Nakamura 0:ad834d403a8c 31
Osamu Nakamura 0:ad834d403a8c 32 // Device Manager support
Osamu Nakamura 0:ad834d403a8c 33 #include "mbed-connector-interface/DeviceManager.h"
Osamu Nakamura 0:ad834d403a8c 34
Osamu Nakamura 0:ad834d403a8c 35 // our endpoint instance
Osamu Nakamura 0:ad834d403a8c 36 static Connector::Endpoint *__endpoint = NULL;
Osamu Nakamura 0:ad834d403a8c 37
Osamu Nakamura 0:ad834d403a8c 38 // LWIP Network interface instance
Osamu Nakamura 0:ad834d403a8c 39 NetworkInterface *__network_interface = NULL;
Osamu Nakamura 0:ad834d403a8c 40
Osamu Nakamura 0:ad834d403a8c 41 // Connector namespace
Osamu Nakamura 0:ad834d403a8c 42 namespace Connector {
Osamu Nakamura 0:ad834d403a8c 43
Osamu Nakamura 0:ad834d403a8c 44 // STATIC: Plumb the network
Osamu Nakamura 0:ad834d403a8c 45 void Endpoint::plumbNetwork(void *device_manager,bool canActAsRouterNode) {
Osamu Nakamura 0:ad834d403a8c 46 // create our endpoint instance...
Osamu Nakamura 0:ad834d403a8c 47 if (__endpoint == NULL) {
Osamu Nakamura 0:ad834d403a8c 48 // initialize our endpoint instance
Osamu Nakamura 0:ad834d403a8c 49 printf("Connector::Endpoint::plumbNetwork: initializing endpoint instance...\r\n");
Osamu Nakamura 0:ad834d403a8c 50 __endpoint = (Connector::Endpoint *)utils_init_endpoint(canActAsRouterNode);
Osamu Nakamura 0:ad834d403a8c 51 }
Osamu Nakamura 0:ad834d403a8c 52
Osamu Nakamura 0:ad834d403a8c 53 // set the device manager
Osamu Nakamura 0:ad834d403a8c 54 if (device_manager != NULL) {
Osamu Nakamura 0:ad834d403a8c 55 // device manager has been supplied
Osamu Nakamura 0:ad834d403a8c 56 printf("Connector::Endpoint::plumbNetwork: setting a device manager...\r\n");
Osamu Nakamura 0:ad834d403a8c 57 __endpoint->setDeviceManager(device_manager);
Osamu Nakamura 0:ad834d403a8c 58 }
Osamu Nakamura 0:ad834d403a8c 59 else {
Osamu Nakamura 0:ad834d403a8c 60 // no device manager supplied
Osamu Nakamura 0:ad834d403a8c 61 printf("Connector::Endpoint::plumbNetwork: no device manager supplied (OK)\r\n");
Osamu Nakamura 0:ad834d403a8c 62 }
Osamu Nakamura 0:ad834d403a8c 63
Osamu Nakamura 0:ad834d403a8c 64 // configure the endpoint...
Osamu Nakamura 0:ad834d403a8c 65 printf("Connector::Endpoint::plumbNetwork: configuring endpoint...\r\n");
Osamu Nakamura 0:ad834d403a8c 66 utils_configure_endpoint((void *)__endpoint);
Osamu Nakamura 0:ad834d403a8c 67
Osamu Nakamura 0:ad834d403a8c 68 // plumb the endpoint's network...
Osamu Nakamura 0:ad834d403a8c 69 printf("Connector::Endpoint::plumbNetwork: plumbing network...\r\n");
Osamu Nakamura 0:ad834d403a8c 70 net_plumb_network((void *)__endpoint);
Osamu Nakamura 0:ad834d403a8c 71 }
Osamu Nakamura 0:ad834d403a8c 72
Osamu Nakamura 0:ad834d403a8c 73 // STATIC: Finalize the endpoint's configuration and begin the endpoint's main even loop (static, not tied into Logger)
Osamu Nakamura 0:ad834d403a8c 74 void Endpoint::start()
Osamu Nakamura 0:ad834d403a8c 75 {
Osamu Nakamura 0:ad834d403a8c 76 // build out the endpoint with its configuration...
Osamu Nakamura 0:ad834d403a8c 77 printf("Connector::Endpoint::start: building out endpoint...\r\n");
Osamu Nakamura 0:ad834d403a8c 78 utils_build_endpoint((void *)__endpoint);
Osamu Nakamura 0:ad834d403a8c 79
Osamu Nakamura 0:ad834d403a8c 80 // finalize the endpoint and start its main loop
Osamu Nakamura 0:ad834d403a8c 81 printf("Endpoint::start: finalize and run the endpoint main loop..\r\n");
Osamu Nakamura 0:ad834d403a8c 82 net_finalize_and_run_endpoint_main_loop((void *)__endpoint);
Osamu Nakamura 0:ad834d403a8c 83 }
Osamu Nakamura 0:ad834d403a8c 84
Osamu Nakamura 0:ad834d403a8c 85 // STATIC: Set the ConnectionStatusInterface Implementation instance
Osamu Nakamura 0:ad834d403a8c 86 void Endpoint::setConnectionStatusInterface(ConnectionStatusInterface *csi) {
Osamu Nakamura 0:ad834d403a8c 87 if (__endpoint != NULL) {
Osamu Nakamura 0:ad834d403a8c 88 __endpoint->setConnectionStatusInterfaceImpl(csi);
Osamu Nakamura 0:ad834d403a8c 89 }
Osamu Nakamura 0:ad834d403a8c 90 }
Osamu Nakamura 0:ad834d403a8c 91
Osamu Nakamura 0:ad834d403a8c 92 // Constructor
Osamu Nakamura 0:ad834d403a8c 93 Endpoint::Endpoint(const Logger *logger, const Options *options) : M2MInterfaceObserver()
Osamu Nakamura 0:ad834d403a8c 94 {
Osamu Nakamura 0:ad834d403a8c 95 this->m_logger = (Logger *)logger;
Osamu Nakamura 0:ad834d403a8c 96 this->m_options = (Options *)options;
Osamu Nakamura 0:ad834d403a8c 97 this->m_device_manager = NULL;
Osamu Nakamura 0:ad834d403a8c 98 this->m_connected = false;
Osamu Nakamura 0:ad834d403a8c 99 this->m_registered = false;
Osamu Nakamura 0:ad834d403a8c 100 this->m_csi = NULL;
Osamu Nakamura 0:ad834d403a8c 101 this->m_oim = NULL;
Osamu Nakamura 0:ad834d403a8c 102 }
Osamu Nakamura 0:ad834d403a8c 103
Osamu Nakamura 0:ad834d403a8c 104 // Copy Constructor
Osamu Nakamura 0:ad834d403a8c 105 Endpoint::Endpoint(const Endpoint &ep)
Osamu Nakamura 0:ad834d403a8c 106 {
Osamu Nakamura 0:ad834d403a8c 107 this->m_logger = ep.m_logger;
Osamu Nakamura 0:ad834d403a8c 108 this->m_options = ep.m_options;
Osamu Nakamura 0:ad834d403a8c 109 this->m_endpoint_interface = ep.m_endpoint_interface;
Osamu Nakamura 0:ad834d403a8c 110 this->m_endpoint_security = ep.m_endpoint_security;
Osamu Nakamura 0:ad834d403a8c 111 this->m_endpoint_object_list = ep.m_endpoint_object_list;
Osamu Nakamura 0:ad834d403a8c 112 this->m_device_manager = ep.m_device_manager;
Osamu Nakamura 0:ad834d403a8c 113 this->m_connected = ep.m_connected;
Osamu Nakamura 0:ad834d403a8c 114 this->m_registered = ep.m_registered;
Osamu Nakamura 0:ad834d403a8c 115 this->m_csi = ep.m_csi;
Osamu Nakamura 0:ad834d403a8c 116 this->m_oim = ep.m_oim;
Osamu Nakamura 0:ad834d403a8c 117 }
Osamu Nakamura 0:ad834d403a8c 118
Osamu Nakamura 0:ad834d403a8c 119 // Destructor
Osamu Nakamura 0:ad834d403a8c 120 Endpoint::~Endpoint() {
Osamu Nakamura 0:ad834d403a8c 121 if (this->m_endpoint_interface != NULL)
Osamu Nakamura 0:ad834d403a8c 122 delete this->m_endpoint_interface;
Osamu Nakamura 0:ad834d403a8c 123 if (this->m_endpoint_security != NULL)
Osamu Nakamura 0:ad834d403a8c 124 delete this->m_endpoint_security;
Osamu Nakamura 0:ad834d403a8c 125 }
Osamu Nakamura 0:ad834d403a8c 126
Osamu Nakamura 0:ad834d403a8c 127 // set the device manager
Osamu Nakamura 0:ad834d403a8c 128 void Endpoint::setDeviceManager(void *device_manager) {
Osamu Nakamura 0:ad834d403a8c 129 this->m_device_manager = device_manager;
Osamu Nakamura 0:ad834d403a8c 130 }
Osamu Nakamura 0:ad834d403a8c 131
Osamu Nakamura 0:ad834d403a8c 132 // get the device manager
Osamu Nakamura 0:ad834d403a8c 133 void *Endpoint::getDeviceManager(void) {
Osamu Nakamura 0:ad834d403a8c 134 return this->m_device_manager;
Osamu Nakamura 0:ad834d403a8c 135 }
Osamu Nakamura 0:ad834d403a8c 136
Osamu Nakamura 0:ad834d403a8c 137 // router node behavior setting
Osamu Nakamura 0:ad834d403a8c 138 void Endpoint::asRouterNode(bool canActAsRouterNode) {
Osamu Nakamura 0:ad834d403a8c 139 this->m_canActAsRouterNode = canActAsRouterNode;
Osamu Nakamura 0:ad834d403a8c 140 }
Osamu Nakamura 0:ad834d403a8c 141
Osamu Nakamura 0:ad834d403a8c 142 // set our Options
Osamu Nakamura 0:ad834d403a8c 143 void Endpoint::setOptions(Options *options) {
Osamu Nakamura 0:ad834d403a8c 144 this->m_options = options;
Osamu Nakamura 0:ad834d403a8c 145 }
Osamu Nakamura 0:ad834d403a8c 146
Osamu Nakamura 0:ad834d403a8c 147 // get our Options
Osamu Nakamura 0:ad834d403a8c 148 Options *Endpoint::getOptions() {
Osamu Nakamura 0:ad834d403a8c 149 return this->m_options;
Osamu Nakamura 0:ad834d403a8c 150 }
Osamu Nakamura 0:ad834d403a8c 151
Osamu Nakamura 0:ad834d403a8c 152 // get our Server
Osamu Nakamura 0:ad834d403a8c 153 M2MSecurity *Endpoint::getEndpointSecurity() {
Osamu Nakamura 0:ad834d403a8c 154 return this->m_endpoint_security;
Osamu Nakamura 0:ad834d403a8c 155 }
Osamu Nakamura 0:ad834d403a8c 156
Osamu Nakamura 0:ad834d403a8c 157 // get our ObjectList
Osamu Nakamura 0:ad834d403a8c 158 M2MObjectList Endpoint::getEndpointObjectList() {
Osamu Nakamura 0:ad834d403a8c 159 return this->m_endpoint_object_list;
Osamu Nakamura 0:ad834d403a8c 160 }
Osamu Nakamura 0:ad834d403a8c 161
Osamu Nakamura 0:ad834d403a8c 162 // get our endpoint interface
Osamu Nakamura 0:ad834d403a8c 163 M2MInterface *Endpoint::getEndpointInterface() {
Osamu Nakamura 0:ad834d403a8c 164 return this->m_endpoint_interface;
Osamu Nakamura 0:ad834d403a8c 165 }
Osamu Nakamura 0:ad834d403a8c 166
Osamu Nakamura 0:ad834d403a8c 167 // mbed-client: create our interface
Osamu Nakamura 0:ad834d403a8c 168 void Endpoint::createEndpointInterface() {
Osamu Nakamura 0:ad834d403a8c 169 // get the CoAP listening port
Osamu Nakamura 0:ad834d403a8c 170 uint16_t listening_port = (uint16_t)this->m_options->getConnectorPort();
Osamu Nakamura 0:ad834d403a8c 171
Osamu Nakamura 0:ad834d403a8c 172 // randomize the port if we are using certificates...
Osamu Nakamura 0:ad834d403a8c 173 if (this->m_options->getServerCertificateSize() > 0) {
Osamu Nakamura 0:ad834d403a8c 174 // Randomizing listening port for Certificate mode connectivity
Osamu Nakamura 0:ad834d403a8c 175 srand(time(NULL));
Osamu Nakamura 0:ad834d403a8c 176 listening_port = rand() % 65535 + 12345;
Osamu Nakamura 0:ad834d403a8c 177 }
Osamu Nakamura 0:ad834d403a8c 178
Osamu Nakamura 0:ad834d403a8c 179 // DEBUG
Osamu Nakamura 0:ad834d403a8c 180 //this->logger()->logging("Connector::Endpoint: listening port: %d",listening_port);
Osamu Nakamura 0:ad834d403a8c 181
Osamu Nakamura 0:ad834d403a8c 182 // Socket protocol type: TCP or UDP
Osamu Nakamura 0:ad834d403a8c 183 M2MInterface::BindingMode socket_protocol_type = M2MInterface::UDP;
Osamu Nakamura 0:ad834d403a8c 184 if (this->m_options->getCoAPConnectionType() == COAP_TCP) socket_protocol_type = M2MInterface::TCP;
Osamu Nakamura 0:ad834d403a8c 185
Osamu Nakamura 0:ad834d403a8c 186 // Socket address type: IPv4 or IPv6
Osamu Nakamura 0:ad834d403a8c 187 M2MInterface::NetworkStack socket_address_type = M2MInterface::LwIP_IPv4;
Osamu Nakamura 0:ad834d403a8c 188 if (this->m_options->getIPAddressType() == IP_ADDRESS_TYPE_IPV6) {
Osamu Nakamura 0:ad834d403a8c 189 // IPv6 mode for the socket addressing type...
Osamu Nakamura 0:ad834d403a8c 190 socket_address_type = M2MInterface::LwIP_IPv6;
Osamu Nakamura 0:ad834d403a8c 191
Osamu Nakamura 0:ad834d403a8c 192 #if defined (IPV4_OVERRIDE)
Osamu Nakamura 0:ad834d403a8c 193 // OVERRIDE (until patched...)
Osamu Nakamura 0:ad834d403a8c 194 this->logger()->logging("Connector::Endpoint: Socket Address Type: IPv4 (IPv6 OVERRIDE)");
Osamu Nakamura 0:ad834d403a8c 195 socket_address_type = M2MInterface::LwIP_IPv4;
Osamu Nakamura 0:ad834d403a8c 196 #endif
Osamu Nakamura 0:ad834d403a8c 197 }
Osamu Nakamura 0:ad834d403a8c 198
Osamu Nakamura 0:ad834d403a8c 199 // DEBUG
Osamu Nakamura 0:ad834d403a8c 200 if (socket_protocol_type == M2MInterface::TCP) this->logger()->logging("Connector::Endpoint: Socket Protocol: TCP");
Osamu Nakamura 0:ad834d403a8c 201 if (socket_protocol_type == M2MInterface::UDP) this->logger()->logging("Connector::Endpoint: Socket Protocol: UDP");
Osamu Nakamura 0:ad834d403a8c 202 if (socket_address_type == M2MInterface::LwIP_IPv4) this->logger()->logging("Connector::Endpoint: Socket Address Type: IPv4");
Osamu Nakamura 0:ad834d403a8c 203 if (socket_address_type == M2MInterface::LwIP_IPv6) this->logger()->logging("Connector::Endpoint: Socket Address Type: IPv6");
Osamu Nakamura 0:ad834d403a8c 204
Osamu Nakamura 0:ad834d403a8c 205 // Create the endpoint M2MInterface instance
Osamu Nakamura 0:ad834d403a8c 206 this->m_endpoint_interface = M2MInterfaceFactory::create_interface(*this,
Osamu Nakamura 0:ad834d403a8c 207 (char *)this->m_options->getEndpointNodename().c_str(), // endpoint name
Osamu Nakamura 0:ad834d403a8c 208 (char *)this->m_options->getEndpointType().c_str(), // endpoint type
Osamu Nakamura 0:ad834d403a8c 209 (int32_t)this->m_options->getLifetime(), // registration lifetime (in seconds)
Osamu Nakamura 0:ad834d403a8c 210 listening_port, // listening port (ephemeral...)
Osamu Nakamura 0:ad834d403a8c 211 (char *)this->m_options->getDomain().c_str(), // endpoint domain
Osamu Nakamura 0:ad834d403a8c 212 socket_protocol_type, // Socket protocol type: UDP or TCP...
Osamu Nakamura 0:ad834d403a8c 213 socket_address_type, // Socket addressing type: IPv4 or IPv6
Osamu Nakamura 0:ad834d403a8c 214 CONTEXT_ADDRESS_STRING // context address string (mbedConnectorInterface.h)
Osamu Nakamura 0:ad834d403a8c 215 );
Osamu Nakamura 0:ad834d403a8c 216
Osamu Nakamura 0:ad834d403a8c 217 // bind LWIP network interface pointer...
Osamu Nakamura 0:ad834d403a8c 218 if (__network_interface != NULL && this->m_endpoint_interface != NULL) {
Osamu Nakamura 0:ad834d403a8c 219 this->logger()->logging("Connector::Endpoint: binding LWIP network instance...");
Osamu Nakamura 0:ad834d403a8c 220 this->m_endpoint_interface->set_platform_network_handler((void *)__network_interface);
Osamu Nakamura 0:ad834d403a8c 221 }
Osamu Nakamura 0:ad834d403a8c 222 }
Osamu Nakamura 0:ad834d403a8c 223
Osamu Nakamura 0:ad834d403a8c 224 // mbed-client: createEndpointInstance()
Osamu Nakamura 0:ad834d403a8c 225 M2MSecurity *Endpoint::createEndpointInstance() {
Osamu Nakamura 0:ad834d403a8c 226 // Creates register server object with mbed device server address and other parameters
Osamu Nakamura 0:ad834d403a8c 227 M2MSecurity *server = M2MInterfaceFactory::create_security(M2MSecurity::M2MServer);
Osamu Nakamura 0:ad834d403a8c 228 if (server != NULL) {
Osamu Nakamura 0:ad834d403a8c 229 const String url = this->m_options->getConnectorURL();
Osamu Nakamura 0:ad834d403a8c 230 server->set_resource_value(M2MSecurity::M2MServerUri, url);
Osamu Nakamura 0:ad834d403a8c 231 server->set_resource_value(M2MSecurity::BootstrapServer, false);
Osamu Nakamura 0:ad834d403a8c 232 server->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate);
Osamu Nakamura 0:ad834d403a8c 233 server->set_resource_value(M2MSecurity::ServerPublicKey,this->m_options->getServerCertificate(),this->m_options->getServerCertificateSize());
Osamu Nakamura 0:ad834d403a8c 234 server->set_resource_value(M2MSecurity::PublicKey,this->m_options->getClientCertificate(),this->m_options->getClientCertificateSize());
Osamu Nakamura 0:ad834d403a8c 235 server->set_resource_value(M2MSecurity::Secretkey,this->m_options->getClientKey(),this->m_options->getClientKeySize());
Osamu Nakamura 0:ad834d403a8c 236 }
Osamu Nakamura 0:ad834d403a8c 237 return server;
Osamu Nakamura 0:ad834d403a8c 238 }
Osamu Nakamura 0:ad834d403a8c 239
Osamu Nakamura 0:ad834d403a8c 240 // mbed-client: Callback from mbed client stack if any error is encountered
Osamu Nakamura 0:ad834d403a8c 241 void Endpoint::error(M2MInterface::Error error) {
Osamu Nakamura 0:ad834d403a8c 242 switch(error){
Osamu Nakamura 0:ad834d403a8c 243 case M2MInterface::AlreadyExists:
Osamu Nakamura 0:ad834d403a8c 244 this->logger()->logging("Connector::Endpoint(ERROR): M2MInterface::AlreadyExists");
Osamu Nakamura 0:ad834d403a8c 245 break;
Osamu Nakamura 0:ad834d403a8c 246 case M2MInterface::BootstrapFailed:
Osamu Nakamura 0:ad834d403a8c 247 this->logger()->logging("Connector::Endpoint(ERROR): M2MInterface::BootstrapFailed");
Osamu Nakamura 0:ad834d403a8c 248 break;
Osamu Nakamura 0:ad834d403a8c 249 case M2MInterface::InvalidParameters:
Osamu Nakamura 0:ad834d403a8c 250 this->logger()->logging("Connector::Endpoint(ERROR): M2MInterface::InvalidParameters");
Osamu Nakamura 0:ad834d403a8c 251 break;
Osamu Nakamura 0:ad834d403a8c 252 case M2MInterface::NotRegistered:
Osamu Nakamura 0:ad834d403a8c 253 this->logger()->logging("Connector::Endpoint(ERROR): M2MInterface::NotRegistered");
Osamu Nakamura 0:ad834d403a8c 254 break;
Osamu Nakamura 0:ad834d403a8c 255 case M2MInterface::Timeout:
Osamu Nakamura 0:ad834d403a8c 256 this->logger()->logging("Connector::Endpoint(ERROR): M2MInterface::Timeout");
Osamu Nakamura 0:ad834d403a8c 257 break;
Osamu Nakamura 0:ad834d403a8c 258 case M2MInterface::NetworkError:
Osamu Nakamura 0:ad834d403a8c 259 this->logger()->logging("Connector::Endpoint(ERROR): M2MInterface::NetworkError");
Osamu Nakamura 0:ad834d403a8c 260 break;
Osamu Nakamura 0:ad834d403a8c 261 case M2MInterface::ResponseParseFailed:
Osamu Nakamura 0:ad834d403a8c 262 this->logger()->logging("Connector::Endpoint(ERROR): M2MInterface::ResponseParseFailed");
Osamu Nakamura 0:ad834d403a8c 263 break;
Osamu Nakamura 0:ad834d403a8c 264 case M2MInterface::UnknownError:
Osamu Nakamura 0:ad834d403a8c 265 this->logger()->logging("Connector::Endpoint(ERROR): M2MInterface::UnknownError");
Osamu Nakamura 0:ad834d403a8c 266 break;
Osamu Nakamura 0:ad834d403a8c 267 case M2MInterface::MemoryFail:
Osamu Nakamura 0:ad834d403a8c 268 this->logger()->logging("Connector::Endpoint(ERROR): M2MInterface::MemoryFail");
Osamu Nakamura 0:ad834d403a8c 269 break;
Osamu Nakamura 0:ad834d403a8c 270 case M2MInterface::NotAllowed:
Osamu Nakamura 0:ad834d403a8c 271 this->logger()->logging("Connector::Endpoint(ERROR): M2MInterface::NotAllowed");
Osamu Nakamura 0:ad834d403a8c 272 break;
Osamu Nakamura 0:ad834d403a8c 273 default:
Osamu Nakamura 0:ad834d403a8c 274 break;
Osamu Nakamura 0:ad834d403a8c 275 }
Osamu Nakamura 0:ad834d403a8c 276 }
Osamu Nakamura 0:ad834d403a8c 277
Osamu Nakamura 0:ad834d403a8c 278 // register the endpoint
Osamu Nakamura 0:ad834d403a8c 279 void Endpoint::register_endpoint(M2MSecurity *endpoint_security, M2MObjectList endpoint_objects) {
Osamu Nakamura 0:ad834d403a8c 280 if (this->m_endpoint_interface != NULL && endpoint_security != NULL && endpoint_objects.size() > 0) {
Osamu Nakamura 0:ad834d403a8c 281 // register endpoint
Osamu Nakamura 0:ad834d403a8c 282 this->logger()->logging("Connector::Endpoint: registering endpoint...");
Osamu Nakamura 0:ad834d403a8c 283 this->m_endpoint_interface->register_object(endpoint_security, endpoint_objects);
Osamu Nakamura 0:ad834d403a8c 284 }
Osamu Nakamura 0:ad834d403a8c 285 }
Osamu Nakamura 0:ad834d403a8c 286
Osamu Nakamura 0:ad834d403a8c 287 // re-register the endpoint
Osamu Nakamura 0:ad834d403a8c 288 void Endpoint::re_register_endpoint() {
Osamu Nakamura 0:ad834d403a8c 289 if (this->m_endpoint_interface != NULL) {
Osamu Nakamura 0:ad834d403a8c 290 this->m_endpoint_interface->update_registration(this->m_endpoint_security,this->m_options->getLifetime());
Osamu Nakamura 0:ad834d403a8c 291 }
Osamu Nakamura 0:ad834d403a8c 292 }
Osamu Nakamura 0:ad834d403a8c 293
Osamu Nakamura 0:ad834d403a8c 294 // de-register endpoint
Osamu Nakamura 0:ad834d403a8c 295 void Endpoint::de_register_endpoint(void) {
Osamu Nakamura 0:ad834d403a8c 296 if (this->m_endpoint_interface != NULL) {
Osamu Nakamura 0:ad834d403a8c 297 // de-register endpoint
Osamu Nakamura 0:ad834d403a8c 298 this->logger()->logging("Connector::Endpoint: de-registering endpoint...");
Osamu Nakamura 0:ad834d403a8c 299 this->m_endpoint_interface->unregister_object(NULL);
Osamu Nakamura 0:ad834d403a8c 300 if (this->m_csi != NULL) {
Osamu Nakamura 0:ad834d403a8c 301 this->m_csi->begin_object_unregistering((void *)this);
Osamu Nakamura 0:ad834d403a8c 302 }
Osamu Nakamura 0:ad834d403a8c 303 }
Osamu Nakamura 0:ad834d403a8c 304 }
Osamu Nakamura 0:ad834d403a8c 305
Osamu Nakamura 0:ad834d403a8c 306 // object registered
Osamu Nakamura 0:ad834d403a8c 307 void Endpoint::object_registered(M2MSecurity *security, const M2MServer &server) {
Osamu Nakamura 0:ad834d403a8c 308 this->logger()->logging("Connector::Endpoint: endpoint registered.");
Osamu Nakamura 0:ad834d403a8c 309 this->m_connected = true;
Osamu Nakamura 0:ad834d403a8c 310 this->m_registered = true;
Osamu Nakamura 0:ad834d403a8c 311 if (this->m_csi != NULL) {
Osamu Nakamura 0:ad834d403a8c 312 this->m_csi->object_registered((void *)this,(void *)security,(void *)&server);
Osamu Nakamura 0:ad834d403a8c 313 }
Osamu Nakamura 0:ad834d403a8c 314 }
Osamu Nakamura 0:ad834d403a8c 315
Osamu Nakamura 0:ad834d403a8c 316 // registration updated
Osamu Nakamura 0:ad834d403a8c 317 void Endpoint::registration_updated(M2MSecurity *security, const M2MServer &server) {
Osamu Nakamura 0:ad834d403a8c 318 this->logger()->logging("Connector::Endpoint: endpoint re-registered.");
Osamu Nakamura 0:ad834d403a8c 319 this->m_connected = true;
Osamu Nakamura 0:ad834d403a8c 320 this->m_registered = true;
Osamu Nakamura 0:ad834d403a8c 321 if (this->m_csi != NULL) {
Osamu Nakamura 0:ad834d403a8c 322 this->m_csi->registration_updated((void *)this,(void *)security,(void *)&server);
Osamu Nakamura 0:ad834d403a8c 323 }
Osamu Nakamura 0:ad834d403a8c 324 }
Osamu Nakamura 0:ad834d403a8c 325
Osamu Nakamura 0:ad834d403a8c 326 // object unregistered
Osamu Nakamura 0:ad834d403a8c 327 void Endpoint::object_unregistered(M2MSecurity *server) {
Osamu Nakamura 0:ad834d403a8c 328 // DEBUG
Osamu Nakamura 0:ad834d403a8c 329 this->logger()->logging("Connector::Endpoint: endpoint de-registered.");
Osamu Nakamura 0:ad834d403a8c 330
Osamu Nakamura 0:ad834d403a8c 331 // no longer connected/registered
Osamu Nakamura 0:ad834d403a8c 332 this->m_registered = false;
Osamu Nakamura 0:ad834d403a8c 333 this->m_connected = false;
Osamu Nakamura 0:ad834d403a8c 334
Osamu Nakamura 0:ad834d403a8c 335 // stop all observers...
Osamu Nakamura 0:ad834d403a8c 336 this->stopObservations();
Osamu Nakamura 0:ad834d403a8c 337
Osamu Nakamura 0:ad834d403a8c 338 // invoke ConnectionHandler if we have one...
Osamu Nakamura 0:ad834d403a8c 339 if (this->m_csi != NULL) {
Osamu Nakamura 0:ad834d403a8c 340 this->m_csi->object_unregistered((void *)this,(void *)server);
Osamu Nakamura 0:ad834d403a8c 341 }
Osamu Nakamura 0:ad834d403a8c 342
Osamu Nakamura 0:ad834d403a8c 343 // halt the main event loop... we are done.
Osamu Nakamura 0:ad834d403a8c 344 net_shutdown_endpoint();
Osamu Nakamura 0:ad834d403a8c 345 }
Osamu Nakamura 0:ad834d403a8c 346
Osamu Nakamura 0:ad834d403a8c 347 // bootstrap done
Osamu Nakamura 0:ad834d403a8c 348 void Endpoint::bootstrap_done(M2MSecurity *server) {
Osamu Nakamura 0:ad834d403a8c 349 this->logger()->logging("Connector::Endpoint: endpoint bootstrapped.");
Osamu Nakamura 0:ad834d403a8c 350 if (this->m_csi != NULL) {
Osamu Nakamura 0:ad834d403a8c 351 this->m_csi->bootstrapped((void *)this,(void *)server);
Osamu Nakamura 0:ad834d403a8c 352 }
Osamu Nakamura 0:ad834d403a8c 353 }
Osamu Nakamura 0:ad834d403a8c 354
Osamu Nakamura 0:ad834d403a8c 355 // resource value updated
Osamu Nakamura 0:ad834d403a8c 356 void Endpoint::value_updated(M2MBase *base, M2MBase::BaseType type) {
Osamu Nakamura 0:ad834d403a8c 357 // Lookup the resource and invoke process() on it...
Osamu Nakamura 0:ad834d403a8c 358 DynamicResource *target_res = this->lookupDynamicResource(base);
Osamu Nakamura 0:ad834d403a8c 359 if (target_res != NULL) {
Osamu Nakamura 0:ad834d403a8c 360 // DEBUG
Osamu Nakamura 0:ad834d403a8c 361 //this->logger()->logging("Value Updated (Custom Resource)");
Osamu Nakamura 0:ad834d403a8c 362
Osamu Nakamura 0:ad834d403a8c 363 // its a custom resource...
Osamu Nakamura 0:ad834d403a8c 364 target_res->process(base->operation(),type);
Osamu Nakamura 0:ad834d403a8c 365 }
Osamu Nakamura 0:ad834d403a8c 366 else {
Osamu Nakamura 0:ad834d403a8c 367 // DEBUG
Osamu Nakamura 0:ad834d403a8c 368 //this->logger()->logging("Value Updated (Device Manager)");
Osamu Nakamura 0:ad834d403a8c 369
Osamu Nakamura 0:ad834d403a8c 370 // let DeviceManager handle it
Osamu Nakamura 0:ad834d403a8c 371 ((DeviceManager *)this->m_device_manager)->process(base,type);
Osamu Nakamura 0:ad834d403a8c 372 }
Osamu Nakamura 0:ad834d403a8c 373
Osamu Nakamura 0:ad834d403a8c 374 // CSI
Osamu Nakamura 0:ad834d403a8c 375 if (this->m_csi != NULL) {
Osamu Nakamura 0:ad834d403a8c 376 this->m_csi->value_updated((void *)this,(void *)base,(int)type);
Osamu Nakamura 0:ad834d403a8c 377 }
Osamu Nakamura 0:ad834d403a8c 378 }
Osamu Nakamura 0:ad834d403a8c 379
Osamu Nakamura 0:ad834d403a8c 380 // lookup which DynamicResource cooresponds to a given M2MBase instance...
Osamu Nakamura 0:ad834d403a8c 381 DynamicResource *Endpoint::lookupDynamicResource(M2MBase *base) {
Osamu Nakamura 0:ad834d403a8c 382 const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList();
Osamu Nakamura 0:ad834d403a8c 383 for(int i=0; i<(int)dynamic_resources->size(); ++i) {
Osamu Nakamura 0:ad834d403a8c 384 M2MBase *t = (M2MBase *)dynamic_resources->at(i)->getResource();
Osamu Nakamura 0:ad834d403a8c 385 if (t == base) {
Osamu Nakamura 0:ad834d403a8c 386 return dynamic_resources->at(i);
Osamu Nakamura 0:ad834d403a8c 387 }
Osamu Nakamura 0:ad834d403a8c 388 }
Osamu Nakamura 0:ad834d403a8c 389 return NULL;
Osamu Nakamura 0:ad834d403a8c 390 }
Osamu Nakamura 0:ad834d403a8c 391
Osamu Nakamura 0:ad834d403a8c 392 // build out the endpoint
Osamu Nakamura 0:ad834d403a8c 393 void Endpoint::buildEndpoint()
Osamu Nakamura 0:ad834d403a8c 394 {
Osamu Nakamura 0:ad834d403a8c 395 // initialize as an mbed-client
Osamu Nakamura 0:ad834d403a8c 396 this->createEndpointInterface();
Osamu Nakamura 0:ad834d403a8c 397
Osamu Nakamura 0:ad834d403a8c 398 // Create our server instance
Osamu Nakamura 0:ad834d403a8c 399 this->m_endpoint_security = this->createEndpointInstance();
Osamu Nakamura 0:ad834d403a8c 400
Osamu Nakamura 0:ad834d403a8c 401 // We now have to bind our device resources
Osamu Nakamura 0:ad834d403a8c 402 if (this->m_device_manager != NULL) {
Osamu Nakamura 0:ad834d403a8c 403 // DEBUG
Osamu Nakamura 0:ad834d403a8c 404 this->logger()->logging("Connector::Endpoint::build(): plumbing the device management objects and resources...");
Osamu Nakamura 0:ad834d403a8c 405
Osamu Nakamura 0:ad834d403a8c 406 // bind the device manager
Osamu Nakamura 0:ad834d403a8c 407 ((DeviceManager *)this->m_device_manager)->bind();
Osamu Nakamura 0:ad834d403a8c 408
Osamu Nakamura 0:ad834d403a8c 409 // push back the Device Resources Object
Osamu Nakamura 0:ad834d403a8c 410 if (this->m_options->getDeviceResourcesObject() != NULL) {
Osamu Nakamura 0:ad834d403a8c 411 // DEBUG
Osamu Nakamura 0:ad834d403a8c 412 this->logger()->logging("Connector::Endpoint::build(): plumbing device resources object...");
Osamu Nakamura 0:ad834d403a8c 413
Osamu Nakamura 0:ad834d403a8c 414 // push back the device resources object
Osamu Nakamura 0:ad834d403a8c 415 this->m_endpoint_object_list.push_back((M2MObject *)this->m_options->getDeviceResourcesObject());
Osamu Nakamura 0:ad834d403a8c 416 }
Osamu Nakamura 0:ad834d403a8c 417 else {
Osamu Nakamura 0:ad834d403a8c 418 // unable to plumb device manager
Osamu Nakamura 0:ad834d403a8c 419 this->logger()->logging("Connector::Endpoint::build(): Unable to plumb device resources. Not installing device resource object...");
Osamu Nakamura 0:ad834d403a8c 420 }
Osamu Nakamura 0:ad834d403a8c 421
Osamu Nakamura 0:ad834d403a8c 422 // push back the Firmware Resources Object
Osamu Nakamura 0:ad834d403a8c 423 if (this->m_options->getFirmwareResourcesObject() != NULL) {
Osamu Nakamura 0:ad834d403a8c 424 // DEBUG
Osamu Nakamura 0:ad834d403a8c 425 this->logger()->logging("Connector::Endpoint::build(): plumbing firmware resources object...");
Osamu Nakamura 0:ad834d403a8c 426
Osamu Nakamura 0:ad834d403a8c 427 // push back the firmware resources object
Osamu Nakamura 0:ad834d403a8c 428 this->m_endpoint_object_list.push_back((M2MObject *)this->m_options->getFirmwareResourcesObject());
Osamu Nakamura 0:ad834d403a8c 429 }
Osamu Nakamura 0:ad834d403a8c 430 else {
Osamu Nakamura 0:ad834d403a8c 431 // unable to plumb firmware manager
Osamu Nakamura 0:ad834d403a8c 432 this->logger()->logging("Connector::Endpoint::build(): Unable to plumb firmware resources. Not installing firmware resource object...");
Osamu Nakamura 0:ad834d403a8c 433 }
Osamu Nakamura 0:ad834d403a8c 434 }
Osamu Nakamura 0:ad834d403a8c 435 else {
Osamu Nakamura 0:ad834d403a8c 436 // no device manager installed
Osamu Nakamura 0:ad834d403a8c 437 this->logger()->logging("Connector::Endpoint::build(): No device manager installed.");
Osamu Nakamura 0:ad834d403a8c 438 }
Osamu Nakamura 0:ad834d403a8c 439
Osamu Nakamura 0:ad834d403a8c 440 // Loop through Static Resources and bind each of them...
Osamu Nakamura 0:ad834d403a8c 441 this->logger()->logging("Connector::Endpoint::build(): adding static resources...");
Osamu Nakamura 0:ad834d403a8c 442 const StaticResourcesList *static_resources = this->m_options->getStaticResourceList();
Osamu Nakamura 0:ad834d403a8c 443 for(int i=0; i<(int)static_resources->size(); ++i) {
Osamu Nakamura 0:ad834d403a8c 444 this->logger()->logging("Connector::Endpoint::build(): binding static resource: [%s]...",static_resources->at(i)->getFullName().c_str());
Osamu Nakamura 0:ad834d403a8c 445 static_resources->at(i)->bind(this);
Osamu Nakamura 0:ad834d403a8c 446 }
Osamu Nakamura 0:ad834d403a8c 447
Osamu Nakamura 0:ad834d403a8c 448 // Loop through Dynamic Resources and bind each of them...
Osamu Nakamura 0:ad834d403a8c 449 this->logger()->logging("Connector::Endpoint::build(): adding dynamic resources...");
Osamu Nakamura 0:ad834d403a8c 450 const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList();
Osamu Nakamura 0:ad834d403a8c 451 for(int i=0; i<(int)dynamic_resources->size(); ++i) {
Osamu Nakamura 0:ad834d403a8c 452 this->logger()->logging("Connector::Endpoint::build(): binding dynamic resource: [%s]...",dynamic_resources->at(i)->getFullName().c_str());
Osamu Nakamura 0:ad834d403a8c 453 dynamic_resources->at(i)->bind(this);
Osamu Nakamura 0:ad834d403a8c 454 }
Osamu Nakamura 0:ad834d403a8c 455
Osamu Nakamura 0:ad834d403a8c 456 // Get the ObjectList from the ObjectInstanceManager...
Osamu Nakamura 0:ad834d403a8c 457 NamedPointerList list = this->getObjectInstanceManager()->getObjectList();
Osamu Nakamura 0:ad834d403a8c 458
Osamu Nakamura 0:ad834d403a8c 459 // DEBUG
Osamu Nakamura 0:ad834d403a8c 460 //this->logger()->logging("Endpoint::build(): All Resources bound. Number of Objects in list: %d",list.size());
Osamu Nakamura 0:ad834d403a8c 461
Osamu Nakamura 0:ad834d403a8c 462 // add all of the object instances we have created...
Osamu Nakamura 0:ad834d403a8c 463 for(int i=0;i<(int)list.size();++i) {
Osamu Nakamura 0:ad834d403a8c 464 // DEBUG
Osamu Nakamura 0:ad834d403a8c 465 //this->logger()->logging("Endpoint::build(): adding Object Instance with ObjID: %s...",list.at(i).name().c_str());
Osamu Nakamura 0:ad834d403a8c 466
Osamu Nakamura 0:ad834d403a8c 467 // push back the object instance...
Osamu Nakamura 0:ad834d403a8c 468 this->m_endpoint_object_list.push_back((M2MObject *)(list.at(i).ptr()));
Osamu Nakamura 0:ad834d403a8c 469 }
Osamu Nakamura 0:ad834d403a8c 470 }
Osamu Nakamura 0:ad834d403a8c 471
Osamu Nakamura 0:ad834d403a8c 472 // stop underlying observation mechanisms
Osamu Nakamura 0:ad834d403a8c 473 void Endpoint::stopObservations() {
Osamu Nakamura 0:ad834d403a8c 474 const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList();
Osamu Nakamura 0:ad834d403a8c 475 for(int i=0; i<(int)dynamic_resources->size(); ++i) {
Osamu Nakamura 0:ad834d403a8c 476 if (dynamic_resources->at(i)->isObservable() == true) {
Osamu Nakamura 0:ad834d403a8c 477 ResourceObserver *observer = (ResourceObserver *)dynamic_resources->at(i)->getObserver();
Osamu Nakamura 0:ad834d403a8c 478 if (observer != NULL) {
Osamu Nakamura 0:ad834d403a8c 479 this->logger()->logging("Connector::Endpoint::stopObservations(): stopping resource observer for: [%s]...",dynamic_resources->at(i)->getFullName().c_str());
Osamu Nakamura 0:ad834d403a8c 480 observer->halt();
Osamu Nakamura 0:ad834d403a8c 481 }
Osamu Nakamura 0:ad834d403a8c 482 }
Osamu Nakamura 0:ad834d403a8c 483 }
Osamu Nakamura 0:ad834d403a8c 484 }
Osamu Nakamura 0:ad834d403a8c 485
Osamu Nakamura 0:ad834d403a8c 486 // underlying network is connected (SET)
Osamu Nakamura 0:ad834d403a8c 487 void Endpoint::isConnected(bool connected) {
Osamu Nakamura 0:ad834d403a8c 488 this->m_connected = connected;
Osamu Nakamura 0:ad834d403a8c 489 }
Osamu Nakamura 0:ad834d403a8c 490
Osamu Nakamura 0:ad834d403a8c 491 // underlying network is connected (GET)
Osamu Nakamura 0:ad834d403a8c 492 bool Endpoint::isConnected() {
Osamu Nakamura 0:ad834d403a8c 493 return this->m_connected;
Osamu Nakamura 0:ad834d403a8c 494 }
Osamu Nakamura 0:ad834d403a8c 495
Osamu Nakamura 0:ad834d403a8c 496 // Registered with mDC/mDS
Osamu Nakamura 0:ad834d403a8c 497 bool Endpoint::isRegistered() {
Osamu Nakamura 0:ad834d403a8c 498 return this->m_registered;
Osamu Nakamura 0:ad834d403a8c 499 }
Osamu Nakamura 0:ad834d403a8c 500
Osamu Nakamura 0:ad834d403a8c 501 // Set the ConnectionStatusInterface
Osamu Nakamura 0:ad834d403a8c 502 void Endpoint::setConnectionStatusInterfaceImpl(ConnectionStatusInterface *csi) {
Osamu Nakamura 0:ad834d403a8c 503 this->m_csi = csi;
Osamu Nakamura 0:ad834d403a8c 504 }
Osamu Nakamura 0:ad834d403a8c 505
Osamu Nakamura 0:ad834d403a8c 506 // Set our ObjectInstanceManager
Osamu Nakamura 0:ad834d403a8c 507 void Endpoint::setObjectInstanceManager(ObjectInstanceManager *oim) {
Osamu Nakamura 0:ad834d403a8c 508 this->m_oim = oim;
Osamu Nakamura 0:ad834d403a8c 509 }
Osamu Nakamura 0:ad834d403a8c 510
Osamu Nakamura 0:ad834d403a8c 511 // Get our ObjectInstanceManager
Osamu Nakamura 0:ad834d403a8c 512 ObjectInstanceManager *Endpoint::getObjectInstanceManager() {
Osamu Nakamura 0:ad834d403a8c 513 return this->m_oim;
Osamu Nakamura 0:ad834d403a8c 514 }
Osamu Nakamura 0:ad834d403a8c 515
Osamu Nakamura 0:ad834d403a8c 516 // our logger
Osamu Nakamura 0:ad834d403a8c 517 Logger *Endpoint::logger()
Osamu Nakamura 0:ad834d403a8c 518 {
Osamu Nakamura 0:ad834d403a8c 519 return this->m_logger;
Osamu Nakamura 0:ad834d403a8c 520 }
Osamu Nakamura 0:ad834d403a8c 521
Osamu Nakamura 0:ad834d403a8c 522 } // namespace Connector