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/
mbed-client/mbed-client-classic/source/m2mconnectionhandler.cpp@2:b894b3508057, 2017-09-05 (annotated)
- 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?
User | Revision | Line number | New 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-classic/m2mconnectionhandlerpimpl.h" |
edamame22 | 0:29983394c6b6 | 17 | #include "mbed-client/m2mconnectionobserver.h" |
edamame22 | 0:29983394c6b6 | 18 | #include "mbed-client/m2mconnectionhandler.h" |
edamame22 | 0:29983394c6b6 | 19 | #include "mbed-client/m2mconstants.h" |
edamame22 | 0:29983394c6b6 | 20 | |
edamame22 | 0:29983394c6b6 | 21 | M2MConnectionHandler::M2MConnectionHandler(M2MConnectionObserver &observer, |
edamame22 | 0:29983394c6b6 | 22 | M2MConnectionSecurity* sec, |
edamame22 | 0:29983394c6b6 | 23 | M2MInterface::BindingMode mode, |
edamame22 | 0:29983394c6b6 | 24 | M2MInterface::NetworkStack stack) |
edamame22 | 0:29983394c6b6 | 25 | :_observer(observer) |
edamame22 | 0:29983394c6b6 | 26 | { |
edamame22 | 0:29983394c6b6 | 27 | _private_impl = new M2MConnectionHandlerPimpl(this, observer, sec, mode, stack); |
edamame22 | 0:29983394c6b6 | 28 | } |
edamame22 | 0:29983394c6b6 | 29 | |
edamame22 | 0:29983394c6b6 | 30 | M2MConnectionHandler::~M2MConnectionHandler() |
edamame22 | 0:29983394c6b6 | 31 | { |
edamame22 | 0:29983394c6b6 | 32 | delete _private_impl; |
edamame22 | 0:29983394c6b6 | 33 | } |
edamame22 | 0:29983394c6b6 | 34 | |
edamame22 | 0:29983394c6b6 | 35 | bool M2MConnectionHandler::bind_connection(const uint16_t listen_port) |
edamame22 | 0:29983394c6b6 | 36 | { |
edamame22 | 0:29983394c6b6 | 37 | |
edamame22 | 0:29983394c6b6 | 38 | return _private_impl->bind_connection(listen_port); |
edamame22 | 0:29983394c6b6 | 39 | } |
edamame22 | 0:29983394c6b6 | 40 | |
edamame22 | 0:29983394c6b6 | 41 | bool M2MConnectionHandler::resolve_server_address(const String& server_address, |
edamame22 | 0:29983394c6b6 | 42 | const uint16_t server_port, |
edamame22 | 0:29983394c6b6 | 43 | M2MConnectionObserver::ServerType server_type, |
edamame22 | 0:29983394c6b6 | 44 | const M2MSecurity* security) |
edamame22 | 0:29983394c6b6 | 45 | { |
edamame22 | 0:29983394c6b6 | 46 | return _private_impl->resolve_server_address(server_address, server_port, |
edamame22 | 0:29983394c6b6 | 47 | server_type, security); |
edamame22 | 0:29983394c6b6 | 48 | } |
edamame22 | 0:29983394c6b6 | 49 | |
edamame22 | 0:29983394c6b6 | 50 | bool M2MConnectionHandler::start_listening_for_data() |
edamame22 | 0:29983394c6b6 | 51 | { |
edamame22 | 0:29983394c6b6 | 52 | return _private_impl->start_listening_for_data(); |
edamame22 | 0:29983394c6b6 | 53 | } |
edamame22 | 0:29983394c6b6 | 54 | |
edamame22 | 0:29983394c6b6 | 55 | void M2MConnectionHandler::stop_listening() |
edamame22 | 0:29983394c6b6 | 56 | { |
edamame22 | 0:29983394c6b6 | 57 | _private_impl->stop_listening(); |
edamame22 | 0:29983394c6b6 | 58 | } |
edamame22 | 0:29983394c6b6 | 59 | |
edamame22 | 0:29983394c6b6 | 60 | int M2MConnectionHandler::send_to_socket(const unsigned char *buf, size_t len) |
edamame22 | 0:29983394c6b6 | 61 | { |
edamame22 | 0:29983394c6b6 | 62 | return _private_impl->send_to_socket(buf, len); |
edamame22 | 0:29983394c6b6 | 63 | } |
edamame22 | 0:29983394c6b6 | 64 | |
edamame22 | 0:29983394c6b6 | 65 | int M2MConnectionHandler::receive_from_socket(unsigned char *buf, size_t len) |
edamame22 | 0:29983394c6b6 | 66 | { |
edamame22 | 0:29983394c6b6 | 67 | return _private_impl->receive_from_socket(buf, len); |
edamame22 | 0:29983394c6b6 | 68 | } |
edamame22 | 0:29983394c6b6 | 69 | |
edamame22 | 0:29983394c6b6 | 70 | bool M2MConnectionHandler::send_data(uint8_t *data, |
edamame22 | 0:29983394c6b6 | 71 | uint16_t data_len, |
edamame22 | 0:29983394c6b6 | 72 | sn_nsdl_addr_s *address) |
edamame22 | 0:29983394c6b6 | 73 | { |
edamame22 | 0:29983394c6b6 | 74 | return _private_impl->send_data(data, data_len, address); |
edamame22 | 0:29983394c6b6 | 75 | } |
edamame22 | 0:29983394c6b6 | 76 | |
edamame22 | 0:29983394c6b6 | 77 | void M2MConnectionHandler::handle_connection_error(int error) |
edamame22 | 0:29983394c6b6 | 78 | { |
edamame22 | 0:29983394c6b6 | 79 | _private_impl->handle_connection_error(error); |
edamame22 | 0:29983394c6b6 | 80 | } |
edamame22 | 0:29983394c6b6 | 81 | |
edamame22 | 0:29983394c6b6 | 82 | void M2MConnectionHandler::set_platform_network_handler(void *handler) |
edamame22 | 0:29983394c6b6 | 83 | { |
edamame22 | 0:29983394c6b6 | 84 | _private_impl->set_platform_network_handler(handler); |
edamame22 | 0:29983394c6b6 | 85 | } |
edamame22 | 0:29983394c6b6 | 86 | |
edamame22 | 0:29983394c6b6 | 87 | void M2MConnectionHandler::claim_mutex() |
edamame22 | 0:29983394c6b6 | 88 | { |
edamame22 | 0:29983394c6b6 | 89 | _private_impl->claim_mutex(); |
edamame22 | 0:29983394c6b6 | 90 | } |
edamame22 | 0:29983394c6b6 | 91 | |
edamame22 | 0:29983394c6b6 | 92 | void M2MConnectionHandler::release_mutex() |
edamame22 | 0:29983394c6b6 | 93 | { |
edamame22 | 0:29983394c6b6 | 94 | _private_impl->release_mutex(); |
edamame22 | 0:29983394c6b6 | 95 | } |