This is a mbed Client sample where ZXing is incorporated, and works on GR-PEACH and GR-LYCHEE.
Dependencies: DisplayApp AsciiFont
Overview
This sample program shows how to use mbed Client together with ZXing which is an open-source, multi-format 1D/2D barcode image processing library. For more info on ZXing, please refer to https://github.com/zxing/zxing.
Required hardware
- GR-PEACH ( https://developer.mbed.org/platforms/Renesas-GR-PEACH/ )
- Audio Camera Shield ( https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield )
- LCD Shield ( https://developer.mbed.org/teams/Renesas/wiki/LCD-shield )
- Ethernet cable and connection to the internet
- Wireless Camera shieled (This is GR-PEACH' Wifi(ESP32) optional.)
- GR-LYCHEE ( https://developer.mbed.org/platforms/Renesas-GR-LYCHEE/ )
Application setup
- Select the connection type. For details, please refer to the following wiki:
https://os.mbed.com/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/wiki/Connection-type. - Set the client credentials. For details, please refer to the following wiki:
https://os.mbed.com/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/wiki/Client-credentials. - Change Ethernet settings. For details, please refer to the following wiki:
https://developer.mbed.org/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/wiki/Ethernet-settings. - Change Wifi settings. For details, please refer to the following wiki:
https://os.mbed.com/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/wiki/Wifi-settings. - Set up an IP address. (This step is optional.) For details, please refer to the following wiki:
https://os.mbed.com/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/wiki/IP-address-setup.
Building the example
To build this example:
- Import this example onto mbed Compiler.
- Configure the example in accordance with Application setup.
- Compile the example on mbed Compiler and download the resultant binary file.
- Plug the Ethernet cable into GR-PEACH or GR-LYCHEE if you are using Ethernet mode.
- Plug the micro-USB cable into the OpenSDA port which lies on the next to the RESET button.
- Copy the binary previously downloaded to your PC to GR-PEACH or GR-LYCHEE to flash this example. When the copy is successfully completed, the board is ready to work.
- Press the RESET button on the board to run the example.
- For verification, please refer to the following wiki:
https://developer.mbed.org/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/wiki/Monitoring-the-application.
Application resources
This example exposes four resources listed below:
- 3202/0/5700. Decode result of barcode data input from camera (GET).
- 3201/0/5850. Blink function, blinks LED when executed (POST).
- 3201/0/5853. Blink pattern, used by the blink function to determine how to blink. In the format of 1000:500:1000:500:1000:500 (PUT).
- 3201/0/5855. Blink color, used by the blink function. Any of red, green, blue, cyan, yellow and magenta is acceptable if you are using GR-PEACH board (PUT).
- 3201/0/5855. Blink color, used by the blink function. Any of green, yellow, orange and red is acceptable if you are using GR-LYCHEE board (PUT).
For more info on how to get notifications when resource 1 changes, or how to use resource 2, 3 and 4, please look at
Import programGR-PEACH_mbed-connector-ZXingSample-node
Node.js based Web Application for mbed Device Connector specific to GR-PEACH_mbed-os-client-ZXingSample
simpleclient.h@6:ea24d9271ff1, 2018-12-13 (annotated)
- Committer:
- 1050186
- Date:
- Thu Dec 13 08:28:47 2018 +0000
- Revision:
- 6:ea24d9271ff1
- Parent:
- 2:6ec5c1c1d41c
Update each library(Mbed OS 5.9.7, mbed-os-client).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 0:eb73febb2bba | 1 | /* |
<> | 0:eb73febb2bba | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
<> | 0:eb73febb2bba | 3 | * SPDX-License-Identifier: Apache-2.0 |
<> | 0:eb73febb2bba | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
<> | 0:eb73febb2bba | 5 | * not use this file except in compliance with the License. |
<> | 0:eb73febb2bba | 6 | * You may obtain a copy of the License at |
<> | 0:eb73febb2bba | 7 | * |
<> | 0:eb73febb2bba | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 0:eb73febb2bba | 9 | * |
<> | 0:eb73febb2bba | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 0:eb73febb2bba | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
<> | 0:eb73febb2bba | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 0:eb73febb2bba | 13 | * See the License for the specific language governing permissions and |
<> | 0:eb73febb2bba | 14 | * limitations under the License. |
<> | 0:eb73febb2bba | 15 | */ |
<> | 0:eb73febb2bba | 16 | |
<> | 0:eb73febb2bba | 17 | #ifndef __SIMPLECLIENT_H__ |
<> | 0:eb73febb2bba | 18 | #define __SIMPLECLIENT_H__ |
<> | 0:eb73febb2bba | 19 | |
<> | 0:eb73febb2bba | 20 | #include "mbed-client/m2minterfacefactory.h" |
<> | 0:eb73febb2bba | 21 | #include "mbed-client/m2mdevice.h" |
<> | 0:eb73febb2bba | 22 | #include "mbed-client/m2minterfaceobserver.h" |
<> | 0:eb73febb2bba | 23 | #include "mbed-client/m2minterface.h" |
<> | 0:eb73febb2bba | 24 | #include "mbed-client/m2mobject.h" |
<> | 0:eb73febb2bba | 25 | #include "mbed-client/m2mobjectinstance.h" |
<> | 0:eb73febb2bba | 26 | #include "mbed-client/m2mresource.h" |
<> | 0:eb73febb2bba | 27 | #include "mbed-client/m2mconfig.h" |
dkato | 2:6ec5c1c1d41c | 28 | #include "mbed-client/m2mblockmessage.h" |
<> | 0:eb73febb2bba | 29 | #include "security.h" |
<> | 0:eb73febb2bba | 30 | #include "mbed.h" |
<> | 0:eb73febb2bba | 31 | |
dkato | 2:6ec5c1c1d41c | 32 | #define STRINGIFY(s) #s |
dkato | 2:6ec5c1c1d41c | 33 | |
1050186 | 6:ea24d9271ff1 | 34 | // EASY_CONNECT_MESH coming via easy-connect |
1050186 | 6:ea24d9271ff1 | 35 | #if defined (EASY_CONNECT_MESH) || (MBED_CONF_LWIP_IPV6_ENABLED==true) |
dkato | 2:6ec5c1c1d41c | 36 | // Mesh is always IPV6 - also WiFi and ETH can be IPV6 if IPV6 is enabled |
dkato | 2:6ec5c1c1d41c | 37 | M2MInterface::NetworkStack NETWORK_STACK = M2MInterface::LwIP_IPv6; |
dkato | 2:6ec5c1c1d41c | 38 | #else |
dkato | 2:6ec5c1c1d41c | 39 | // Everything else - we assume it's IPv4 |
dkato | 2:6ec5c1c1d41c | 40 | M2MInterface::NetworkStack NETWORK_STACK = M2MInterface::LwIP_IPv4; |
dkato | 2:6ec5c1c1d41c | 41 | #endif |
dkato | 2:6ec5c1c1d41c | 42 | |
dkato | 2:6ec5c1c1d41c | 43 | //Select binding mode: UDP or TCP -- note - Mesh networking is IPv6 UDP ONLY |
1050186 | 6:ea24d9271ff1 | 44 | #if defined (EASY_CONNECT_MESH) |
dkato | 2:6ec5c1c1d41c | 45 | M2MInterface::BindingMode SOCKET_MODE = M2MInterface::UDP; |
dkato | 2:6ec5c1c1d41c | 46 | #else |
dkato | 2:6ec5c1c1d41c | 47 | // WiFi or Ethernet supports both - TCP by default to avoid |
dkato | 2:6ec5c1c1d41c | 48 | // NAT problems, but UDP will also work - IF you configure |
dkato | 2:6ec5c1c1d41c | 49 | // your network right. |
dkato | 2:6ec5c1c1d41c | 50 | M2MInterface::BindingMode SOCKET_MODE = M2MInterface::TCP; |
dkato | 2:6ec5c1c1d41c | 51 | #endif |
dkato | 2:6ec5c1c1d41c | 52 | |
<> | 0:eb73febb2bba | 53 | |
<> | 0:eb73febb2bba | 54 | // MBED_DOMAIN and MBED_ENDPOINT_NAME come |
<> | 0:eb73febb2bba | 55 | // from the security.h file copied from connector.mbed.com |
<> | 0:eb73febb2bba | 56 | |
<> | 0:eb73febb2bba | 57 | struct MbedClientDevice { |
<> | 0:eb73febb2bba | 58 | const char* Manufacturer; |
<> | 0:eb73febb2bba | 59 | const char* Type; |
<> | 0:eb73febb2bba | 60 | const char* ModelNumber; |
<> | 0:eb73febb2bba | 61 | const char* SerialNumber; |
<> | 0:eb73febb2bba | 62 | }; |
<> | 0:eb73febb2bba | 63 | |
<> | 0:eb73febb2bba | 64 | /* |
<> | 0:eb73febb2bba | 65 | * Wrapper for mbed client stack that handles all callbacks, error handling, and |
<> | 0:eb73febb2bba | 66 | * other shenanigans to make the mbed client stack easier to use. |
<> | 0:eb73febb2bba | 67 | * |
<> | 0:eb73febb2bba | 68 | * The end user should only have to care about configuring the parameters at the |
<> | 0:eb73febb2bba | 69 | * top of this file and making sure they add the security.h file correctly. |
<> | 0:eb73febb2bba | 70 | * To add resources you can copy the _TODO__ function and add as many instances as |
<> | 0:eb73febb2bba | 71 | * you want. |
<> | 0:eb73febb2bba | 72 | * |
<> | 0:eb73febb2bba | 73 | */ |
<> | 0:eb73febb2bba | 74 | class MbedClient: public M2MInterfaceObserver { |
<> | 0:eb73febb2bba | 75 | public: |
<> | 0:eb73febb2bba | 76 | |
<> | 0:eb73febb2bba | 77 | // constructor for MbedClient object, initialize private variables |
<> | 0:eb73febb2bba | 78 | MbedClient(struct MbedClientDevice device) { |
<> | 0:eb73febb2bba | 79 | _interface = NULL; |
<> | 0:eb73febb2bba | 80 | _bootstrapped = false; |
<> | 0:eb73febb2bba | 81 | _error = false; |
<> | 0:eb73febb2bba | 82 | _registered = false; |
<> | 0:eb73febb2bba | 83 | _unregistered = false; |
<> | 0:eb73febb2bba | 84 | _register_security = NULL; |
<> | 0:eb73febb2bba | 85 | _value = 0; |
<> | 0:eb73febb2bba | 86 | _object = NULL; |
<> | 0:eb73febb2bba | 87 | _device = device; |
<> | 0:eb73febb2bba | 88 | } |
<> | 0:eb73febb2bba | 89 | |
<> | 0:eb73febb2bba | 90 | // de-constructor for MbedClient object, you can ignore this |
<> | 0:eb73febb2bba | 91 | ~MbedClient() { |
<> | 0:eb73febb2bba | 92 | if(_interface) { |
<> | 0:eb73febb2bba | 93 | delete _interface; |
<> | 0:eb73febb2bba | 94 | } |
<> | 0:eb73febb2bba | 95 | if(_register_security){ |
<> | 0:eb73febb2bba | 96 | delete _register_security; |
<> | 0:eb73febb2bba | 97 | } |
<> | 0:eb73febb2bba | 98 | } |
<> | 0:eb73febb2bba | 99 | |
<> | 0:eb73febb2bba | 100 | // debug printf function |
<> | 0:eb73febb2bba | 101 | void trace_printer(const char* str) { |
<> | 0:eb73febb2bba | 102 | printf("\r\n%s\r\n", str); |
<> | 0:eb73febb2bba | 103 | } |
<> | 0:eb73febb2bba | 104 | |
<> | 0:eb73febb2bba | 105 | /* |
<> | 0:eb73febb2bba | 106 | * Creates M2MInterface using which endpoint can |
<> | 0:eb73febb2bba | 107 | * setup its name, resource type, life time, connection mode, |
<> | 0:eb73febb2bba | 108 | * Currently only LwIPv4 is supported. |
<> | 0:eb73febb2bba | 109 | */ |
<> | 0:eb73febb2bba | 110 | void create_interface(const char *server_address, |
<> | 0:eb73febb2bba | 111 | void *handler=NULL) { |
dkato | 2:6ec5c1c1d41c | 112 | // Randomizing listening port for Certificate mode connectivity |
<> | 0:eb73febb2bba | 113 | _server_address = server_address; |
dkato | 2:6ec5c1c1d41c | 114 | uint16_t port = 0; // Network interface will randomize with port 0 |
<> | 0:eb73febb2bba | 115 | |
<> | 0:eb73febb2bba | 116 | // create mDS interface object, this is the base object everything else attaches to |
<> | 0:eb73febb2bba | 117 | _interface = M2MInterfaceFactory::create_interface(*this, |
<> | 0:eb73febb2bba | 118 | MBED_ENDPOINT_NAME, // endpoint name string |
<> | 0:eb73febb2bba | 119 | "test", // endpoint type string |
<> | 0:eb73febb2bba | 120 | 100, // lifetime |
<> | 0:eb73febb2bba | 121 | port, // listen port |
<> | 0:eb73febb2bba | 122 | MBED_DOMAIN, // domain string |
<> | 0:eb73febb2bba | 123 | SOCKET_MODE, // binding mode |
dkato | 2:6ec5c1c1d41c | 124 | NETWORK_STACK, // network stack |
<> | 0:eb73febb2bba | 125 | ""); // context address string |
<> | 0:eb73febb2bba | 126 | const char *binding_mode = (SOCKET_MODE == M2MInterface::UDP) ? "UDP" : "TCP"; |
<> | 0:eb73febb2bba | 127 | printf("\r\nSOCKET_MODE : %s\r\n", binding_mode); |
<> | 0:eb73febb2bba | 128 | printf("Connecting to %s\r\n", server_address); |
<> | 0:eb73febb2bba | 129 | |
<> | 0:eb73febb2bba | 130 | if(_interface) { |
<> | 0:eb73febb2bba | 131 | _interface->set_platform_network_handler(handler); |
<> | 0:eb73febb2bba | 132 | } |
<> | 0:eb73febb2bba | 133 | |
<> | 0:eb73febb2bba | 134 | } |
<> | 0:eb73febb2bba | 135 | |
<> | 0:eb73febb2bba | 136 | /* |
<> | 0:eb73febb2bba | 137 | * check private variable to see if the registration was sucessful or not |
<> | 0:eb73febb2bba | 138 | */ |
<> | 0:eb73febb2bba | 139 | bool register_successful() { |
<> | 0:eb73febb2bba | 140 | return _registered; |
<> | 0:eb73febb2bba | 141 | } |
<> | 0:eb73febb2bba | 142 | |
<> | 0:eb73febb2bba | 143 | /* |
<> | 0:eb73febb2bba | 144 | * check private variable to see if un-registration was sucessful or not |
<> | 0:eb73febb2bba | 145 | */ |
<> | 0:eb73febb2bba | 146 | bool unregister_successful() { |
<> | 0:eb73febb2bba | 147 | return _unregistered; |
<> | 0:eb73febb2bba | 148 | } |
<> | 0:eb73febb2bba | 149 | |
<> | 0:eb73febb2bba | 150 | /* |
<> | 0:eb73febb2bba | 151 | * Creates register server object with mbed device server address and other parameters |
<> | 0:eb73febb2bba | 152 | * required for client to connect to mbed device server. |
<> | 0:eb73febb2bba | 153 | */ |
<> | 0:eb73febb2bba | 154 | M2MSecurity* create_register_object() { |
<> | 0:eb73febb2bba | 155 | // create security object using the interface factory. |
<> | 0:eb73febb2bba | 156 | // this will generate a security ObjectID and ObjectInstance |
<> | 0:eb73febb2bba | 157 | M2MSecurity *security = M2MInterfaceFactory::create_security(M2MSecurity::M2MServer); |
<> | 0:eb73febb2bba | 158 | |
<> | 0:eb73febb2bba | 159 | // make sure security ObjectID/ObjectInstance was created successfully |
<> | 0:eb73febb2bba | 160 | if(security) { |
<> | 0:eb73febb2bba | 161 | // Add ResourceID's and values to the security ObjectID/ObjectInstance |
<> | 0:eb73febb2bba | 162 | security->set_resource_value(M2MSecurity::M2MServerUri, _server_address); |
<> | 0:eb73febb2bba | 163 | security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate); |
dkato | 2:6ec5c1c1d41c | 164 | security->set_resource_value(M2MSecurity::ServerPublicKey, SERVER_CERT, sizeof(SERVER_CERT) - 1); |
dkato | 2:6ec5c1c1d41c | 165 | security->set_resource_value(M2MSecurity::PublicKey, CERT, sizeof(CERT) - 1); |
dkato | 2:6ec5c1c1d41c | 166 | security->set_resource_value(M2MSecurity::Secretkey, KEY, sizeof(KEY) - 1); |
<> | 0:eb73febb2bba | 167 | } |
<> | 0:eb73febb2bba | 168 | return security; |
<> | 0:eb73febb2bba | 169 | } |
<> | 0:eb73febb2bba | 170 | |
<> | 0:eb73febb2bba | 171 | /* |
<> | 0:eb73febb2bba | 172 | * Creates device object which contains mandatory resources linked with |
<> | 0:eb73febb2bba | 173 | * device endpoint. |
<> | 0:eb73febb2bba | 174 | */ |
<> | 0:eb73febb2bba | 175 | M2MDevice* create_device_object() { |
<> | 0:eb73febb2bba | 176 | // create device objectID/ObjectInstance |
<> | 0:eb73febb2bba | 177 | M2MDevice *device = M2MInterfaceFactory::create_device(); |
<> | 0:eb73febb2bba | 178 | // make sure device object was created successfully |
<> | 0:eb73febb2bba | 179 | if(device) { |
<> | 0:eb73febb2bba | 180 | // add resourceID's to device objectID/ObjectInstance |
<> | 0:eb73febb2bba | 181 | device->create_resource(M2MDevice::Manufacturer, _device.Manufacturer); |
<> | 0:eb73febb2bba | 182 | device->create_resource(M2MDevice::DeviceType, _device.Type); |
<> | 0:eb73febb2bba | 183 | device->create_resource(M2MDevice::ModelNumber, _device.ModelNumber); |
<> | 0:eb73febb2bba | 184 | device->create_resource(M2MDevice::SerialNumber, _device.SerialNumber); |
<> | 0:eb73febb2bba | 185 | } |
<> | 0:eb73febb2bba | 186 | return device; |
<> | 0:eb73febb2bba | 187 | } |
<> | 0:eb73febb2bba | 188 | |
<> | 0:eb73febb2bba | 189 | /* |
<> | 0:eb73febb2bba | 190 | * register an object |
<> | 0:eb73febb2bba | 191 | */ |
<> | 0:eb73febb2bba | 192 | void test_register(M2MSecurity *register_object, M2MObjectList object_list){ |
<> | 0:eb73febb2bba | 193 | if(_interface) { |
<> | 0:eb73febb2bba | 194 | // Register function |
<> | 0:eb73febb2bba | 195 | _interface->register_object(register_object, object_list); |
<> | 0:eb73febb2bba | 196 | } |
<> | 0:eb73febb2bba | 197 | } |
<> | 0:eb73febb2bba | 198 | |
<> | 0:eb73febb2bba | 199 | /* |
<> | 0:eb73febb2bba | 200 | * unregister all objects |
<> | 0:eb73febb2bba | 201 | */ |
<> | 0:eb73febb2bba | 202 | void test_unregister() { |
<> | 0:eb73febb2bba | 203 | if(_interface) { |
<> | 0:eb73febb2bba | 204 | // Unregister function |
<> | 0:eb73febb2bba | 205 | _interface->unregister_object(NULL); // NULL will unregister all objects |
<> | 0:eb73febb2bba | 206 | } |
<> | 0:eb73febb2bba | 207 | } |
<> | 0:eb73febb2bba | 208 | |
<> | 0:eb73febb2bba | 209 | //Callback from mbed client stack when the bootstrap |
<> | 0:eb73febb2bba | 210 | // is successful, it returns the mbed Device Server object |
<> | 0:eb73febb2bba | 211 | // which will be used for registering the resources to |
<> | 0:eb73febb2bba | 212 | // mbed Device server. |
<> | 0:eb73febb2bba | 213 | void bootstrap_done(M2MSecurity *server_object){ |
<> | 0:eb73febb2bba | 214 | if(server_object) { |
<> | 0:eb73febb2bba | 215 | _bootstrapped = true; |
<> | 0:eb73febb2bba | 216 | _error = false; |
<> | 0:eb73febb2bba | 217 | trace_printer("Bootstrapped"); |
<> | 0:eb73febb2bba | 218 | } |
<> | 0:eb73febb2bba | 219 | } |
<> | 0:eb73febb2bba | 220 | |
<> | 0:eb73febb2bba | 221 | //Callback from mbed client stack when the registration |
<> | 0:eb73febb2bba | 222 | // is successful, it returns the mbed Device Server object |
<> | 0:eb73febb2bba | 223 | // to which the resources are registered and registered objects. |
<> | 0:eb73febb2bba | 224 | void object_registered(M2MSecurity */*security_object*/, const M2MServer &/*server_object*/){ |
<> | 0:eb73febb2bba | 225 | _registered = true; |
<> | 0:eb73febb2bba | 226 | _unregistered = false; |
<> | 0:eb73febb2bba | 227 | trace_printer("Registered object successfully!"); |
<> | 0:eb73febb2bba | 228 | } |
<> | 0:eb73febb2bba | 229 | |
<> | 0:eb73febb2bba | 230 | //Callback from mbed client stack when the unregistration |
<> | 0:eb73febb2bba | 231 | // is successful, it returns the mbed Device Server object |
<> | 0:eb73febb2bba | 232 | // to which the resources were unregistered. |
<> | 0:eb73febb2bba | 233 | void object_unregistered(M2MSecurity */*server_object*/){ |
<> | 0:eb73febb2bba | 234 | trace_printer("Unregistered Object Successfully"); |
<> | 0:eb73febb2bba | 235 | _unregistered = true; |
dkato | 2:6ec5c1c1d41c | 236 | _registered = false; |
<> | 0:eb73febb2bba | 237 | } |
<> | 0:eb73febb2bba | 238 | |
<> | 0:eb73febb2bba | 239 | /* |
<> | 0:eb73febb2bba | 240 | * Callback from mbed client stack when registration is updated |
<> | 0:eb73febb2bba | 241 | */ |
<> | 0:eb73febb2bba | 242 | void registration_updated(M2MSecurity */*security_object*/, const M2MServer & /*server_object*/){ |
<> | 0:eb73febb2bba | 243 | /* The registration is updated automatically and frequently by the |
<> | 0:eb73febb2bba | 244 | * mbed client stack. This print statement is turned off because it |
<> | 0:eb73febb2bba | 245 | * tends to happen alot. |
<> | 0:eb73febb2bba | 246 | */ |
<> | 0:eb73febb2bba | 247 | //trace_printer("\r\nRegistration Updated\r\n"); |
<> | 0:eb73febb2bba | 248 | } |
<> | 0:eb73febb2bba | 249 | |
<> | 0:eb73febb2bba | 250 | // Callback from mbed client stack if any error is encountered |
<> | 0:eb73febb2bba | 251 | // during any of the LWM2M operations. Error type is passed in |
<> | 0:eb73febb2bba | 252 | // the callback. |
<> | 0:eb73febb2bba | 253 | void error(M2MInterface::Error error){ |
<> | 0:eb73febb2bba | 254 | _error = true; |
<> | 0:eb73febb2bba | 255 | switch(error){ |
<> | 0:eb73febb2bba | 256 | case M2MInterface::AlreadyExists: |
<> | 0:eb73febb2bba | 257 | trace_printer("[ERROR:] M2MInterface::AlreadyExist"); |
<> | 0:eb73febb2bba | 258 | break; |
<> | 0:eb73febb2bba | 259 | case M2MInterface::BootstrapFailed: |
<> | 0:eb73febb2bba | 260 | trace_printer("[ERROR:] M2MInterface::BootstrapFailed"); |
<> | 0:eb73febb2bba | 261 | break; |
<> | 0:eb73febb2bba | 262 | case M2MInterface::InvalidParameters: |
<> | 0:eb73febb2bba | 263 | trace_printer("[ERROR:] M2MInterface::InvalidParameters"); |
<> | 0:eb73febb2bba | 264 | break; |
<> | 0:eb73febb2bba | 265 | case M2MInterface::NotRegistered: |
<> | 0:eb73febb2bba | 266 | trace_printer("[ERROR:] M2MInterface::NotRegistered"); |
<> | 0:eb73febb2bba | 267 | break; |
<> | 0:eb73febb2bba | 268 | case M2MInterface::Timeout: |
<> | 0:eb73febb2bba | 269 | trace_printer("[ERROR:] M2MInterface::Timeout"); |
<> | 0:eb73febb2bba | 270 | break; |
<> | 0:eb73febb2bba | 271 | case M2MInterface::NetworkError: |
<> | 0:eb73febb2bba | 272 | trace_printer("[ERROR:] M2MInterface::NetworkError"); |
<> | 0:eb73febb2bba | 273 | break; |
<> | 0:eb73febb2bba | 274 | case M2MInterface::ResponseParseFailed: |
<> | 0:eb73febb2bba | 275 | trace_printer("[ERROR:] M2MInterface::ResponseParseFailed"); |
<> | 0:eb73febb2bba | 276 | break; |
<> | 0:eb73febb2bba | 277 | case M2MInterface::UnknownError: |
<> | 0:eb73febb2bba | 278 | trace_printer("[ERROR:] M2MInterface::UnknownError"); |
<> | 0:eb73febb2bba | 279 | break; |
<> | 0:eb73febb2bba | 280 | case M2MInterface::MemoryFail: |
<> | 0:eb73febb2bba | 281 | trace_printer("[ERROR:] M2MInterface::MemoryFail"); |
<> | 0:eb73febb2bba | 282 | break; |
<> | 0:eb73febb2bba | 283 | case M2MInterface::NotAllowed: |
<> | 0:eb73febb2bba | 284 | trace_printer("[ERROR:] M2MInterface::NotAllowed"); |
<> | 0:eb73febb2bba | 285 | break; |
<> | 0:eb73febb2bba | 286 | case M2MInterface::SecureConnectionFailed: |
<> | 0:eb73febb2bba | 287 | trace_printer("[ERROR:] M2MInterface::SecureConnectionFailed"); |
<> | 0:eb73febb2bba | 288 | break; |
<> | 0:eb73febb2bba | 289 | case M2MInterface::DnsResolvingFailed: |
<> | 0:eb73febb2bba | 290 | trace_printer("[ERROR:] M2MInterface::DnsResolvingFailed"); |
<> | 0:eb73febb2bba | 291 | break; |
<> | 0:eb73febb2bba | 292 | |
<> | 0:eb73febb2bba | 293 | default: |
<> | 0:eb73febb2bba | 294 | break; |
<> | 0:eb73febb2bba | 295 | } |
<> | 0:eb73febb2bba | 296 | } |
<> | 0:eb73febb2bba | 297 | |
<> | 0:eb73febb2bba | 298 | /* Callback from mbed client stack if any value has changed |
<> | 0:eb73febb2bba | 299 | * during PUT operation. Object and its type is passed in |
<> | 0:eb73febb2bba | 300 | * the callback. |
<> | 0:eb73febb2bba | 301 | * BaseType enum from m2mbase.h |
<> | 0:eb73febb2bba | 302 | * Object = 0x0, Resource = 0x1, ObjectInstance = 0x2, ResourceInstance = 0x3 |
<> | 0:eb73febb2bba | 303 | */ |
<> | 0:eb73febb2bba | 304 | void value_updated(M2MBase *base, M2MBase::BaseType type) { |
<> | 0:eb73febb2bba | 305 | printf("\r\nPUT Request Received!"); |
dkato | 2:6ec5c1c1d41c | 306 | printf("\r\nName :'%s', \r\nPath : '%s', \r\nType : '%d' (0 for Object, 1 for Resource), \r\nType : '%s'\r\n", |
dkato | 2:6ec5c1c1d41c | 307 | base->name(), |
dkato | 2:6ec5c1c1d41c | 308 | base->uri_path(), |
<> | 0:eb73febb2bba | 309 | type, |
dkato | 2:6ec5c1c1d41c | 310 | base->resource_type() |
<> | 0:eb73febb2bba | 311 | ); |
<> | 0:eb73febb2bba | 312 | } |
<> | 0:eb73febb2bba | 313 | |
<> | 0:eb73febb2bba | 314 | /* |
<> | 0:eb73febb2bba | 315 | * update the registration period |
<> | 0:eb73febb2bba | 316 | */ |
<> | 0:eb73febb2bba | 317 | void test_update_register() { |
<> | 0:eb73febb2bba | 318 | if (_registered) { |
<> | 0:eb73febb2bba | 319 | _interface->update_registration(_register_security, 100); |
<> | 0:eb73febb2bba | 320 | } |
<> | 0:eb73febb2bba | 321 | } |
<> | 0:eb73febb2bba | 322 | |
<> | 0:eb73febb2bba | 323 | /* |
<> | 0:eb73febb2bba | 324 | * manually configure the security object private variable |
<> | 0:eb73febb2bba | 325 | */ |
<> | 0:eb73febb2bba | 326 | void set_register_object(M2MSecurity *register_object) { |
<> | 0:eb73febb2bba | 327 | if (_register_security == NULL) { |
<> | 0:eb73febb2bba | 328 | _register_security = register_object; |
<> | 0:eb73febb2bba | 329 | } |
<> | 0:eb73febb2bba | 330 | } |
<> | 0:eb73febb2bba | 331 | |
<> | 0:eb73febb2bba | 332 | private: |
<> | 0:eb73febb2bba | 333 | |
<> | 0:eb73febb2bba | 334 | /* |
<> | 0:eb73febb2bba | 335 | * Private variables used in class |
<> | 0:eb73febb2bba | 336 | */ |
<> | 0:eb73febb2bba | 337 | M2MInterface *_interface; |
<> | 0:eb73febb2bba | 338 | M2MSecurity *_register_security; |
<> | 0:eb73febb2bba | 339 | M2MObject *_object; |
<> | 0:eb73febb2bba | 340 | volatile bool _bootstrapped; |
<> | 0:eb73febb2bba | 341 | volatile bool _error; |
<> | 0:eb73febb2bba | 342 | volatile bool _registered; |
<> | 0:eb73febb2bba | 343 | volatile bool _unregistered; |
<> | 0:eb73febb2bba | 344 | int _value; |
<> | 0:eb73febb2bba | 345 | struct MbedClientDevice _device; |
<> | 0:eb73febb2bba | 346 | String _server_address; |
<> | 0:eb73febb2bba | 347 | }; |
<> | 0:eb73febb2bba | 348 | |
<> | 0:eb73febb2bba | 349 | #endif // __SIMPLECLIENT_H__ |