A simple interface to mbed Device Connector, where you just declare variables to push them to the cloud.

Dependents:   Wifi_Get_Test_V1 simple-mbed-client-example simple-client-app-shield simple-sensor-client

Fork of simple-mbed-client by Jan Jongboom

TL;DR? See simple-mbed-client-example to get started immediately.

This library is a simpler interface to mbed Client, making it trivial to expose sensors, actuators and other variables to the cloud. It does not require you to change how you write your code. You can take any local variable, swap it out for a call to Simple Mbed Client, and the variable will automatically be synchronised with mbed Cloud.

For example, here's how you expose the value of a light sensor to the cloud:

SimpleMbedClient client;

SimpleResourceInt light_value = client.define_resource("light/0/value", 0);     // create the var

AnalogIn light(A1);

void read_light_sensor() {
    // light_value behaves just like a normal variable that you can read and write to!
    light_value = light.read_u16();
}

// update every second
Ticker t;
t.attach(&read_light_sensor, 1.0f);

Setting up

First import this library to your project. As Simple Mbed Client also needs a way to talk to the outside world, you'll need a NetworkInterface-object. The easiest way is by using the easy-connect library, so add that to your project as well. See the easy-connect docs on how to specify the connectivity method.

We also need a way of authenticating with mbed Cloud. For this we need a security certificate. Go to mbed Cloud, and select 'GET MY DEVICE SECURITY CREDENTIALS'. Save the certificate as security.h in your project folder.

Now we can initiate Simple Mbed Client and connect it to the internet.

#include "mbed.h"
#include "security.h"
#include "easy-connect.h"
#include "simple-mbed-client.h"

SimpleMbedClient client;

DigitalOut led(LED1, 0);

void registered() {
    led = 1;
}

int main() {
    NetworkInterface* network = connect_to_network(); // if connection failed, network will be NULL
    client.setup(network); // returns a bool, check if it's true

    client.on_registered(&registered);

    while (1) {
        wait_ms(25000);
        client.keep_alive();
    }
}

Defining variables

You can define a new variable by a call to client.define_resource. This function takes five arguments:

  1. path - The URL on which your variable is exposed in mbed Cloud. Needs to be three (3) segments, split by a slash (/) in the form of 'sensor/0/value'. The second segment always needs to be numeric.
  2. defaultValue - The default value of the variable. Needs to be either a string or an integer. Depending on the type that you pass in here the type of the variable is defined.
  3. operation - Some variables might be read-only or write-only (seen from the cloud). Use the operation to define these constraints. It's of type M2MBase::Operation. Default is GET_PUT_ALLOWED.
  4. observable - If set to false, cloud applications cannot subscribe to updates on this variable. Default is true.
  5. callback - Function pointer which is called whenever the value of the variable is changed from the cloud.

The type returned by the function is either SimpleResourceInt or SimpleResourceString. You can assign and read from these variables like any normal local variable.

void name_updated(string new_value) {
    printf("Value is now %s\n", new_value.c_str());
}

SimpleResourceString name = client.define_resource("device/0/name", "jan", M2MBase::GET_PUT_ALLOWED, true, &name_updated);

// we can read and write to this variable, e.g.:
stringstream ss;
ss << name;

// or
name = "pietje";

// are all valid

Defining functions

You can define functions, which do not have a value, but can just be invoked from the cloud, by a call to client.define_function. This function takes two arguments:

  1. path - The URL on which your variable is exposed in mbed Cloud. Needs to be three (3) segments, split by a slash (/) in the form of 'sensor/0/value'. The second segment always needs to be numeric.
  2. callback - Function pointer which is invoked when the function is called. Takes in a pointer, which contains the data being passed in from the cloud.

void play(void* data) {
    if (data) { // data can be NULL!
        // cast it to something useful
    }
}

client.define_function("music/0/play", &play);

Accessing the underlying M2MResource

If you need access to the underlying M2MResource you can do so by calling get_resource on a variable, or by calling client.get_resource if it's a function.

SimpleResourceInt led = client.define_resource("led/0/value", true);

client.define_function("led/0/toggle", &toggleLed);

// now to get the resource
M2MResource* ledResource = led.get_resource();
M2MResource* toggleResource = client.get_resource("led/0/toggle");

Printing variables

Unfortunately printf is kind of dumb, and does not automatically cast the variables. If you want to print any of the Simple Mbed Client variables you'll need to cast yourself.

SimpleResourceInt led = client.define_resource("led/0/value", true);

printf("Value is currently %d\n", static_cast<int>(led));

Event Queue

Simple Mbed Client uses an mbed-events EventQueue - running on a separate RTOS thread - to handle incoming events without blocking the main loop. Both the thread and event queue are created when initializing the library. You can override this behavior by providing your own event queue. In this case no thread is created.

EventQueue myQueue;
SimpleMbedClient client(&myQueue);

You can also use the queue to process your own events, which is very useful when dealing with ISRs. The queue is accessible through the eventQueue() function on the client object and returns a pointer to the queue.

SimpleMbedClient client;

InterruptIn btn(D2);

int main() {
  btn.fall(client.eventQueue()->event(&fall));
}
Committer:
janjongboom
Date:
Sun May 15 20:02:58 2016 +0000
Revision:
0:9fa3f3028773
Child:
3:ce2322965a27
Port of mbed-client-ethernet-c-style to mbed Classic

Who changed what in which revision?

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