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