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 <string.h>
edamame22 0:29983394c6b6 17 #include <stdio.h>
edamame22 0:29983394c6b6 18 #include <stdarg.h>
edamame22 0:29983394c6b6 19
edamame22 0:29983394c6b6 20 //stack
edamame22 0:29983394c6b6 21 #include "eventOS_event.h"
edamame22 0:29983394c6b6 22 #include "eventOS_scheduler.h"
edamame22 0:29983394c6b6 23
edamame22 0:29983394c6b6 24 //mbed-client-libservice
edamame22 0:29983394c6b6 25 #include "randLIB.h"
edamame22 0:29983394c6b6 26 #include "nsdynmemLIB.h"
edamame22 0:29983394c6b6 27 #include "mbed-trace/mbed_trace.h"
edamame22 0:29983394c6b6 28 #include "ns_cmdline.h"
edamame22 0:29983394c6b6 29
edamame22 0:29983394c6b6 30
edamame22 0:29983394c6b6 31 //application
edamame22 0:29983394c6b6 32 #include "cmd_commands.h"
edamame22 0:29983394c6b6 33
edamame22 0:29983394c6b6 34 #define APP_DEV_HEAP_SIZE 30000
edamame22 0:29983394c6b6 35
edamame22 0:29983394c6b6 36 void eventOS_scheduler_idle(void)
edamame22 0:29983394c6b6 37 {
edamame22 0:29983394c6b6 38 eventOS_scheduler_wait();
edamame22 0:29983394c6b6 39 }
edamame22 0:29983394c6b6 40
edamame22 0:29983394c6b6 41 /*Global variables*/
edamame22 0:29983394c6b6 42
edamame22 0:29983394c6b6 43 uint8_t app_defined_stack_heap[APP_DEV_HEAP_SIZE];
edamame22 0:29983394c6b6 44
edamame22 0:29983394c6b6 45 void app_heap_error_handler(heap_fail_t event)
edamame22 0:29983394c6b6 46 {
edamame22 0:29983394c6b6 47 switch (event)
edamame22 0:29983394c6b6 48 {
edamame22 0:29983394c6b6 49 case NS_DYN_MEM_NULL_FREE:
edamame22 0:29983394c6b6 50 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:NULL_FREE");
edamame22 0:29983394c6b6 51 break;
edamame22 0:29983394c6b6 52 case NS_DYN_MEM_DOUBLE_FREE:
edamame22 0:29983394c6b6 53 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:DOUBLE_FREE");
edamame22 0:29983394c6b6 54 break;
edamame22 0:29983394c6b6 55
edamame22 0:29983394c6b6 56 case NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID:
edamame22 0:29983394c6b6 57 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:SIZE_NOT_VALID");
edamame22 0:29983394c6b6 58 break;
edamame22 0:29983394c6b6 59 case NS_DYN_MEM_POINTER_NOT_VALID:
edamame22 0:29983394c6b6 60 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:POINTER_NOT_VALID");
edamame22 0:29983394c6b6 61 break;
edamame22 0:29983394c6b6 62
edamame22 0:29983394c6b6 63 case NS_DYN_MEM_HEAP_SECTOR_CORRUPTED:
edamame22 0:29983394c6b6 64 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:SECTOR_CORRUPTED");
edamame22 0:29983394c6b6 65 break;
edamame22 0:29983394c6b6 66
edamame22 0:29983394c6b6 67 case NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED:
edamame22 0:29983394c6b6 68 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:SECTOR_UNITIALIZED");
edamame22 0:29983394c6b6 69 break;
edamame22 0:29983394c6b6 70 default:
edamame22 0:29983394c6b6 71 tracef(TRACE_LEVEL_ERROR, "mem", "Dyn mem error:UNKNOWN!");
edamame22 0:29983394c6b6 72 break;
edamame22 0:29983394c6b6 73 }
edamame22 0:29983394c6b6 74 while(1);
edamame22 0:29983394c6b6 75 }
edamame22 0:29983394c6b6 76
edamame22 0:29983394c6b6 77 int app_time_i=0;
edamame22 0:29983394c6b6 78 char* time_now(size_t size)
edamame22 0:29983394c6b6 79 {
edamame22 0:29983394c6b6 80 static char str[10] = {0};
edamame22 0:29983394c6b6 81 sprintf(str, "[%04d]", app_time_i++);
edamame22 0:29983394c6b6 82 return str;
edamame22 0:29983394c6b6 83 }
edamame22 0:29983394c6b6 84
edamame22 0:29983394c6b6 85 void trace_printer(const char* str)
edamame22 0:29983394c6b6 86 {
edamame22 0:29983394c6b6 87 printf("%s\r\n", str);
edamame22 0:29983394c6b6 88 cmd_output();
edamame22 0:29983394c6b6 89 fflush(stdout);
edamame22 0:29983394c6b6 90 }
edamame22 0:29983394c6b6 91 void cmd_printer(const char *str)
edamame22 0:29983394c6b6 92 {
edamame22 0:29983394c6b6 93 cmd_printf("%s", str);
edamame22 0:29983394c6b6 94 fflush(stdout);
edamame22 0:29983394c6b6 95 }
edamame22 0:29983394c6b6 96
edamame22 0:29983394c6b6 97 void custom_cmd_response_out(const char* fmt, va_list ap)
edamame22 0:29983394c6b6 98 {
edamame22 0:29983394c6b6 99 vprintf(fmt, ap);
edamame22 0:29983394c6b6 100 fflush(stdout);
edamame22 0:29983394c6b6 101 }
edamame22 0:29983394c6b6 102
edamame22 0:29983394c6b6 103 mem_stat_t memory_heap_stat;
edamame22 0:29983394c6b6 104 /**
edamame22 0:29983394c6b6 105 * \brief Application infinite loop.
edamame22 0:29983394c6b6 106 */
edamame22 0:29983394c6b6 107 int main(void)
edamame22 0:29983394c6b6 108 {
edamame22 0:29983394c6b6 109 ns_dyn_mem_init(app_defined_stack_heap, APP_DEV_HEAP_SIZE, app_heap_error_handler, &memory_heap_stat);
edamame22 0:29983394c6b6 110 eventOS_scheduler_init();
edamame22 0:29983394c6b6 111 mbed_trace_init();
edamame22 0:29983394c6b6 112 mbed_trace_print_function_set( trace_printer );
edamame22 0:29983394c6b6 113 mbed_trace_cmdprint_function_set( cmd_printer );
edamame22 0:29983394c6b6 114 mbed_trace_prefix_function_set( time_now );
edamame22 0:29983394c6b6 115 mbed_trace_config_set(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_DEBUG|TRACE_CARRIAGE_RETURN);
edamame22 0:29983394c6b6 116 cmd_init( &custom_cmd_response_out );
edamame22 0:29983394c6b6 117
edamame22 0:29983394c6b6 118 initialize_app_commands(0);
edamame22 0:29983394c6b6 119
edamame22 0:29983394c6b6 120 eventOS_scheduler_run();
edamame22 0:29983394c6b6 121 return 0;
edamame22 0:29983394c6b6 122 }