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 DeviceManagementResponder.cpp
Osamu Nakamura 0:ad834d403a8c 3 * @brief mbed CoAP Endpoint Device Management Responder class
Osamu Nakamura 0:ad834d403a8c 4 * @author Doug Anson
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) 2016
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 // Class support
Osamu Nakamura 0:ad834d403a8c 24 #include "mbed-connector-interface/DeviceManagementResponder.h"
Osamu Nakamura 0:ad834d403a8c 25
Osamu Nakamura 0:ad834d403a8c 26 // Endpoint support
Osamu Nakamura 0:ad834d403a8c 27 #include "mbed-connector-interface/ConnectorEndpoint.h"
Osamu Nakamura 0:ad834d403a8c 28
Osamu Nakamura 0:ad834d403a8c 29 // DeviceManager Support
Osamu Nakamura 0:ad834d403a8c 30 #include "mbed-connector-interface/DeviceManager.h"
Osamu Nakamura 0:ad834d403a8c 31
Osamu Nakamura 0:ad834d403a8c 32 // constructor
Osamu Nakamura 0:ad834d403a8c 33 DeviceManagementResponder::DeviceManagementResponder(const Logger *logger,const Authenticator *authenticator) {
Osamu Nakamura 0:ad834d403a8c 34 this->m_logger = (Logger *)logger;
Osamu Nakamura 0:ad834d403a8c 35 this->m_authenticator = (Authenticator *)authenticator;
Osamu Nakamura 0:ad834d403a8c 36 this->m_endpoint = NULL;
Osamu Nakamura 0:ad834d403a8c 37 this->m_initialize_fn = NULL;
Osamu Nakamura 0:ad834d403a8c 38 this->m_reboot_responder_fn = NULL;
Osamu Nakamura 0:ad834d403a8c 39 this->m_reset_responder_fn = NULL;
Osamu Nakamura 0:ad834d403a8c 40 this->m_fota_manifest_fn = NULL;
Osamu Nakamura 0:ad834d403a8c 41 this->m_fota_image_set_fn = NULL;
Osamu Nakamura 0:ad834d403a8c 42 this->m_fota_invocation_fn = NULL;
Osamu Nakamura 0:ad834d403a8c 43 this->m_manifest = NULL;
Osamu Nakamura 0:ad834d403a8c 44 this->m_manifest_length = 0;
Osamu Nakamura 0:ad834d403a8c 45 this->m_fota_image = NULL;
Osamu Nakamura 0:ad834d403a8c 46 this->m_fota_image_length = 0;
Osamu Nakamura 0:ad834d403a8c 47 }
Osamu Nakamura 0:ad834d403a8c 48
Osamu Nakamura 0:ad834d403a8c 49 // copy constructor
Osamu Nakamura 0:ad834d403a8c 50 DeviceManagementResponder::DeviceManagementResponder(const DeviceManagementResponder &responder) {
Osamu Nakamura 0:ad834d403a8c 51 this->m_logger = responder.m_logger;
Osamu Nakamura 0:ad834d403a8c 52 this->m_authenticator = responder.m_authenticator;
Osamu Nakamura 0:ad834d403a8c 53 this->m_endpoint = responder.m_endpoint;
Osamu Nakamura 0:ad834d403a8c 54 this->m_initialize_fn = responder.m_initialize_fn;
Osamu Nakamura 0:ad834d403a8c 55 this->m_reboot_responder_fn = responder.m_reboot_responder_fn;
Osamu Nakamura 0:ad834d403a8c 56 this->m_reset_responder_fn = responder.m_reset_responder_fn;
Osamu Nakamura 0:ad834d403a8c 57 this->m_fota_manifest_fn = responder.m_fota_manifest_fn;
Osamu Nakamura 0:ad834d403a8c 58 this->m_fota_image_set_fn = responder.m_fota_image_set_fn;
Osamu Nakamura 0:ad834d403a8c 59 this->m_fota_invocation_fn = responder.m_fota_invocation_fn;
Osamu Nakamura 0:ad834d403a8c 60 this->m_manifest = responder.m_manifest;
Osamu Nakamura 0:ad834d403a8c 61 this->m_manifest_length = responder.m_manifest_length;
Osamu Nakamura 0:ad834d403a8c 62 this->m_fota_image = responder.m_fota_image;
Osamu Nakamura 0:ad834d403a8c 63 this->m_fota_image_length = responder.m_fota_image_length;
Osamu Nakamura 0:ad834d403a8c 64 }
Osamu Nakamura 0:ad834d403a8c 65
Osamu Nakamura 0:ad834d403a8c 66 // destructor
Osamu Nakamura 0:ad834d403a8c 67 DeviceManagementResponder::~DeviceManagementResponder() {
Osamu Nakamura 0:ad834d403a8c 68 }
Osamu Nakamura 0:ad834d403a8c 69
Osamu Nakamura 0:ad834d403a8c 70 // set the Endpoint
Osamu Nakamura 0:ad834d403a8c 71 void DeviceManagementResponder::setEndpoint(const void *ep) {
Osamu Nakamura 0:ad834d403a8c 72 this->m_endpoint = (void *)ep;
Osamu Nakamura 0:ad834d403a8c 73 }
Osamu Nakamura 0:ad834d403a8c 74
Osamu Nakamura 0:ad834d403a8c 75 // authenticate
Osamu Nakamura 0:ad834d403a8c 76 bool DeviceManagementResponder::authenticate(const void *challenge) {
Osamu Nakamura 0:ad834d403a8c 77 if (this->m_authenticator != NULL) {
Osamu Nakamura 0:ad834d403a8c 78 return this->m_authenticator->authenticate((void *)challenge);
Osamu Nakamura 0:ad834d403a8c 79 }
Osamu Nakamura 0:ad834d403a8c 80 return false;
Osamu Nakamura 0:ad834d403a8c 81 }
Osamu Nakamura 0:ad834d403a8c 82
Osamu Nakamura 0:ad834d403a8c 83 // set the Initialize handler
Osamu Nakamura 0:ad834d403a8c 84 void DeviceManagementResponder::setInitializeHandler(initialize_fn initialize_fn) {
Osamu Nakamura 0:ad834d403a8c 85 this->m_initialize_fn = initialize_fn;
Osamu Nakamura 0:ad834d403a8c 86 if (this->m_initialize_fn != NULL) {
Osamu Nakamura 0:ad834d403a8c 87 (*this->m_initialize_fn)(this->m_logger);
Osamu Nakamura 0:ad834d403a8c 88 }
Osamu Nakamura 0:ad834d403a8c 89 }
Osamu Nakamura 0:ad834d403a8c 90
Osamu Nakamura 0:ad834d403a8c 91 // set the Reboot Responder handler
Osamu Nakamura 0:ad834d403a8c 92 void DeviceManagementResponder::setRebootResponderHandler(responder_fn reboot_responder_fn) {
Osamu Nakamura 0:ad834d403a8c 93 this->m_reboot_responder_fn = reboot_responder_fn;
Osamu Nakamura 0:ad834d403a8c 94 }
Osamu Nakamura 0:ad834d403a8c 95
Osamu Nakamura 0:ad834d403a8c 96 // set the Reset Responder handler
Osamu Nakamura 0:ad834d403a8c 97 void DeviceManagementResponder::setResetResponderHandler(responder_fn reset_responder_fn) {
Osamu Nakamura 0:ad834d403a8c 98 this->m_reset_responder_fn = reset_responder_fn;
Osamu Nakamura 0:ad834d403a8c 99 }
Osamu Nakamura 0:ad834d403a8c 100
Osamu Nakamura 0:ad834d403a8c 101 // set the FOTA manifest handler
Osamu Nakamura 0:ad834d403a8c 102 void DeviceManagementResponder::setFOTAManifestHandler(manifest_fn fota_manifest_fn) {
Osamu Nakamura 0:ad834d403a8c 103 this->m_fota_manifest_fn = fota_manifest_fn;
Osamu Nakamura 0:ad834d403a8c 104 }
Osamu Nakamura 0:ad834d403a8c 105
Osamu Nakamura 0:ad834d403a8c 106 // set the FOTA image set handler
Osamu Nakamura 0:ad834d403a8c 107 void DeviceManagementResponder::setFOTAImageHandler(image_set_fn fota_image_set_fn) {
Osamu Nakamura 0:ad834d403a8c 108 this->m_fota_image_set_fn = fota_image_set_fn;
Osamu Nakamura 0:ad834d403a8c 109 }
Osamu Nakamura 0:ad834d403a8c 110
Osamu Nakamura 0:ad834d403a8c 111 // set the FOTA invocation handler
Osamu Nakamura 0:ad834d403a8c 112 void DeviceManagementResponder::setFOTAInvocationHandler(responder_fn fota_invocation_fn) {
Osamu Nakamura 0:ad834d403a8c 113 this->m_fota_invocation_fn = fota_invocation_fn;
Osamu Nakamura 0:ad834d403a8c 114 }
Osamu Nakamura 0:ad834d403a8c 115
Osamu Nakamura 0:ad834d403a8c 116 // set the FOTA manifest
Osamu Nakamura 0:ad834d403a8c 117 void DeviceManagementResponder::setFOTAManifest(char *manifest,uint32_t manifest_length) {
Osamu Nakamura 0:ad834d403a8c 118 this->m_manifest = manifest;
Osamu Nakamura 0:ad834d403a8c 119 this->m_manifest_length = manifest_length;
Osamu Nakamura 0:ad834d403a8c 120 if (this->m_fota_manifest_fn != NULL) {
Osamu Nakamura 0:ad834d403a8c 121 (*this->m_fota_manifest_fn)(this->m_endpoint,this->m_logger,this->m_manifest,this->m_manifest_length);
Osamu Nakamura 0:ad834d403a8c 122 }
Osamu Nakamura 0:ad834d403a8c 123 }
Osamu Nakamura 0:ad834d403a8c 124
Osamu Nakamura 0:ad834d403a8c 125 // get the FOTA manifest
Osamu Nakamura 0:ad834d403a8c 126 char *DeviceManagementResponder::getFOTAManifest() {
Osamu Nakamura 0:ad834d403a8c 127 return this->m_manifest;
Osamu Nakamura 0:ad834d403a8c 128 }
Osamu Nakamura 0:ad834d403a8c 129
Osamu Nakamura 0:ad834d403a8c 130 // get the FOTA manifest
Osamu Nakamura 0:ad834d403a8c 131 uint32_t DeviceManagementResponder::getFOTAManifestLength() {
Osamu Nakamura 0:ad834d403a8c 132 return this->m_manifest_length;
Osamu Nakamura 0:ad834d403a8c 133 }
Osamu Nakamura 0:ad834d403a8c 134
Osamu Nakamura 0:ad834d403a8c 135 // set the FOTA Image
Osamu Nakamura 0:ad834d403a8c 136 void DeviceManagementResponder::setFOTAImage(void *fota_image,uint32_t fota_image_length) {
Osamu Nakamura 0:ad834d403a8c 137 this->m_fota_image = fota_image;
Osamu Nakamura 0:ad834d403a8c 138 this->m_fota_image_length = fota_image_length;
Osamu Nakamura 0:ad834d403a8c 139 if (this->m_fota_image_set_fn != NULL) {
Osamu Nakamura 0:ad834d403a8c 140 (*this->m_fota_image_set_fn)(this->m_endpoint,this->m_logger,this->m_fota_image,this->m_fota_image_length);
Osamu Nakamura 0:ad834d403a8c 141 }
Osamu Nakamura 0:ad834d403a8c 142 }
Osamu Nakamura 0:ad834d403a8c 143
Osamu Nakamura 0:ad834d403a8c 144 // get the FOTA Image
Osamu Nakamura 0:ad834d403a8c 145 void *DeviceManagementResponder::getFOTAImage() {
Osamu Nakamura 0:ad834d403a8c 146 return this->m_fota_image;
Osamu Nakamura 0:ad834d403a8c 147 }
Osamu Nakamura 0:ad834d403a8c 148
Osamu Nakamura 0:ad834d403a8c 149 // get the FOTA Image Length
Osamu Nakamura 0:ad834d403a8c 150 uint32_t DeviceManagementResponder::getFOTAImageLength() {
Osamu Nakamura 0:ad834d403a8c 151 return this->m_fota_image_length;
Osamu Nakamura 0:ad834d403a8c 152 }
Osamu Nakamura 0:ad834d403a8c 153
Osamu Nakamura 0:ad834d403a8c 154 // ACTION: deregister device
Osamu Nakamura 0:ad834d403a8c 155 void DeviceManagementResponder::deregisterDevice(const void *challenge) {
Osamu Nakamura 0:ad834d403a8c 156 // check endpoint
Osamu Nakamura 0:ad834d403a8c 157 if (this->m_endpoint != NULL) {
Osamu Nakamura 0:ad834d403a8c 158 // authenticate
Osamu Nakamura 0:ad834d403a8c 159 if (this->authenticate(challenge)) {
Osamu Nakamura 0:ad834d403a8c 160 // DEBUG
Osamu Nakamura 0:ad834d403a8c 161 this->m_logger->logging("DeviceManagementResponder(deregister): de-registering device...");
Osamu Nakamura 0:ad834d403a8c 162
Osamu Nakamura 0:ad834d403a8c 163 // act
Osamu Nakamura 0:ad834d403a8c 164 ((Connector::Endpoint *)this->m_endpoint)->de_register_endpoint();
Osamu Nakamura 0:ad834d403a8c 165 }
Osamu Nakamura 0:ad834d403a8c 166 else {
Osamu Nakamura 0:ad834d403a8c 167 // authentication failure
Osamu Nakamura 0:ad834d403a8c 168 this->m_logger->logging("DeviceManagementResponder(deregister): authentication failed. No action taken.");
Osamu Nakamura 0:ad834d403a8c 169 }
Osamu Nakamura 0:ad834d403a8c 170 }
Osamu Nakamura 0:ad834d403a8c 171 else {
Osamu Nakamura 0:ad834d403a8c 172 // no endpoint
Osamu Nakamura 0:ad834d403a8c 173 this->m_logger->logging("DeviceManagementResponder(deregister): No endpoint instance. No action taken.");
Osamu Nakamura 0:ad834d403a8c 174 }
Osamu Nakamura 0:ad834d403a8c 175 }
Osamu Nakamura 0:ad834d403a8c 176
Osamu Nakamura 0:ad834d403a8c 177 // ACTION: reboot device
Osamu Nakamura 0:ad834d403a8c 178 void DeviceManagementResponder::rebootDevice(const void *challenge) {
Osamu Nakamura 0:ad834d403a8c 179 // check our Reboot Responder handler pointer
Osamu Nakamura 0:ad834d403a8c 180 if (this->m_reboot_responder_fn != NULL) {
Osamu Nakamura 0:ad834d403a8c 181 // check endpoint
Osamu Nakamura 0:ad834d403a8c 182 if (this->m_endpoint != NULL) {
Osamu Nakamura 0:ad834d403a8c 183 // authenticate
Osamu Nakamura 0:ad834d403a8c 184 if (this->authenticate(challenge)) {
Osamu Nakamura 0:ad834d403a8c 185 // act
Osamu Nakamura 0:ad834d403a8c 186 (*this->m_reboot_responder_fn)((const void *)this->m_endpoint,(const void *)this->m_logger,NULL);
Osamu Nakamura 0:ad834d403a8c 187 }
Osamu Nakamura 0:ad834d403a8c 188 else {
Osamu Nakamura 0:ad834d403a8c 189 // authentication failure
Osamu Nakamura 0:ad834d403a8c 190 this->m_logger->logging("DeviceManagementResponder(reboot): authentication failed. No action taken.");
Osamu Nakamura 0:ad834d403a8c 191 }
Osamu Nakamura 0:ad834d403a8c 192 }
Osamu Nakamura 0:ad834d403a8c 193 else {
Osamu Nakamura 0:ad834d403a8c 194 // no endpoint
Osamu Nakamura 0:ad834d403a8c 195 this->m_logger->logging("DeviceManagementResponder(reboot): No endpoint instance. No action taken.");
Osamu Nakamura 0:ad834d403a8c 196 }
Osamu Nakamura 0:ad834d403a8c 197 }
Osamu Nakamura 0:ad834d403a8c 198 else {
Osamu Nakamura 0:ad834d403a8c 199 // no reset responder handler
Osamu Nakamura 0:ad834d403a8c 200 this->m_logger->logging("DeviceManagementResponder(reboot): No reboot responder handler pointer. No action taken.");
Osamu Nakamura 0:ad834d403a8c 201 }
Osamu Nakamura 0:ad834d403a8c 202 }
Osamu Nakamura 0:ad834d403a8c 203
Osamu Nakamura 0:ad834d403a8c 204 // ACTION: reset device
Osamu Nakamura 0:ad834d403a8c 205 void DeviceManagementResponder::resetDevice(const void *challenge) {
Osamu Nakamura 0:ad834d403a8c 206 // check our Reset Responder handler pointer
Osamu Nakamura 0:ad834d403a8c 207 if (this->m_reset_responder_fn != NULL) {
Osamu Nakamura 0:ad834d403a8c 208 // check endpoint
Osamu Nakamura 0:ad834d403a8c 209 if (this->m_endpoint != NULL) {
Osamu Nakamura 0:ad834d403a8c 210 // authenticate
Osamu Nakamura 0:ad834d403a8c 211 if (this->authenticate(challenge)) {
Osamu Nakamura 0:ad834d403a8c 212 // act
Osamu Nakamura 0:ad834d403a8c 213 (*this->m_reset_responder_fn)((const void *)this->m_endpoint,(const void *)this->m_logger,NULL);
Osamu Nakamura 0:ad834d403a8c 214 }
Osamu Nakamura 0:ad834d403a8c 215 else {
Osamu Nakamura 0:ad834d403a8c 216 // authentication failure
Osamu Nakamura 0:ad834d403a8c 217 this->m_logger->logging("DeviceManagementResponder(reset): authentication failed. No action taken.");
Osamu Nakamura 0:ad834d403a8c 218 }
Osamu Nakamura 0:ad834d403a8c 219 }
Osamu Nakamura 0:ad834d403a8c 220 else {
Osamu Nakamura 0:ad834d403a8c 221 // no endpoint
Osamu Nakamura 0:ad834d403a8c 222 this->m_logger->logging("DeviceManagementResponder(reset): No endpoint instance. No action taken.");
Osamu Nakamura 0:ad834d403a8c 223 }
Osamu Nakamura 0:ad834d403a8c 224 }
Osamu Nakamura 0:ad834d403a8c 225 else {
Osamu Nakamura 0:ad834d403a8c 226 // no reset responder handler
Osamu Nakamura 0:ad834d403a8c 227 this->m_logger->logging("DeviceManagementResponder(reset): No reset responder handler pointer. No action taken.");
Osamu Nakamura 0:ad834d403a8c 228 }
Osamu Nakamura 0:ad834d403a8c 229 }
Osamu Nakamura 0:ad834d403a8c 230
Osamu Nakamura 0:ad834d403a8c 231 // ACTION: invoke FOTA
Osamu Nakamura 0:ad834d403a8c 232 void DeviceManagementResponder::invokeFOTA(const void *challenge) {
Osamu Nakamura 0:ad834d403a8c 233 // check our FOTA invocation handler pointer
Osamu Nakamura 0:ad834d403a8c 234 if (this->m_fota_invocation_fn != NULL) {
Osamu Nakamura 0:ad834d403a8c 235 // check endpoint
Osamu Nakamura 0:ad834d403a8c 236 if (this->m_endpoint != NULL) {
Osamu Nakamura 0:ad834d403a8c 237 // authenticate
Osamu Nakamura 0:ad834d403a8c 238 if (this->authenticate(challenge)) {
Osamu Nakamura 0:ad834d403a8c 239 // act
Osamu Nakamura 0:ad834d403a8c 240 (*this->m_fota_invocation_fn)((const void *)this->m_endpoint,(const void *)this->m_logger,this->getFOTAManifest());
Osamu Nakamura 0:ad834d403a8c 241 }
Osamu Nakamura 0:ad834d403a8c 242 else {
Osamu Nakamura 0:ad834d403a8c 243 // authentication failure
Osamu Nakamura 0:ad834d403a8c 244 this->m_logger->logging("DeviceManagementResponder(FOTA): authentication failed. No action taken.");
Osamu Nakamura 0:ad834d403a8c 245 }
Osamu Nakamura 0:ad834d403a8c 246 }
Osamu Nakamura 0:ad834d403a8c 247 else {
Osamu Nakamura 0:ad834d403a8c 248 // no endpoint
Osamu Nakamura 0:ad834d403a8c 249 this->m_logger->logging("DeviceManagementResponder(FOTA): No endpoint instance. No action taken.");
Osamu Nakamura 0:ad834d403a8c 250 }
Osamu Nakamura 0:ad834d403a8c 251 }
Osamu Nakamura 0:ad834d403a8c 252 else {
Osamu Nakamura 0:ad834d403a8c 253 // no FOTA invocation handler
Osamu Nakamura 0:ad834d403a8c 254 this->m_logger->logging("DeviceManagementResponder(FOTA): No FOTA invocation handler pointer. No action taken.");
Osamu Nakamura 0:ad834d403a8c 255 }
Osamu Nakamura 0:ad834d403a8c 256 }