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 #ifndef M2MREPORTHANDLER_H
edamame22 0:29983394c6b6 17 #define M2MREPORTHANDLER_H
edamame22 0:29983394c6b6 18
edamame22 0:29983394c6b6 19 // Support for std args
edamame22 0:29983394c6b6 20 #include <stdint.h>
edamame22 0:29983394c6b6 21 #include "mbed-client/m2mconfig.h"
edamame22 0:29983394c6b6 22 #include "mbed-client/m2mbase.h"
edamame22 0:29983394c6b6 23 #include "mbed-client/m2mtimerobserver.h"
edamame22 0:29983394c6b6 24 #include "mbed-client/m2mresourceinstance.h"
edamame22 0:29983394c6b6 25 #include "mbed-client/m2mvector.h"
edamame22 0:29983394c6b6 26 #include "mbed-client/m2mtimer.h"
edamame22 0:29983394c6b6 27
edamame22 0:29983394c6b6 28 //FORWARD DECLARATION
edamame22 0:29983394c6b6 29 class M2MReportObserver;
edamame22 0:29983394c6b6 30 class M2MTimer;
edamame22 0:29983394c6b6 31 class M2MResourceInstance;
edamame22 0:29983394c6b6 32
edamame22 0:29983394c6b6 33 /**
edamame22 0:29983394c6b6 34 * @brief M2MReportHandler.
edamame22 0:29983394c6b6 35 * This class is handles all the observation related operations.
edamame22 0:29983394c6b6 36 */
edamame22 0:29983394c6b6 37 class M2MReportHandler: public M2MTimerObserver
edamame22 0:29983394c6b6 38 {
edamame22 0:29983394c6b6 39 private:
edamame22 0:29983394c6b6 40 // Prevents the use of assignment operator by accident.
edamame22 0:29983394c6b6 41 M2MReportHandler& operator=( const M2MReportHandler& /*other*/ );
edamame22 0:29983394c6b6 42
edamame22 0:29983394c6b6 43 public:
edamame22 0:29983394c6b6 44
edamame22 0:29983394c6b6 45 M2MReportHandler(M2MReportObserver &observer);
edamame22 0:29983394c6b6 46
edamame22 0:29983394c6b6 47 public:
edamame22 0:29983394c6b6 48
edamame22 0:29983394c6b6 49 /**
edamame22 0:29983394c6b6 50 * Enum defining which write attributes are set.
edamame22 0:29983394c6b6 51 */
edamame22 0:29983394c6b6 52 enum {
edamame22 0:29983394c6b6 53 Cancel = 1,
edamame22 0:29983394c6b6 54 Pmin = 2,
edamame22 0:29983394c6b6 55 Pmax = 4,
edamame22 0:29983394c6b6 56 Lt = 8,
edamame22 0:29983394c6b6 57 Gt = 16,
edamame22 0:29983394c6b6 58 St = 32
edamame22 0:29983394c6b6 59 };
edamame22 0:29983394c6b6 60
edamame22 0:29983394c6b6 61 /**
edamame22 0:29983394c6b6 62 * Destructor
edamame22 0:29983394c6b6 63 */
edamame22 0:29983394c6b6 64 virtual ~M2MReportHandler();
edamame22 0:29983394c6b6 65
edamame22 0:29983394c6b6 66 /**
edamame22 0:29983394c6b6 67 * @brief Sets that object is under observation.
edamame22 0:29983394c6b6 68 * @param Value for the observation.
edamame22 0:29983394c6b6 69 * @param handler, Handler object for sending
edamame22 0:29983394c6b6 70 * observation callbacks.
edamame22 0:29983394c6b6 71 */
edamame22 0:29983394c6b6 72 void set_under_observation(bool observed);
edamame22 0:29983394c6b6 73
edamame22 0:29983394c6b6 74 /**
edamame22 0:29983394c6b6 75 * @brief Sets the value of the given resource.
edamame22 0:29983394c6b6 76 * @param value, Value of the observed resource.
edamame22 0:29983394c6b6 77 */
edamame22 0:29983394c6b6 78 void set_value(float value);
edamame22 0:29983394c6b6 79
edamame22 0:29983394c6b6 80 /**
edamame22 0:29983394c6b6 81 * @brief Sets notification trigger.
edamame22 0:29983394c6b6 82 * @param obj_instance_id, Object instance id that has changed
edamame22 0:29983394c6b6 83 */
edamame22 0:29983394c6b6 84 void set_notification_trigger(uint16_t obj_instance_id = 0);
edamame22 0:29983394c6b6 85
edamame22 0:29983394c6b6 86 /**
edamame22 0:29983394c6b6 87 * @brief Parses the received query for notification
edamame22 0:29983394c6b6 88 * attribute.
edamame22 0:29983394c6b6 89 * @param query Query to be parsed for attributes.
edamame22 0:29983394c6b6 90 * @param type Type of the Base Object.
edamame22 0:29983394c6b6 91 * @param resource_type Type of the Resource.
edamame22 0:29983394c6b6 92 * @return true if required attributes are present else false.
edamame22 0:29983394c6b6 93 */
edamame22 0:29983394c6b6 94 bool parse_notification_attribute(const char *query,
edamame22 0:29983394c6b6 95 M2MBase::BaseType type,
edamame22 0:29983394c6b6 96 M2MResourceInstance::ResourceType resource_type = M2MResourceInstance::OPAQUE);
edamame22 0:29983394c6b6 97
edamame22 0:29983394c6b6 98 /**
edamame22 0:29983394c6b6 99 * @brief Set back to default values.
edamame22 0:29983394c6b6 100 */
edamame22 0:29983394c6b6 101 void set_default_values();
edamame22 0:29983394c6b6 102
edamame22 0:29983394c6b6 103 /**
edamame22 0:29983394c6b6 104 * @brief Return write attribute flags.
edamame22 0:29983394c6b6 105 */
edamame22 0:29983394c6b6 106 uint8_t attribute_flags();
edamame22 0:29983394c6b6 107
edamame22 0:29983394c6b6 108 protected : // from M2MTimerObserver
edamame22 0:29983394c6b6 109
edamame22 0:29983394c6b6 110 virtual void timer_expired(M2MTimerObserver::Type type =
edamame22 0:29983394c6b6 111 M2MTimerObserver::Notdefined);
edamame22 0:29983394c6b6 112
edamame22 0:29983394c6b6 113 private:
edamame22 0:29983394c6b6 114
edamame22 0:29983394c6b6 115
edamame22 0:29983394c6b6 116
edamame22 0:29983394c6b6 117 bool set_notification_attribute(const char* option,
edamame22 0:29983394c6b6 118 M2MBase::BaseType type,
edamame22 0:29983394c6b6 119 M2MResourceInstance::ResourceType resource_type);
edamame22 0:29983394c6b6 120
edamame22 0:29983394c6b6 121 /**
edamame22 0:29983394c6b6 122 * @brief Schedule a report, if the pmin is exceeded
edamame22 0:29983394c6b6 123 * then report immediately else store the state to be
edamame22 0:29983394c6b6 124 * reported once the time fires.
edamame22 0:29983394c6b6 125 */
edamame22 0:29983394c6b6 126 void schedule_report();
edamame22 0:29983394c6b6 127
edamame22 0:29983394c6b6 128 /**
edamame22 0:29983394c6b6 129 * @brief Reports a sample that satisfies the reporting criteria.
edamame22 0:29983394c6b6 130 */
edamame22 0:29983394c6b6 131 void report();
edamame22 0:29983394c6b6 132
edamame22 0:29983394c6b6 133 /**
edamame22 0:29983394c6b6 134 * @brief Manage timers for pmin and pmax.
edamame22 0:29983394c6b6 135 */
edamame22 0:29983394c6b6 136 void handle_timers();
edamame22 0:29983394c6b6 137
edamame22 0:29983394c6b6 138 /**
edamame22 0:29983394c6b6 139 * @brief Check whether notification params can be accepted.
edamame22 0:29983394c6b6 140 */
edamame22 0:29983394c6b6 141 bool check_attribute_validity();
edamame22 0:29983394c6b6 142
edamame22 0:29983394c6b6 143 /**
edamame22 0:29983394c6b6 144 * @brief Stop pmin & pmax timers.
edamame22 0:29983394c6b6 145 */
edamame22 0:29983394c6b6 146 void stop_timers();
edamame22 0:29983394c6b6 147
edamame22 0:29983394c6b6 148 /**
edamame22 0:29983394c6b6 149 * @brief Check if current value match threshold values.
edamame22 0:29983394c6b6 150 * @return True if notify can be send otherwise false.
edamame22 0:29983394c6b6 151 */
edamame22 0:29983394c6b6 152 bool check_threshold_values();
edamame22 0:29983394c6b6 153
edamame22 0:29983394c6b6 154 /**
edamame22 0:29983394c6b6 155 * @brief Check whether current value matches with GT & LT.
edamame22 0:29983394c6b6 156 * @return True if current value match with GT or LT values.
edamame22 0:29983394c6b6 157 */
edamame22 0:29983394c6b6 158 bool check_gt_lt_params();
edamame22 0:29983394c6b6 159
edamame22 0:29983394c6b6 160 private:
edamame22 0:29983394c6b6 161 M2MReportObserver &_observer;
edamame22 0:29983394c6b6 162 uint8_t _attribute_state;
edamame22 0:29983394c6b6 163 bool _notify;
edamame22 0:29983394c6b6 164 bool _pmin_exceeded;
edamame22 0:29983394c6b6 165 bool _pmax_exceeded;
edamame22 0:29983394c6b6 166 M2MTimer _pmin_timer;
edamame22 0:29983394c6b6 167 M2MTimer _pmax_timer;
edamame22 0:29983394c6b6 168 int32_t _pmax;
edamame22 0:29983394c6b6 169 int32_t _pmin;
edamame22 0:29983394c6b6 170 float _current_value;
edamame22 0:29983394c6b6 171 float _gt;
edamame22 0:29983394c6b6 172 float _lt;
edamame22 0:29983394c6b6 173 float _st;
edamame22 0:29983394c6b6 174 float _high_step;
edamame22 0:29983394c6b6 175 float _low_step;
edamame22 0:29983394c6b6 176 float _last_value;
edamame22 0:29983394c6b6 177 m2m::Vector<uint16_t> _changed_instance_ids;
edamame22 0:29983394c6b6 178
edamame22 0:29983394c6b6 179 friend class Test_M2MReportHandler;
edamame22 0:29983394c6b6 180
edamame22 0:29983394c6b6 181 };
edamame22 0:29983394c6b6 182
edamame22 0:29983394c6b6 183 #endif // M2MREPORTHANDLER_H