Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API LIS3DH mbed nRF51822
Fork of BLE_Sensor by
Diff: main.cpp
- Revision:
- 3:3eda308b78e6
- Parent:
- 2:b935358da5ba
- Child:
- 4:e5fa4c8838db
--- a/main.cpp Fri Jul 17 08:46:31 2015 +0000
+++ b/main.cpp Mon Jul 20 08:58:21 2015 +0000
@@ -21,6 +21,16 @@
#include "ble/DiscoveredService.h"
#include "TMP_nrf51/TMP_nrf51.h"
+#define COMP_ID_TEST 0xFEFE
+
+#pragma pack(1)
+typedef struct manufacturerData {
+ uint16_t companyId;
+ /* User defined manufacture data */
+ TMP_nrf51::tmpSensorValue_t tmpSensorValue;
+} manufacturerData_t;
+#pragma pack()
+
BLE ble;
TMP_nrf51 tempSensor;
DigitalOut alivenessLED(LED1, 1);
@@ -35,23 +45,27 @@
void temperatureValueAdvertising(void)
{
- TMP_nrf51::tmpSensorValue_t tempVal;
+ manufacturerData_t manuData;
+ manuData.companyId = COMP_ID_TEST;
+
/* Read a new temperature value */
- tempVal = tempSensor.get();
- printf("Temp is %f\r\n", tempVal);
+ manuData.tmpSensorValue = tempSensor.get();
+ printf("Temp is %f\r\n", (float)manuData.tmpSensorValue);
/* Stop advertising and clear the payload if in advertising state */
if((ble.gap().getState()).advertising == 1) {
ble.gap().stopAdvertising();
ble.gap().clearAdvertisingPayload();
}
- /* Setup advertising. */
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER);
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&tempVal, sizeof(TMP_nrf51::tmpSensorValue_t));
+
+ /* 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::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&manuData, sizeof(manufacturerData_t)); /* Set data */
+ /* Setup advertising parameters */
ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
ble.gap().setAdvertisingInterval(500);
-
+ /* Start advertising */
ble.gap().startAdvertising();
}
