this is a test about ble
Dependencies: BLE_API LinkNode_TemperatureAdvertising mbed nRF51822
Fork of LinkNode_DataAdvertising1 by
Diff: main.cpp
- Revision:
- 5:d30cc8560678
- Parent:
- 4:e5fa4c8838db
- Child:
- 6:b3d3351aadc6
--- a/main.cpp Fri Jul 31 09:11:43 2015 +0000 +++ b/main.cpp Mon Feb 22 03:03:01 2016 +0000 @@ -1,23 +1,6 @@ - -/* mbed Microcontroller Library - * Copyright (c) 2006-2015 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #include "mbed.h" #include "ble/BLE.h" -#include "TMP_nrf51/TMP_nrf51.h" +#include "Sensors/Sensors.h" #define APP_SPECIFIC_ID_TEST 0xFEFE @@ -25,39 +8,40 @@ struct ApplicationData_t { uint16_t applicationSpecificId; /* An ID used to identify temperature value in the manufacture specific AD data field */ - TMP_nrf51::tmpSensorValue_t tmpSensorValue; /* User defined application data */ + Sensors::tmpSensorValue_t tmpSensorValue; /* User defined application data */ }; #pragma pack() BLE ble; -TMP_nrf51 tempSensor; -DigitalOut alivenessLED(LED1, 1); +Sensors tempSensor; +DigitalOut led(P0_20); static bool triggerTempValueUpdate = false; +const static char DEVICE_NAME[8] = "Linkaa"; void periodicCallback(void) { /* Do blinky on LED1 while we're waiting for BLE events */ - alivenessLED = !alivenessLED; + led = !led; triggerTempValueUpdate = true; } void accumulateApplicationData(ApplicationData_t &appData) { appData.applicationSpecificId = APP_SPECIFIC_ID_TEST; - /* Read a new temperature value */ + /* Read a new data value */ appData.tmpSensorValue = tempSensor.get(); } void temperatureValueAdvertising(void) -{ +{ ApplicationData_t appData; accumulateApplicationData(appData); - //printf("Temp is %f\r\n", (float)appData.tmpSensorValue); /* Setup advertising payload */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); /* Set flag */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER); /* Set appearance */ + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&appData, sizeof(ApplicationData_t)); /* Set data */ /* Setup advertising parameters */ ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); @@ -74,7 +58,7 @@ /* Stop advertising first */ ble.gap().stopAdvertising(); - /* Only update temperature value field */ + /* Only update data value field */ ble.gap().updateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&appData, sizeof(ApplicationData_t)); /* Start advertising again */ ble.gap().startAdvertising(); @@ -87,12 +71,13 @@ ticker.attach(periodicCallback, 2); ble.init(); - /* Start temperature advertising */ + /* Start data advertising */ temperatureValueAdvertising(); while (true) { - if (triggerTempValueUpdate) { - /* Update temperature value */ + if (triggerTempValueUpdate) + { + /* Update data value */ updateSensorValueInAdvPayload(); triggerTempValueUpdate = false; }