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