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) 2016 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
edamame22 0:29983394c6b6 17
edamame22 0:29983394c6b6 18 #include "pal.h"
edamame22 0:29983394c6b6 19 #include "pal_plat_rtos.h"
edamame22 0:29983394c6b6 20 #include "pal_plat_network.h"
edamame22 0:29983394c6b6 21 #include "pal_macros.h"
edamame22 0:29983394c6b6 22
edamame22 0:29983394c6b6 23 //this variable must be a int32_t for using atomic increment
edamame22 0:29983394c6b6 24 static int32_t g_palIntialized = 0;
edamame22 0:29983394c6b6 25
edamame22 0:29983394c6b6 26
edamame22 0:29983394c6b6 27 palStatus_t pal_init()
edamame22 0:29983394c6b6 28 {
edamame22 0:29983394c6b6 29
edamame22 0:29983394c6b6 30 palStatus_t status = PAL_SUCCESS;
edamame22 0:29983394c6b6 31 int32_t currentInitValue;
edamame22 0:29983394c6b6 32 // get the return value of g_palIntialized+1 to save it locally
edamame22 0:29983394c6b6 33 currentInitValue = pal_osAtomicIncrement(&g_palIntialized,1);
edamame22 0:29983394c6b6 34 // if increased for the 1st time
edamame22 0:29983394c6b6 35 if (1 == currentInitValue)
edamame22 0:29983394c6b6 36 {
edamame22 0:29983394c6b6 37 DEBUG_PRINT("Init for the 1st time, initializing the modules\r\n");
edamame22 0:29983394c6b6 38 status = pal_plat_RTOSInitialize(NULL);
edamame22 0:29983394c6b6 39 if (PAL_SUCCESS == status)
edamame22 0:29983394c6b6 40 {
edamame22 0:29983394c6b6 41
edamame22 0:29983394c6b6 42 status = pal_plat_socketsInit(NULL);
edamame22 0:29983394c6b6 43 if (PAL_SUCCESS != status)
edamame22 0:29983394c6b6 44 {
edamame22 0:29983394c6b6 45 DEBUG_PRINT("init of network module has failed with status %d\r\n",status);
edamame22 0:29983394c6b6 46 }
edamame22 0:29983394c6b6 47 }
edamame22 0:29983394c6b6 48 else
edamame22 0:29983394c6b6 49 {
edamame22 0:29983394c6b6 50 DEBUG_PRINT("init of RTOS module has failed with status %d\r\n",status);
edamame22 0:29983394c6b6 51 }
edamame22 0:29983394c6b6 52 }
edamame22 0:29983394c6b6 53 // if failed decrees the value of g_palIntialized
edamame22 0:29983394c6b6 54 if (PAL_SUCCESS != status)
edamame22 0:29983394c6b6 55 {
edamame22 0:29983394c6b6 56 pal_plat_socketsTerminate(NULL);
edamame22 0:29983394c6b6 57 pal_plat_RTOSDestroy();
edamame22 0:29983394c6b6 58 pal_osAtomicIncrement(&g_palIntialized, -1);
edamame22 0:29983394c6b6 59 }
edamame22 0:29983394c6b6 60 return status;
edamame22 0:29983394c6b6 61 }
edamame22 0:29983394c6b6 62
edamame22 0:29983394c6b6 63
edamame22 0:29983394c6b6 64 void pal_destroy()
edamame22 0:29983394c6b6 65 {
edamame22 0:29983394c6b6 66 int32_t currentInitValue;
edamame22 0:29983394c6b6 67 // get the current value of g_palIntialized locally
edamame22 0:29983394c6b6 68 currentInitValue = pal_osAtomicIncrement(&g_palIntialized, -1);
edamame22 0:29983394c6b6 69 if (0 == currentInitValue)
edamame22 0:29983394c6b6 70 {
edamame22 0:29983394c6b6 71 DEBUG_PRINT("Destroying modules\r\n");
edamame22 0:29983394c6b6 72 pal_plat_RTOSDestroy();
edamame22 0:29983394c6b6 73 pal_plat_socketsTerminate(NULL);
edamame22 0:29983394c6b6 74 }
edamame22 0:29983394c6b6 75 }