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