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/

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?

UserRevisionLine numberNew 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 #include "mbed-client/m2mvector.h"
edamame22 0:29983394c6b6 17 #include "mbed-client/m2mobject.h"
edamame22 0:29983394c6b6 18 #include "mbed-client/m2mobjectinstance.h"
edamame22 0:29983394c6b6 19 #include "mbed-client/m2mresource.h"
edamame22 0:29983394c6b6 20
edamame22 0:29983394c6b6 21 /**
edamame22 0:29983394c6b6 22 * @brief M2MTLVSerializer
edamame22 0:29983394c6b6 23 * TLV Serialiser constructs the binary representation of object instances,
edamame22 0:29983394c6b6 24 * resources and resource instances (see OMA-LWM2M specification, chapter 6.1
edamame22 0:29983394c6b6 25 * for resource model) as OMA-TLV according described in chapter 6.3.3.
edamame22 0:29983394c6b6 26 *
edamame22 0:29983394c6b6 27 */
edamame22 0:29983394c6b6 28 class M2MTLVSerializer {
edamame22 0:29983394c6b6 29
edamame22 0:29983394c6b6 30 public:
edamame22 0:29983394c6b6 31
edamame22 0:29983394c6b6 32 /**
edamame22 0:29983394c6b6 33 * Constructor.
edamame22 0:29983394c6b6 34 */
edamame22 0:29983394c6b6 35 M2MTLVSerializer();
edamame22 0:29983394c6b6 36
edamame22 0:29983394c6b6 37 /**
edamame22 0:29983394c6b6 38 * Destructor.
edamame22 0:29983394c6b6 39 */
edamame22 0:29983394c6b6 40 ~M2MTLVSerializer();
edamame22 0:29983394c6b6 41
edamame22 0:29983394c6b6 42 /**
edamame22 0:29983394c6b6 43 * Serialises given objects instances that contain resources or multiple
edamame22 0:29983394c6b6 44 * resources. Object instance IDs are also encoded. This method must be
edamame22 0:29983394c6b6 45 * used when an operation targets an object with (potential) multiple
edamame22 0:29983394c6b6 46 * instances like "GET /1". In that case the generated TLV will contain the
edamame22 0:29983394c6b6 47 * following data:
edamame22 0:29983394c6b6 48 * <ul>
edamame22 0:29983394c6b6 49 * <li> ./0
edamame22 0:29983394c6b6 50 * <li> ./0/0
edamame22 0:29983394c6b6 51 * <li> ./0/1
edamame22 0:29983394c6b6 52 * <li> ...
edamame22 0:29983394c6b6 53 * <li> ./1
edamame22 0:29983394c6b6 54 * <li> ./1/0
edamame22 0:29983394c6b6 55 * <li> ./1/1
edamame22 0:29983394c6b6 56 * <li> ...
edamame22 0:29983394c6b6 57 * </ul>
edamame22 0:29983394c6b6 58 *
edamame22 0:29983394c6b6 59 * @param objects List of object instances.
edamame22 0:29983394c6b6 60 * @return Object instances encoded binary as OMA-TLV
edamame22 0:29983394c6b6 61 * @see #serializeObjectInstances(List)
edamame22 0:29983394c6b6 62 */
edamame22 0:29983394c6b6 63 uint8_t* serialize(M2MObjectInstanceList object_instance_list, uint32_t &size);
edamame22 0:29983394c6b6 64
edamame22 0:29983394c6b6 65 /**
edamame22 0:29983394c6b6 66 * Serialises given resources with no information about the parent object
edamame22 0:29983394c6b6 67 * instance. This method must be used when an operation targets an object
edamame22 0:29983394c6b6 68 * instance like "GET /1/0" or a single-instance object like "GET /3//".
edamame22 0:29983394c6b6 69 * Resources may have single or multiple instances. The generated TLV will
edamame22 0:29983394c6b6 70 * contain the following data as response to "GET /3//":
edamame22 0:29983394c6b6 71 * <ul>
edamame22 0:29983394c6b6 72 * <li> ./0
edamame22 0:29983394c6b6 73 * <li> ./1
edamame22 0:29983394c6b6 74 * <li> ./2
edamame22 0:29983394c6b6 75 * <li> ./6/0 (1st instance of a multiple resource)
edamame22 0:29983394c6b6 76 * <li> ./6/1 (2nd instance of a multiple resource)
edamame22 0:29983394c6b6 77 * <li> ...
edamame22 0:29983394c6b6 78 * </ul>
edamame22 0:29983394c6b6 79 * @param resources Array of resources and resource instances.
edamame22 0:29983394c6b6 80 * @return Resources encoded binary as OMA-TLV
edamame22 0:29983394c6b6 81 * @see #serializeResources(List)
edamame22 0:29983394c6b6 82 */
edamame22 0:29983394c6b6 83 uint8_t* serialize(M2MResourceList resource_list, uint32_t &size);
edamame22 0:29983394c6b6 84
edamame22 0:29983394c6b6 85 uint8_t* serialize(M2MResource *resource, uint32_t &size);
edamame22 0:29983394c6b6 86
edamame22 0:29983394c6b6 87 private :
edamame22 0:29983394c6b6 88
edamame22 0:29983394c6b6 89 uint8_t* serialize_object_instances(M2MObjectInstanceList object_instance_list, uint32_t &size);
edamame22 0:29983394c6b6 90
edamame22 0:29983394c6b6 91 uint8_t* serialize_resources(M2MResourceList resource_list, uint32_t &size, bool &valid);
edamame22 0:29983394c6b6 92
edamame22 0:29983394c6b6 93 void serialize(uint16_t id, M2MObjectInstance *object_instance, uint8_t *&data, uint32_t &size);
edamame22 0:29983394c6b6 94
edamame22 0:29983394c6b6 95 bool serialize (M2MResource *resource, uint8_t *&data, uint32_t &size);
edamame22 0:29983394c6b6 96
edamame22 0:29983394c6b6 97 bool serialize_resource(M2MResource *resource, uint8_t *&data, uint32_t &size);
edamame22 0:29983394c6b6 98
edamame22 0:29983394c6b6 99 bool serialize_multiple_resource(M2MResource *resource, uint8_t *&data, uint32_t &size);
edamame22 0:29983394c6b6 100
edamame22 0:29983394c6b6 101 void serialize_resource_instance(uint16_t id, M2MResourceInstance *resource, uint8_t *&data, uint32_t &size);
edamame22 0:29983394c6b6 102
edamame22 0:29983394c6b6 103 void serialize_TILV (uint8_t type, uint16_t id, uint8_t *value, uint32_t value_length, uint8_t *&data, uint32_t &size);
edamame22 0:29983394c6b6 104
edamame22 0:29983394c6b6 105 uint8_t* serialize_id(uint16_t id, uint32_t &size);
edamame22 0:29983394c6b6 106
edamame22 0:29983394c6b6 107 uint8_t* serialize_length(uint32_t length, uint32_t &size);
edamame22 0:29983394c6b6 108 };