Mbed Client sample for GR-LYCHEE where ZXing is incorporated.

Dependencies:   DisplayApp AsciiFont

Fork of GR-PEACH_mbed-os-client-ZXingSample by Renesas

Overview

This sample program shows how to use mbed Client together with ZXing which is an open-source, multi-format 1D/2D barcode image processing library. For more info on ZXing, please refer to https://github.com/zxing/zxing.

Required hardware

Application setup

  1. Select the connection type. For details, please refer to the following wiki:
    https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Connection-type.
  2. Set the client credentials. For details, please refer to the following wiki:
    https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Client-credentials.
  3. Change Wifi settings. For details, please refer to the following wiki:
    https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Wifi-settings.

Building the example

To build this example:

  1. Import this example onto mbed Compiler.
  2. Configure the example in accordance with Application setup.
  3. Compile the example on mbed Compiler and download the resultant binary file.
  4. Plug the micro-USB cable into the OpenSDA port which lies on the next to the RESET button.
  5. Copy the binary previously downloaded to your PC to GR-LYCHEE to flash this example. When the copy is successfully completed, the board is ready to work.
  6. Press the RESET button on the board to run the example.
  7. For verification, please refer to the following wiki:
    https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Monitoring-the-application.

Application resources

This example exposes four resources listed below:

  1. 3202/0/5700. Decode result of barcode data input from camera (GET).
  2. 3201/0/5850. Blink function, blinks LED when executed (POST).
  3. 3201/0/5853. Blink pattern, used by the blink function to determine how to blink. In the format of 1000:500:1000:500:1000:500 (PUT).
  4. 3201/0/5855. Blink color, used by the blink function. Any of green, yellow, orange and red is acceptable (PUT).
Committer:
dkato
Date:
Tue Mar 28 11:02:34 2017 +0000
Revision:
2:6ec5c1c1d41c
Parent:
0:eb73febb2bba
Child:
6:4e43b6f8f772
Memory-saving version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 0:eb73febb2bba 1 /*
dkato 2:6ec5c1c1d41c 2 * Copyright (c) 2015, 2016 ARM Limited. All rights reserved.
<> 0:eb73febb2bba 3 * SPDX-License-Identifier: Apache-2.0
<> 0:eb73febb2bba 4 * Licensed under the Apache License, Version 2.0 (the License); you may
<> 0:eb73febb2bba 5 * not use this file except in compliance with the License.
<> 0:eb73febb2bba 6 * You may obtain a copy of the License at
<> 0:eb73febb2bba 7 *
<> 0:eb73febb2bba 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 0:eb73febb2bba 9 *
<> 0:eb73febb2bba 10 * Unless required by applicable law or agreed to in writing, software
<> 0:eb73febb2bba 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
<> 0:eb73febb2bba 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 0:eb73febb2bba 13 * See the License for the specific language governing permissions and
<> 0:eb73febb2bba 14 * limitations under the License.
<> 0:eb73febb2bba 15 */
dkato 2:6ec5c1c1d41c 16 #include "mbed-trace/mbed_trace.h"
dkato 2:6ec5c1c1d41c 17 #include "mbed.h"
dkato 2:6ec5c1c1d41c 18 #include "zxing_main.h"
dkato 2:6ec5c1c1d41c 19
dkato 2:6ec5c1c1d41c 20 // Network interaction must be performed outside of interrupt context
dkato 2:6ec5c1c1d41c 21 osThreadId mainThread;
dkato 2:6ec5c1c1d41c 22
dkato 2:6ec5c1c1d41c 23 #define NO_CONNECT (-1)
dkato 2:6ec5c1c1d41c 24
dkato 2:6ec5c1c1d41c 25 #if MBED_CONF_APP_NETWORK_INTERFACE == NO_CONNECT
dkato 2:6ec5c1c1d41c 26
dkato 2:6ec5c1c1d41c 27 static void callback_zxing(char * addr, int size) {
dkato 2:6ec5c1c1d41c 28 printf("%s\r\n", addr);
dkato 2:6ec5c1c1d41c 29 }
dkato 2:6ec5c1c1d41c 30
dkato 2:6ec5c1c1d41c 31 // Entry point to the program
dkato 2:6ec5c1c1d41c 32 int main() {
dkato 2:6ec5c1c1d41c 33 // Keep track of the main thread
dkato 2:6ec5c1c1d41c 34 mainThread = osThreadGetId();
dkato 2:6ec5c1c1d41c 35 printf("no connect\n");
dkato 2:6ec5c1c1d41c 36 mbed_trace_init();
dkato 2:6ec5c1c1d41c 37 zxing_init(&callback_zxing);
dkato 2:6ec5c1c1d41c 38
dkato 2:6ec5c1c1d41c 39 while (1) {
dkato 2:6ec5c1c1d41c 40 zxing_loop();
dkato 2:6ec5c1c1d41c 41 Thread::wait(5);
dkato 2:6ec5c1c1d41c 42 }
dkato 2:6ec5c1c1d41c 43 }
dkato 2:6ec5c1c1d41c 44
dkato 2:6ec5c1c1d41c 45 #else // MBED_CONF_APP_NETWORK_INTERFACE != NO_CONNECT
dkato 2:6ec5c1c1d41c 46
dkato 2:6ec5c1c1d41c 47 #define __STDC_FORMAT_MACROS
<> 0:eb73febb2bba 48 #include <string>
<> 0:eb73febb2bba 49 #include <sstream>
<> 0:eb73febb2bba 50 #include <vector>
<> 0:eb73febb2bba 51 #include "security.h"
dkato 2:6ec5c1c1d41c 52 #include "simpleclient.h"
dkato 2:6ec5c1c1d41c 53 #include "mbedtls/entropy_poll.h"
<> 0:eb73febb2bba 54
dkato 2:6ec5c1c1d41c 55 // easy-connect compliancy, it has 2 sets of wifi pins we have only one
dkato 2:6ec5c1c1d41c 56 #define MBED_CONF_APP_ESP8266_TX MBED_CONF_APP_WIFI_TX
dkato 2:6ec5c1c1d41c 57 #define MBED_CONF_APP_ESP8266_RX MBED_CONF_APP_WIFI_RX
dkato 2:6ec5c1c1d41c 58 #include "easy-connect.h"
<> 0:eb73febb2bba 59
<> 0:eb73febb2bba 60 // These are example resource values for the Device Object
<> 0:eb73febb2bba 61 struct MbedClientDevice device = {
<> 0:eb73febb2bba 62 "Manufacturer_String", // Manufacturer
<> 0:eb73febb2bba 63 "Type_String", // Type
<> 0:eb73febb2bba 64 "ModelNumber_String", // ModelNumber
<> 0:eb73febb2bba 65 "SerialNumber_String" // SerialNumber
<> 0:eb73febb2bba 66 };
<> 0:eb73febb2bba 67
<> 0:eb73febb2bba 68 // Instantiate the class which implements LWM2M Client API (from simpleclient.h)
<> 0:eb73febb2bba 69 MbedClient mbed_client(device);
<> 0:eb73febb2bba 70
<> 0:eb73febb2bba 71 // LED Output
<> 0:eb73febb2bba 72 DigitalOut led1(LED1);
<> 0:eb73febb2bba 73 DigitalOut led2(LED2);
<> 0:eb73febb2bba 74 DigitalOut led3(LED3);
<> 0:eb73febb2bba 75 /*
<> 0:eb73febb2bba 76 * The Led contains one property (pattern) and a function (blink).
<> 0:eb73febb2bba 77 * When the function blink is executed, the pattern is read, and the LED
<> 0:eb73febb2bba 78 * will blink based on the pattern.
<> 0:eb73febb2bba 79 */
<> 0:eb73febb2bba 80 class LedResource {
<> 0:eb73febb2bba 81 public:
<> 0:eb73febb2bba 82 LedResource() {
<> 0:eb73febb2bba 83 // create ObjectID with metadata tag of '3201', which is 'digital output'
<> 0:eb73febb2bba 84 led_object = M2MInterfaceFactory::create_object("3201");
<> 0:eb73febb2bba 85 M2MObjectInstance* led_inst = led_object->create_object_instance();
<> 0:eb73febb2bba 86
<> 0:eb73febb2bba 87 // 5855 = Multi-state output
<> 0:eb73febb2bba 88 M2MResource* color_res = led_inst->create_dynamic_resource("5855", "Color",
<> 0:eb73febb2bba 89 M2MResourceInstance::STRING, false);
<> 0:eb73febb2bba 90 // read and write
<> 0:eb73febb2bba 91 color_res->set_operation(M2MBase::GET_PUT_ALLOWED);
<> 0:eb73febb2bba 92 // set red as initial color
<> 0:eb73febb2bba 93 color_res->set_value((const uint8_t*)"red", 3);
<> 0:eb73febb2bba 94
<> 0:eb73febb2bba 95 // 5853 = Multi-state output
<> 0:eb73febb2bba 96 M2MResource* pattern_res = led_inst->create_dynamic_resource("5853", "Pattern",
<> 0:eb73febb2bba 97 M2MResourceInstance::STRING, false);
<> 0:eb73febb2bba 98 // read and write
<> 0:eb73febb2bba 99 pattern_res->set_operation(M2MBase::GET_PUT_ALLOWED);
<> 0:eb73febb2bba 100 // set initial pattern (toggle every 200ms. 7 toggles in total)
<> 0:eb73febb2bba 101 pattern_res->set_value((const uint8_t*)"500:500:500:500:500:500:500", 27);
<> 0:eb73febb2bba 102
<> 0:eb73febb2bba 103 // there's not really an execute LWM2M ID that matches... hmm...
<> 0:eb73febb2bba 104 M2MResource* led_res = led_inst->create_dynamic_resource("5850", "Blink",
<> 0:eb73febb2bba 105 M2MResourceInstance::OPAQUE, false);
<> 0:eb73febb2bba 106 // we allow executing a function here...
<> 0:eb73febb2bba 107 led_res->set_operation(M2MBase::POST_ALLOWED);
<> 0:eb73febb2bba 108 // when a POST comes in, we want to execute the led_execute_callback
<> 0:eb73febb2bba 109 led_res->set_execute_function(execute_callback(this, &LedResource::blink));
dkato 2:6ec5c1c1d41c 110
<> 0:eb73febb2bba 111 }
<> 0:eb73febb2bba 112
<> 0:eb73febb2bba 113 M2MObject* get_object() {
<> 0:eb73febb2bba 114 return led_object;
<> 0:eb73febb2bba 115 }
<> 0:eb73febb2bba 116
dkato 2:6ec5c1c1d41c 117 void blink(void *argument) {
dkato 2:6ec5c1c1d41c 118
dkato 2:6ec5c1c1d41c 119
<> 0:eb73febb2bba 120 // read the value of 'Pattern'
<> 0:eb73febb2bba 121 M2MObjectInstance* inst = led_object->object_instance();
<> 0:eb73febb2bba 122 M2MResource* res = inst->resource("5853");
<> 0:eb73febb2bba 123 // read the value of 'Color'
<> 0:eb73febb2bba 124 M2MObjectInstance* instC = led_object->object_instance();
<> 0:eb73febb2bba 125 M2MResource* resC = instC->resource("5855");
<> 0:eb73febb2bba 126
<> 0:eb73febb2bba 127 // values in mbed Client are all buffers, and we need a vector of int's
<> 0:eb73febb2bba 128 uint8_t* buffIn = NULL;
<> 0:eb73febb2bba 129 uint32_t sizeIn;
<> 0:eb73febb2bba 130 res->get_value(buffIn, sizeIn);
<> 0:eb73febb2bba 131
<> 0:eb73febb2bba 132 uint8_t* cbuffIn = NULL;
<> 0:eb73febb2bba 133 uint32_t csizeIn;
<> 0:eb73febb2bba 134 resC->get_value(cbuffIn, csizeIn);
<> 0:eb73febb2bba 135
<> 0:eb73febb2bba 136 // turn the buffer into a string, and initialize a vector<int> on the heap
<> 0:eb73febb2bba 137 std::string s((char*)buffIn, sizeIn);
<> 0:eb73febb2bba 138 std::vector<uint32_t>* v = new std::vector<uint32_t>;
<> 0:eb73febb2bba 139
dkato 2:6ec5c1c1d41c 140 printf("led_execute_callback pattern=%s\r\n", s.c_str());
<> 0:eb73febb2bba 141
<> 0:eb73febb2bba 142 // our pattern is something like 500:200:500, so parse that
<> 0:eb73febb2bba 143 std::size_t found = s.find_first_of(":");
<> 0:eb73febb2bba 144 while (found!=std::string::npos) {
<> 0:eb73febb2bba 145
<> 0:eb73febb2bba 146 v->push_back(atoi((const char*)s.substr(0,found).c_str()));
<> 0:eb73febb2bba 147 s = s.substr(found+1);
<> 0:eb73febb2bba 148 found=s.find_first_of(":");
<> 0:eb73febb2bba 149 if(found == std::string::npos) {
<> 0:eb73febb2bba 150 v->push_back(atoi((const char*)s.c_str()));
<> 0:eb73febb2bba 151 }
<> 0:eb73febb2bba 152 }
dkato 2:6ec5c1c1d41c 153 int position = 0;
dkato 2:6ec5c1c1d41c 154 while (1) {
dkato 2:6ec5c1c1d41c 155 do_blink(cbuffIn);
dkato 2:6ec5c1c1d41c 156 if (position >= v->size()) {
dkato 2:6ec5c1c1d41c 157 break;
dkato 2:6ec5c1c1d41c 158 }
dkato 2:6ec5c1c1d41c 159 // how long do we need to wait before the next blink?
dkato 2:6ec5c1c1d41c 160 Thread::wait(v->at(position));
dkato 2:6ec5c1c1d41c 161 position++;
dkato 2:6ec5c1c1d41c 162 }
dkato 2:6ec5c1c1d41c 163 free(buffIn);
dkato 2:6ec5c1c1d41c 164 free(cbuffIn);
dkato 2:6ec5c1c1d41c 165 delete v;
<> 0:eb73febb2bba 166 }
<> 0:eb73febb2bba 167
<> 0:eb73febb2bba 168 private:
<> 0:eb73febb2bba 169 M2MObject* led_object;
dkato 2:6ec5c1c1d41c 170 void do_blink(uint8_t* color) {
<> 0:eb73febb2bba 171
<> 0:eb73febb2bba 172 if (!strcmp((char *)color, "red")) {
<> 0:eb73febb2bba 173 // blink the LED in red color
<> 0:eb73febb2bba 174 led1 = !led1;
<> 0:eb73febb2bba 175 }
<> 0:eb73febb2bba 176 else if (!strcmp((char *)color, "green")) {
<> 0:eb73febb2bba 177 // blink in green color
<> 0:eb73febb2bba 178 led2 = !led2;
<> 0:eb73febb2bba 179 }
<> 0:eb73febb2bba 180 else if (!strcmp((char *)color, "blue")) {
<> 0:eb73febb2bba 181 // blink in blue color
<> 0:eb73febb2bba 182 led3 = !led3;
<> 0:eb73febb2bba 183 }
<> 0:eb73febb2bba 184 else if (!strcmp((char *)color, "cyan")) {
<> 0:eb73febb2bba 185 // blink in cyan color
<> 0:eb73febb2bba 186 led2 = !led2;
<> 0:eb73febb2bba 187 led3 = !led3;
<> 0:eb73febb2bba 188 }
<> 0:eb73febb2bba 189 else if (!strcmp((char *)color, "yellow")) {
<> 0:eb73febb2bba 190 // blink in yellow color
<> 0:eb73febb2bba 191 led1 = !led1;
<> 0:eb73febb2bba 192 led2 = !led2;
<> 0:eb73febb2bba 193 }
<> 0:eb73febb2bba 194 else if (!strcmp((char *)color, "magenta")) {
<> 0:eb73febb2bba 195 // blink in magenta color
<> 0:eb73febb2bba 196 led1 = !led1;
<> 0:eb73febb2bba 197 led3 = !led3;
<> 0:eb73febb2bba 198 }
<> 0:eb73febb2bba 199 else if (!strcmp((char *)color, "white")) {
<> 0:eb73febb2bba 200 // blink in white color
<> 0:eb73febb2bba 201 led1 = !led1;
<> 0:eb73febb2bba 202 led2 = !led2;
<> 0:eb73febb2bba 203 led3 = !led3;
<> 0:eb73febb2bba 204 }
<> 0:eb73febb2bba 205 else {
<> 0:eb73febb2bba 206 // no operation
<> 0:eb73febb2bba 207 }
<> 0:eb73febb2bba 208 }
<> 0:eb73febb2bba 209 };
<> 0:eb73febb2bba 210
<> 0:eb73febb2bba 211 /*
<> 0:eb73febb2bba 212 * The Zxing contains a function (send string).
<> 0:eb73febb2bba 213 * When `handle_string_send` is executed, the string after decoding is sent.
<> 0:eb73febb2bba 214 */
<> 0:eb73febb2bba 215 class ZxingResource {
<> 0:eb73febb2bba 216 public:
<> 0:eb73febb2bba 217 ZxingResource() {
<> 0:eb73febb2bba 218 // create ObjectID with metadata tag of '3202', which is 'send string'
<> 0:eb73febb2bba 219 zxing_object = M2MInterfaceFactory::create_object("3202");
<> 0:eb73febb2bba 220 M2MObjectInstance* zxing_inst = zxing_object->create_object_instance();
<> 0:eb73febb2bba 221 // create resource with ID '5700', which is 'send string'
<> 0:eb73febb2bba 222 M2MResource* zxing_res = zxing_inst->create_dynamic_resource("5700", "zxing",
<> 0:eb73febb2bba 223 M2MResourceInstance::STRING, true);
<> 0:eb73febb2bba 224 // we can read this value
<> 0:eb73febb2bba 225 zxing_res->set_operation(M2MBase::GET_ALLOWED);
<> 0:eb73febb2bba 226 // set initial value (all values in mbed Client are buffers)
<> 0:eb73febb2bba 227 // to be able to read this data easily in the Connector console, we'll use a string
dkato 2:6ec5c1c1d41c 228 zxing_res->set_value((uint8_t*)"0", 1);
<> 0:eb73febb2bba 229 }
<> 0:eb73febb2bba 230
<> 0:eb73febb2bba 231 ~ZxingResource() {
<> 0:eb73febb2bba 232 }
<> 0:eb73febb2bba 233
<> 0:eb73febb2bba 234 M2MObject* get_object() {
<> 0:eb73febb2bba 235 return zxing_object;
<> 0:eb73febb2bba 236 }
<> 0:eb73febb2bba 237
<> 0:eb73febb2bba 238 /*
<> 0:eb73febb2bba 239 * When you success the decode process of barcode, we send the string after decoding to mbed Device Connector.
<> 0:eb73febb2bba 240 */
<> 0:eb73febb2bba 241 void handle_string_send(char * addr, int size) {
<> 0:eb73febb2bba 242 M2MObjectInstance* inst = zxing_object->object_instance();
<> 0:eb73febb2bba 243 M2MResource* res = inst->resource("5700");
<> 0:eb73febb2bba 244
<> 0:eb73febb2bba 245 printf("%s\r\n", addr);
<> 0:eb73febb2bba 246
<> 0:eb73febb2bba 247 // tell the string to connector
<> 0:eb73febb2bba 248 res->set_value((uint8_t *)addr, size);
<> 0:eb73febb2bba 249 }
<> 0:eb73febb2bba 250
<> 0:eb73febb2bba 251 private:
<> 0:eb73febb2bba 252 M2MObject* zxing_object;
<> 0:eb73febb2bba 253 };
<> 0:eb73febb2bba 254
<> 0:eb73febb2bba 255 ZxingResource zxing_resource;
<> 0:eb73febb2bba 256
<> 0:eb73febb2bba 257 static void callback_zxing(char * addr, int size) {
<> 0:eb73febb2bba 258 zxing_resource.handle_string_send(addr, size);
<> 0:eb73febb2bba 259 }
dkato 2:6ec5c1c1d41c 260
dkato 2:6ec5c1c1d41c 261 static volatile bool registered;
dkato 2:6ec5c1c1d41c 262
dkato 2:6ec5c1c1d41c 263 void unregister() {
dkato 2:6ec5c1c1d41c 264 registered = false;
dkato 2:6ec5c1c1d41c 265 }
<> 0:eb73febb2bba 266
<> 0:eb73febb2bba 267 // Entry point to the program
<> 0:eb73febb2bba 268 int main() {
<> 0:eb73febb2bba 269
dkato 2:6ec5c1c1d41c 270 unsigned int seed;
dkato 2:6ec5c1c1d41c 271 size_t len;
<> 0:eb73febb2bba 272
dkato 2:6ec5c1c1d41c 273 #ifdef MBEDTLS_ENTROPY_HARDWARE_ALT
dkato 2:6ec5c1c1d41c 274 // Used to randomize source port
dkato 2:6ec5c1c1d41c 275 mbedtls_hardware_poll(NULL, (unsigned char *) &seed, sizeof seed, &len);
dkato 2:6ec5c1c1d41c 276
dkato 2:6ec5c1c1d41c 277 #elif defined MBEDTLS_TEST_NULL_ENTROPY
dkato 2:6ec5c1c1d41c 278
<> 0:eb73febb2bba 279 #warning "mbedTLS security feature is disabled. Connection will not be secure !! Implement proper hardware entropy for your selected hardware."
dkato 2:6ec5c1c1d41c 280 // Used to randomize source port
dkato 2:6ec5c1c1d41c 281 mbedtls_null_entropy_poll( NULL,(unsigned char *) &seed, sizeof seed, &len);
<> 0:eb73febb2bba 282
<> 0:eb73febb2bba 283 #else
<> 0:eb73febb2bba 284
<> 0:eb73febb2bba 285 #error "This hardware does not have entropy, endpoint will not register to Connector.\
<> 0:eb73febb2bba 286 You need to enable NULL ENTROPY for your application, but if this configuration change is made then no security is offered by mbed TLS.\
<> 0:eb73febb2bba 287 Add MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES and MBEDTLS_TEST_NULL_ENTROPY in mbed_app.json macros to register your endpoint."
<> 0:eb73febb2bba 288
<> 0:eb73febb2bba 289 #endif
<> 0:eb73febb2bba 290
dkato 2:6ec5c1c1d41c 291 srand(seed);
<> 0:eb73febb2bba 292 // Keep track of the main thread
<> 0:eb73febb2bba 293 mainThread = osThreadGetId();
dkato 2:6ec5c1c1d41c 294 printf("\nStarting mbed Client example in ");
<> 0:eb73febb2bba 295
dkato 2:6ec5c1c1d41c 296 #if defined (MESH) || (MBED_CONF_LWIP_IPV6_ENABLED==true)
dkato 2:6ec5c1c1d41c 297 printf("IPv6 mode\n");
dkato 2:6ec5c1c1d41c 298 #else
dkato 2:6ec5c1c1d41c 299 printf("IPv4 mode\n");
dkato 2:6ec5c1c1d41c 300 #endif
<> 0:eb73febb2bba 301
<> 0:eb73febb2bba 302 mbed_trace_init();
<> 0:eb73febb2bba 303
dkato 2:6ec5c1c1d41c 304 #if MBED_CONF_APP_NETWORK_INTERFACE == WIFI_BP3595
dkato 2:6ec5c1c1d41c 305 DigitalOut usb1en(P3_8);
<> 0:eb73febb2bba 306 usb1en = 1;
<> 0:eb73febb2bba 307 Thread::wait(5);
<> 0:eb73febb2bba 308 usb1en = 0;
<> 0:eb73febb2bba 309 Thread::wait(5);
<> 0:eb73febb2bba 310 #endif
dkato 2:6ec5c1c1d41c 311
dkato 2:6ec5c1c1d41c 312 NetworkInterface* network = easy_connect(true);
dkato 2:6ec5c1c1d41c 313 if(network == NULL) {
dkato 2:6ec5c1c1d41c 314 printf("\nConnection to Network Failed - exiting application...\n");
dkato 2:6ec5c1c1d41c 315 return -1;
<> 0:eb73febb2bba 316 }
<> 0:eb73febb2bba 317 LedResource led_resource;
<> 0:eb73febb2bba 318
<> 0:eb73febb2bba 319 // Create endpoint interface to manage register and unregister
dkato 2:6ec5c1c1d41c 320 mbed_client.create_interface(MBED_SERVER_ADDRESS, network);
<> 0:eb73febb2bba 321
<> 0:eb73febb2bba 322 // Create Objects of varying types, see simpleclient.h for more details on implementation.
<> 0:eb73febb2bba 323 M2MSecurity* register_object = mbed_client.create_register_object(); // server object specifying connector info
<> 0:eb73febb2bba 324 M2MDevice* device_object = mbed_client.create_device_object(); // device resources object
<> 0:eb73febb2bba 325
<> 0:eb73febb2bba 326 // Create list of Objects to register
<> 0:eb73febb2bba 327 M2MObjectList object_list;
<> 0:eb73febb2bba 328
<> 0:eb73febb2bba 329 // Add objects to list
<> 0:eb73febb2bba 330 object_list.push_back(device_object);
dkato 2:6ec5c1c1d41c 331 object_list.push_back(led_resource.get_object());
<> 0:eb73febb2bba 332 object_list.push_back(zxing_resource.get_object());
<> 0:eb73febb2bba 333
<> 0:eb73febb2bba 334 // Set endpoint registration object
<> 0:eb73febb2bba 335 mbed_client.set_register_object(register_object);
<> 0:eb73febb2bba 336
<> 0:eb73febb2bba 337 // Register with mbed Device Connector
<> 0:eb73febb2bba 338 mbed_client.test_register(register_object, object_list);
<> 0:eb73febb2bba 339
<> 0:eb73febb2bba 340 zxing_init(&callback_zxing);
dkato 2:6ec5c1c1d41c 341
<> 0:eb73febb2bba 342 Timer update_timer;
<> 0:eb73febb2bba 343 update_timer.reset();
<> 0:eb73febb2bba 344 update_timer.start();
<> 0:eb73febb2bba 345
dkato 2:6ec5c1c1d41c 346 registered = true;
dkato 2:6ec5c1c1d41c 347 InterruptIn unreg_button(USER_BUTTON0);
dkato 2:6ec5c1c1d41c 348 unreg_button.fall(&unregister);
dkato 2:6ec5c1c1d41c 349
<> 0:eb73febb2bba 350 while (registered) {
<> 0:eb73febb2bba 351 if (zxing_loop() == 0) {
<> 0:eb73febb2bba 352 update_timer.reset();
<> 0:eb73febb2bba 353 } else if (update_timer.read() >= 25) {
<> 0:eb73febb2bba 354 mbed_client.test_update_register();
<> 0:eb73febb2bba 355 update_timer.reset();
<> 0:eb73febb2bba 356 } else {
<> 0:eb73febb2bba 357 // do nothing
<> 0:eb73febb2bba 358 }
<> 0:eb73febb2bba 359 Thread::wait(5);
<> 0:eb73febb2bba 360 }
<> 0:eb73febb2bba 361
<> 0:eb73febb2bba 362 mbed_client.test_unregister();
<> 0:eb73febb2bba 363 }
dkato 2:6ec5c1c1d41c 364
dkato 2:6ec5c1c1d41c 365 #endif // MBED_CONF_APP_NETWORK_INTERFACE != NO_CONNECT
dkato 2:6ec5c1c1d41c 366
dkato 2:6ec5c1c1d41c 367