This is a simple mbed client example demonstrating, registration of a device with mbed Device Connector and reading and writing values as well as deregistering on different Network Interfaces including Ethernet, WiFi, 6LoWPAN ND and Thread respectively.

Dependencies:   lwip

Fork of mbed-os-example-client by mbed-os-examples

Committer:
mbed_official
Date:
Thu Sep 29 16:15:08 2016 +0100
Revision:
19:91eb6f58fd77
Parent:
0:7d5ec759888b
Child:
21:b88cdeb5b302
Merge pull request #88 from mikaleppanen/entropy

Added support for entropy poll to randomize source ports.

Commit copied from https://github.com/ARMmbed/mbed-os-example-client

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yogesh Pande 0:7d5ec759888b 1 /*
Yogesh Pande 0:7d5ec759888b 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
Yogesh Pande 0:7d5ec759888b 3 * SPDX-License-Identifier: Apache-2.0
Yogesh Pande 0:7d5ec759888b 4 * Licensed under the Apache License, Version 2.0 (the License); you may
Yogesh Pande 0:7d5ec759888b 5 * not use this file except in compliance with the License.
Yogesh Pande 0:7d5ec759888b 6 * You may obtain a copy of the License at
Yogesh Pande 0:7d5ec759888b 7 *
Yogesh Pande 0:7d5ec759888b 8 * http://www.apache.org/licenses/LICENSE-2.0
Yogesh Pande 0:7d5ec759888b 9 *
Yogesh Pande 0:7d5ec759888b 10 * Unless required by applicable law or agreed to in writing, software
Yogesh Pande 0:7d5ec759888b 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
Yogesh Pande 0:7d5ec759888b 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Yogesh Pande 0:7d5ec759888b 13 * See the License for the specific language governing permissions and
Yogesh Pande 0:7d5ec759888b 14 * limitations under the License.
Yogesh Pande 0:7d5ec759888b 15 */
Yogesh Pande 0:7d5ec759888b 16
Yogesh Pande 0:7d5ec759888b 17 #ifndef __SIMPLECLIENT_H__
Yogesh Pande 0:7d5ec759888b 18 #define __SIMPLECLIENT_H__
Yogesh Pande 0:7d5ec759888b 19
Yogesh Pande 0:7d5ec759888b 20 #include "mbed-client/m2minterfacefactory.h"
Yogesh Pande 0:7d5ec759888b 21 #include "mbed-client/m2mdevice.h"
Yogesh Pande 0:7d5ec759888b 22 #include "mbed-client/m2minterfaceobserver.h"
Yogesh Pande 0:7d5ec759888b 23 #include "mbed-client/m2minterface.h"
Yogesh Pande 0:7d5ec759888b 24 #include "mbed-client/m2mobject.h"
Yogesh Pande 0:7d5ec759888b 25 #include "mbed-client/m2mobjectinstance.h"
Yogesh Pande 0:7d5ec759888b 26 #include "mbed-client/m2mresource.h"
Yogesh Pande 0:7d5ec759888b 27 #include "mbed-client/m2mconfig.h"
Yogesh Pande 0:7d5ec759888b 28 #include "security.h"
Yogesh Pande 0:7d5ec759888b 29 #include "mbed.h"
Yogesh Pande 0:7d5ec759888b 30
Yogesh Pande 0:7d5ec759888b 31 //Select binding mode: UDP or TCP
Yogesh Pande 0:7d5ec759888b 32 M2MInterface::BindingMode SOCKET_MODE = M2MInterface::UDP;
Yogesh Pande 0:7d5ec759888b 33
Yogesh Pande 0:7d5ec759888b 34 // MBED_DOMAIN and MBED_ENDPOINT_NAME come
Yogesh Pande 0:7d5ec759888b 35 // from the security.h file copied from connector.mbed.com
Yogesh Pande 0:7d5ec759888b 36
Yogesh Pande 0:7d5ec759888b 37 struct MbedClientDevice {
Yogesh Pande 0:7d5ec759888b 38 const char* Manufacturer;
Yogesh Pande 0:7d5ec759888b 39 const char* Type;
Yogesh Pande 0:7d5ec759888b 40 const char* ModelNumber;
Yogesh Pande 0:7d5ec759888b 41 const char* SerialNumber;
Yogesh Pande 0:7d5ec759888b 42 };
Yogesh Pande 0:7d5ec759888b 43
Yogesh Pande 0:7d5ec759888b 44 /*
Yogesh Pande 0:7d5ec759888b 45 * Wrapper for mbed client stack that handles all callbacks, error handling, and
Yogesh Pande 0:7d5ec759888b 46 * other shenanigans to make the mbed client stack easier to use.
Yogesh Pande 0:7d5ec759888b 47 *
Yogesh Pande 0:7d5ec759888b 48 * The end user should only have to care about configuring the parameters at the
Yogesh Pande 0:7d5ec759888b 49 * top of this file and making sure they add the security.h file correctly.
Yogesh Pande 0:7d5ec759888b 50 * To add resources you can copy the _TODO__ function and add as many instances as
Yogesh Pande 0:7d5ec759888b 51 * you want.
Yogesh Pande 0:7d5ec759888b 52 *
Yogesh Pande 0:7d5ec759888b 53 */
Yogesh Pande 0:7d5ec759888b 54 class MbedClient: public M2MInterfaceObserver {
Yogesh Pande 0:7d5ec759888b 55 public:
Yogesh Pande 0:7d5ec759888b 56
Yogesh Pande 0:7d5ec759888b 57 // constructor for MbedClient object, initialize private variables
Yogesh Pande 0:7d5ec759888b 58 MbedClient(struct MbedClientDevice device) {
Yogesh Pande 0:7d5ec759888b 59 _interface = NULL;
Yogesh Pande 0:7d5ec759888b 60 _bootstrapped = false;
Yogesh Pande 0:7d5ec759888b 61 _error = false;
Yogesh Pande 0:7d5ec759888b 62 _registered = false;
Yogesh Pande 0:7d5ec759888b 63 _unregistered = false;
Yogesh Pande 0:7d5ec759888b 64 _register_security = NULL;
Yogesh Pande 0:7d5ec759888b 65 _value = 0;
Yogesh Pande 0:7d5ec759888b 66 _object = NULL;
Yogesh Pande 0:7d5ec759888b 67 _device = device;
Yogesh Pande 0:7d5ec759888b 68 }
Yogesh Pande 0:7d5ec759888b 69
Yogesh Pande 0:7d5ec759888b 70 // de-constructor for MbedClient object, you can ignore this
Yogesh Pande 0:7d5ec759888b 71 ~MbedClient() {
Yogesh Pande 0:7d5ec759888b 72 if(_interface) {
Yogesh Pande 0:7d5ec759888b 73 delete _interface;
Yogesh Pande 0:7d5ec759888b 74 }
Yogesh Pande 0:7d5ec759888b 75 if(_register_security){
Yogesh Pande 0:7d5ec759888b 76 delete _register_security;
Yogesh Pande 0:7d5ec759888b 77 }
Yogesh Pande 0:7d5ec759888b 78 }
Yogesh Pande 0:7d5ec759888b 79
Yogesh Pande 0:7d5ec759888b 80 // debug printf function
Yogesh Pande 0:7d5ec759888b 81 void trace_printer(const char* str) {
Yogesh Pande 0:7d5ec759888b 82 printf("\r\n%s\r\n", str);
Yogesh Pande 0:7d5ec759888b 83 }
Yogesh Pande 0:7d5ec759888b 84
Yogesh Pande 0:7d5ec759888b 85 /*
Yogesh Pande 0:7d5ec759888b 86 * Creates M2MInterface using which endpoint can
Yogesh Pande 0:7d5ec759888b 87 * setup its name, resource type, life time, connection mode,
Yogesh Pande 0:7d5ec759888b 88 * Currently only LwIPv4 is supported.
Yogesh Pande 0:7d5ec759888b 89 */
Yogesh Pande 0:7d5ec759888b 90 void create_interface(const char *server_address,
Yogesh Pande 0:7d5ec759888b 91 void *handler=NULL) {
Yogesh Pande 0:7d5ec759888b 92 // Randomizing listening port for Certificate mode connectivity
Yogesh Pande 0:7d5ec759888b 93 _server_address = server_address;
Yogesh Pande 0:7d5ec759888b 94 uint16_t port = rand() % 65535 + 12345;
Yogesh Pande 0:7d5ec759888b 95
Yogesh Pande 0:7d5ec759888b 96 // create mDS interface object, this is the base object everything else attaches to
Yogesh Pande 0:7d5ec759888b 97 _interface = M2MInterfaceFactory::create_interface(*this,
Yogesh Pande 0:7d5ec759888b 98 MBED_ENDPOINT_NAME, // endpoint name string
Yogesh Pande 0:7d5ec759888b 99 "test", // endpoint type string
Yogesh Pande 0:7d5ec759888b 100 100, // lifetime
Yogesh Pande 0:7d5ec759888b 101 port, // listen port
Yogesh Pande 0:7d5ec759888b 102 MBED_DOMAIN, // domain string
Yogesh Pande 0:7d5ec759888b 103 SOCKET_MODE, // binding mode
Yogesh Pande 0:7d5ec759888b 104 M2MInterface::LwIP_IPv4, // network stack
Yogesh Pande 0:7d5ec759888b 105 ""); // context address string
Yogesh Pande 0:7d5ec759888b 106 const char *binding_mode = (SOCKET_MODE == M2MInterface::UDP) ? "UDP" : "TCP";
Yogesh Pande 0:7d5ec759888b 107 printf("\r\nSOCKET_MODE : %s\r\n", binding_mode);
Yogesh Pande 0:7d5ec759888b 108 printf("Connecting to %s\r\n", server_address);
Yogesh Pande 0:7d5ec759888b 109
Yogesh Pande 0:7d5ec759888b 110 if(_interface) {
Yogesh Pande 0:7d5ec759888b 111 _interface->set_platform_network_handler(handler);
Yogesh Pande 0:7d5ec759888b 112 }
Yogesh Pande 0:7d5ec759888b 113
Yogesh Pande 0:7d5ec759888b 114 }
Yogesh Pande 0:7d5ec759888b 115
Yogesh Pande 0:7d5ec759888b 116 /*
Yogesh Pande 0:7d5ec759888b 117 * check private variable to see if the registration was sucessful or not
Yogesh Pande 0:7d5ec759888b 118 */
Yogesh Pande 0:7d5ec759888b 119 bool register_successful() {
Yogesh Pande 0:7d5ec759888b 120 return _registered;
Yogesh Pande 0:7d5ec759888b 121 }
Yogesh Pande 0:7d5ec759888b 122
Yogesh Pande 0:7d5ec759888b 123 /*
Yogesh Pande 0:7d5ec759888b 124 * check private variable to see if un-registration was sucessful or not
Yogesh Pande 0:7d5ec759888b 125 */
Yogesh Pande 0:7d5ec759888b 126 bool unregister_successful() {
Yogesh Pande 0:7d5ec759888b 127 return _unregistered;
Yogesh Pande 0:7d5ec759888b 128 }
Yogesh Pande 0:7d5ec759888b 129
Yogesh Pande 0:7d5ec759888b 130 /*
Yogesh Pande 0:7d5ec759888b 131 * Creates register server object with mbed device server address and other parameters
Yogesh Pande 0:7d5ec759888b 132 * required for client to connect to mbed device server.
Yogesh Pande 0:7d5ec759888b 133 */
Yogesh Pande 0:7d5ec759888b 134 M2MSecurity* create_register_object() {
Yogesh Pande 0:7d5ec759888b 135 // create security object using the interface factory.
Yogesh Pande 0:7d5ec759888b 136 // this will generate a security ObjectID and ObjectInstance
Yogesh Pande 0:7d5ec759888b 137 M2MSecurity *security = M2MInterfaceFactory::create_security(M2MSecurity::M2MServer);
Yogesh Pande 0:7d5ec759888b 138
Yogesh Pande 0:7d5ec759888b 139 // make sure security ObjectID/ObjectInstance was created successfully
Yogesh Pande 0:7d5ec759888b 140 if(security) {
Yogesh Pande 0:7d5ec759888b 141 // Add ResourceID's and values to the security ObjectID/ObjectInstance
Yogesh Pande 0:7d5ec759888b 142 security->set_resource_value(M2MSecurity::M2MServerUri, _server_address);
Yogesh Pande 0:7d5ec759888b 143 security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate);
Yogesh Pande 0:7d5ec759888b 144 security->set_resource_value(M2MSecurity::ServerPublicKey, SERVER_CERT, sizeof(SERVER_CERT));
Yogesh Pande 0:7d5ec759888b 145 security->set_resource_value(M2MSecurity::PublicKey, CERT, sizeof(CERT));
Yogesh Pande 0:7d5ec759888b 146 security->set_resource_value(M2MSecurity::Secretkey, KEY, sizeof(KEY));
Yogesh Pande 0:7d5ec759888b 147 }
Yogesh Pande 0:7d5ec759888b 148 return security;
Yogesh Pande 0:7d5ec759888b 149 }
Yogesh Pande 0:7d5ec759888b 150
Yogesh Pande 0:7d5ec759888b 151 /*
Yogesh Pande 0:7d5ec759888b 152 * Creates device object which contains mandatory resources linked with
Yogesh Pande 0:7d5ec759888b 153 * device endpoint.
Yogesh Pande 0:7d5ec759888b 154 */
Yogesh Pande 0:7d5ec759888b 155 M2MDevice* create_device_object() {
Yogesh Pande 0:7d5ec759888b 156 // create device objectID/ObjectInstance
Yogesh Pande 0:7d5ec759888b 157 M2MDevice *device = M2MInterfaceFactory::create_device();
Yogesh Pande 0:7d5ec759888b 158 // make sure device object was created successfully
Yogesh Pande 0:7d5ec759888b 159 if(device) {
Yogesh Pande 0:7d5ec759888b 160 // add resourceID's to device objectID/ObjectInstance
Yogesh Pande 0:7d5ec759888b 161 device->create_resource(M2MDevice::Manufacturer, _device.Manufacturer);
Yogesh Pande 0:7d5ec759888b 162 device->create_resource(M2MDevice::DeviceType, _device.Type);
Yogesh Pande 0:7d5ec759888b 163 device->create_resource(M2MDevice::ModelNumber, _device.ModelNumber);
Yogesh Pande 0:7d5ec759888b 164 device->create_resource(M2MDevice::SerialNumber, _device.SerialNumber);
Yogesh Pande 0:7d5ec759888b 165 }
Yogesh Pande 0:7d5ec759888b 166 return device;
Yogesh Pande 0:7d5ec759888b 167 }
Yogesh Pande 0:7d5ec759888b 168
Yogesh Pande 0:7d5ec759888b 169 /*
Yogesh Pande 0:7d5ec759888b 170 * register an object
Yogesh Pande 0:7d5ec759888b 171 */
Yogesh Pande 0:7d5ec759888b 172 void test_register(M2MSecurity *register_object, M2MObjectList object_list){
Yogesh Pande 0:7d5ec759888b 173 if(_interface) {
Yogesh Pande 0:7d5ec759888b 174 // Register function
Yogesh Pande 0:7d5ec759888b 175 _interface->register_object(register_object, object_list);
Yogesh Pande 0:7d5ec759888b 176 }
Yogesh Pande 0:7d5ec759888b 177 }
Yogesh Pande 0:7d5ec759888b 178
Yogesh Pande 0:7d5ec759888b 179 /*
Yogesh Pande 0:7d5ec759888b 180 * unregister all objects
Yogesh Pande 0:7d5ec759888b 181 */
Yogesh Pande 0:7d5ec759888b 182 void test_unregister() {
Yogesh Pande 0:7d5ec759888b 183 if(_interface) {
Yogesh Pande 0:7d5ec759888b 184 // Unregister function
Yogesh Pande 0:7d5ec759888b 185 _interface->unregister_object(NULL); // NULL will unregister all objects
Yogesh Pande 0:7d5ec759888b 186 }
Yogesh Pande 0:7d5ec759888b 187 }
Yogesh Pande 0:7d5ec759888b 188
Yogesh Pande 0:7d5ec759888b 189 //Callback from mbed client stack when the bootstrap
Yogesh Pande 0:7d5ec759888b 190 // is successful, it returns the mbed Device Server object
Yogesh Pande 0:7d5ec759888b 191 // which will be used for registering the resources to
Yogesh Pande 0:7d5ec759888b 192 // mbed Device server.
Yogesh Pande 0:7d5ec759888b 193 void bootstrap_done(M2MSecurity *server_object){
Yogesh Pande 0:7d5ec759888b 194 if(server_object) {
Yogesh Pande 0:7d5ec759888b 195 _bootstrapped = true;
Yogesh Pande 0:7d5ec759888b 196 _error = false;
Yogesh Pande 0:7d5ec759888b 197 trace_printer("Bootstrapped");
Yogesh Pande 0:7d5ec759888b 198 }
Yogesh Pande 0:7d5ec759888b 199 }
Yogesh Pande 0:7d5ec759888b 200
Yogesh Pande 0:7d5ec759888b 201 //Callback from mbed client stack when the registration
Yogesh Pande 0:7d5ec759888b 202 // is successful, it returns the mbed Device Server object
Yogesh Pande 0:7d5ec759888b 203 // to which the resources are registered and registered objects.
Yogesh Pande 0:7d5ec759888b 204 void object_registered(M2MSecurity */*security_object*/, const M2MServer &/*server_object*/){
Yogesh Pande 0:7d5ec759888b 205 _registered = true;
Yogesh Pande 0:7d5ec759888b 206 _unregistered = false;
Yogesh Pande 0:7d5ec759888b 207 trace_printer("Registered object successfully!");
Yogesh Pande 0:7d5ec759888b 208 }
Yogesh Pande 0:7d5ec759888b 209
Yogesh Pande 0:7d5ec759888b 210 //Callback from mbed client stack when the unregistration
Yogesh Pande 0:7d5ec759888b 211 // is successful, it returns the mbed Device Server object
Yogesh Pande 0:7d5ec759888b 212 // to which the resources were unregistered.
Yogesh Pande 0:7d5ec759888b 213 void object_unregistered(M2MSecurity */*server_object*/){
Yogesh Pande 0:7d5ec759888b 214 trace_printer("Unregistered Object Successfully");
Yogesh Pande 0:7d5ec759888b 215 _unregistered = true;
Yogesh Pande 0:7d5ec759888b 216 _registered = false;
Yogesh Pande 0:7d5ec759888b 217 }
Yogesh Pande 0:7d5ec759888b 218
Yogesh Pande 0:7d5ec759888b 219 /*
Yogesh Pande 0:7d5ec759888b 220 * Callback from mbed client stack when registration is updated
Yogesh Pande 0:7d5ec759888b 221 */
Yogesh Pande 0:7d5ec759888b 222 void registration_updated(M2MSecurity */*security_object*/, const M2MServer & /*server_object*/){
Yogesh Pande 0:7d5ec759888b 223 /* The registration is updated automatically and frequently by the
Yogesh Pande 0:7d5ec759888b 224 * mbed client stack. This print statement is turned off because it
Yogesh Pande 0:7d5ec759888b 225 * tends to happen alot.
Yogesh Pande 0:7d5ec759888b 226 */
Yogesh Pande 0:7d5ec759888b 227 //trace_printer("\r\nRegistration Updated\r\n");
Yogesh Pande 0:7d5ec759888b 228 }
Yogesh Pande 0:7d5ec759888b 229
Yogesh Pande 0:7d5ec759888b 230 // Callback from mbed client stack if any error is encountered
Yogesh Pande 0:7d5ec759888b 231 // during any of the LWM2M operations. Error type is passed in
Yogesh Pande 0:7d5ec759888b 232 // the callback.
Yogesh Pande 0:7d5ec759888b 233 void error(M2MInterface::Error error){
Yogesh Pande 0:7d5ec759888b 234 _error = true;
Yogesh Pande 0:7d5ec759888b 235 switch(error){
Yogesh Pande 0:7d5ec759888b 236 case M2MInterface::AlreadyExists:
Yogesh Pande 0:7d5ec759888b 237 trace_printer("[ERROR:] M2MInterface::AlreadyExist");
Yogesh Pande 0:7d5ec759888b 238 break;
Yogesh Pande 0:7d5ec759888b 239 case M2MInterface::BootstrapFailed:
Yogesh Pande 0:7d5ec759888b 240 trace_printer("[ERROR:] M2MInterface::BootstrapFailed");
Yogesh Pande 0:7d5ec759888b 241 break;
Yogesh Pande 0:7d5ec759888b 242 case M2MInterface::InvalidParameters:
Yogesh Pande 0:7d5ec759888b 243 trace_printer("[ERROR:] M2MInterface::InvalidParameters");
Yogesh Pande 0:7d5ec759888b 244 break;
Yogesh Pande 0:7d5ec759888b 245 case M2MInterface::NotRegistered:
Yogesh Pande 0:7d5ec759888b 246 trace_printer("[ERROR:] M2MInterface::NotRegistered");
Yogesh Pande 0:7d5ec759888b 247 break;
Yogesh Pande 0:7d5ec759888b 248 case M2MInterface::Timeout:
Yogesh Pande 0:7d5ec759888b 249 trace_printer("[ERROR:] M2MInterface::Timeout");
Yogesh Pande 0:7d5ec759888b 250 break;
Yogesh Pande 0:7d5ec759888b 251 case M2MInterface::NetworkError:
Yogesh Pande 0:7d5ec759888b 252 trace_printer("[ERROR:] M2MInterface::NetworkError");
Yogesh Pande 0:7d5ec759888b 253 break;
Yogesh Pande 0:7d5ec759888b 254 case M2MInterface::ResponseParseFailed:
Yogesh Pande 0:7d5ec759888b 255 trace_printer("[ERROR:] M2MInterface::ResponseParseFailed");
Yogesh Pande 0:7d5ec759888b 256 break;
Yogesh Pande 0:7d5ec759888b 257 case M2MInterface::UnknownError:
Yogesh Pande 0:7d5ec759888b 258 trace_printer("[ERROR:] M2MInterface::UnknownError");
Yogesh Pande 0:7d5ec759888b 259 break;
Yogesh Pande 0:7d5ec759888b 260 case M2MInterface::MemoryFail:
Yogesh Pande 0:7d5ec759888b 261 trace_printer("[ERROR:] M2MInterface::MemoryFail");
Yogesh Pande 0:7d5ec759888b 262 break;
Yogesh Pande 0:7d5ec759888b 263 case M2MInterface::NotAllowed:
Yogesh Pande 0:7d5ec759888b 264 trace_printer("[ERROR:] M2MInterface::NotAllowed");
Yogesh Pande 0:7d5ec759888b 265 break;
Yogesh Pande 0:7d5ec759888b 266 case M2MInterface::SecureConnectionFailed:
Yogesh Pande 0:7d5ec759888b 267 trace_printer("[ERROR:] M2MInterface::SecureConnectionFailed");
Yogesh Pande 0:7d5ec759888b 268 break;
Yogesh Pande 0:7d5ec759888b 269 case M2MInterface::DnsResolvingFailed:
Yogesh Pande 0:7d5ec759888b 270 trace_printer("[ERROR:] M2MInterface::DnsResolvingFailed");
Yogesh Pande 0:7d5ec759888b 271 break;
Yogesh Pande 0:7d5ec759888b 272
Yogesh Pande 0:7d5ec759888b 273 default:
Yogesh Pande 0:7d5ec759888b 274 break;
Yogesh Pande 0:7d5ec759888b 275 }
Yogesh Pande 0:7d5ec759888b 276 }
Yogesh Pande 0:7d5ec759888b 277
Yogesh Pande 0:7d5ec759888b 278 /* Callback from mbed client stack if any value has changed
Yogesh Pande 0:7d5ec759888b 279 * during PUT operation. Object and its type is passed in
Yogesh Pande 0:7d5ec759888b 280 * the callback.
Yogesh Pande 0:7d5ec759888b 281 * BaseType enum from m2mbase.h
Yogesh Pande 0:7d5ec759888b 282 * Object = 0x0, Resource = 0x1, ObjectInstance = 0x2, ResourceInstance = 0x3
Yogesh Pande 0:7d5ec759888b 283 */
Yogesh Pande 0:7d5ec759888b 284 void value_updated(M2MBase *base, M2MBase::BaseType type) {
Yogesh Pande 0:7d5ec759888b 285 printf("\r\nPUT Request Received!");
Yogesh Pande 0:7d5ec759888b 286 printf("\r\nName :'%s', \r\nType : '%d' (0 for Object, 1 for Resource), \r\nType : '%s'\r\n",
Yogesh Pande 0:7d5ec759888b 287 base->name().c_str(),
Yogesh Pande 0:7d5ec759888b 288 type,
Yogesh Pande 0:7d5ec759888b 289 base->resource_type().c_str()
Yogesh Pande 0:7d5ec759888b 290 );
Yogesh Pande 0:7d5ec759888b 291 }
Yogesh Pande 0:7d5ec759888b 292
Yogesh Pande 0:7d5ec759888b 293 /*
Yogesh Pande 0:7d5ec759888b 294 * update the registration period
Yogesh Pande 0:7d5ec759888b 295 */
Yogesh Pande 0:7d5ec759888b 296 void test_update_register() {
Yogesh Pande 0:7d5ec759888b 297 if (_registered) {
Yogesh Pande 0:7d5ec759888b 298 _interface->update_registration(_register_security, 100);
Yogesh Pande 0:7d5ec759888b 299 }
Yogesh Pande 0:7d5ec759888b 300 }
Yogesh Pande 0:7d5ec759888b 301
Yogesh Pande 0:7d5ec759888b 302 /*
Yogesh Pande 0:7d5ec759888b 303 * manually configure the security object private variable
Yogesh Pande 0:7d5ec759888b 304 */
Yogesh Pande 0:7d5ec759888b 305 void set_register_object(M2MSecurity *register_object) {
Yogesh Pande 0:7d5ec759888b 306 if (_register_security == NULL) {
Yogesh Pande 0:7d5ec759888b 307 _register_security = register_object;
Yogesh Pande 0:7d5ec759888b 308 }
Yogesh Pande 0:7d5ec759888b 309 }
Yogesh Pande 0:7d5ec759888b 310
Yogesh Pande 0:7d5ec759888b 311 private:
Yogesh Pande 0:7d5ec759888b 312
Yogesh Pande 0:7d5ec759888b 313 /*
Yogesh Pande 0:7d5ec759888b 314 * Private variables used in class
Yogesh Pande 0:7d5ec759888b 315 */
Yogesh Pande 0:7d5ec759888b 316 M2MInterface *_interface;
Yogesh Pande 0:7d5ec759888b 317 M2MSecurity *_register_security;
Yogesh Pande 0:7d5ec759888b 318 M2MObject *_object;
Yogesh Pande 0:7d5ec759888b 319 volatile bool _bootstrapped;
Yogesh Pande 0:7d5ec759888b 320 volatile bool _error;
Yogesh Pande 0:7d5ec759888b 321 volatile bool _registered;
Yogesh Pande 0:7d5ec759888b 322 volatile bool _unregistered;
Yogesh Pande 0:7d5ec759888b 323 int _value;
Yogesh Pande 0:7d5ec759888b 324 struct MbedClientDevice _device;
Yogesh Pande 0:7d5ec759888b 325 String _server_address;
Yogesh Pande 0:7d5ec759888b 326 };
Yogesh Pande 0:7d5ec759888b 327
Yogesh Pande 0:7d5ec759888b 328 #endif // __SIMPLECLIENT_H__