This is an example to broadcast measured value of BME280 through BLE GATT service.
please refer detail information at GitHub. https://github.com/soramame21/BLE_Server_BME280
Diff: source/main.cpp
- Revision:
- 4:a937975ebe7e
- Parent:
- 3:4b41a1ba65c8
diff -r 4b41a1ba65c8 -r a937975ebe7e source/main.cpp
--- a/source/main.cpp Wed Aug 23 13:40:01 2017 +0900
+++ b/source/main.cpp Fri Aug 25 15:47:39 2017 +0900
@@ -3,6 +3,10 @@
#include "ble/BLE.h"
#include "ble/services/EnvironmentalService.h"
+#if defined(_DEBUG)
+Serial pc(USBTX, USBRX);
+#endif
+
#if defined(TARGET_TY51822R3)
BME280 sensor(I2C_SDA0, I2C_SCL0);
#else
@@ -24,8 +28,9 @@
BLE &ble = params->ble;
ble_error_t error = params->error;
service = new EnvironmentalService(ble);
-
- printf("Inside BLE..starting payload creation..\r\n");
+#if defined(_DEBUG)
+ pc.printf("Inside BLE..starting payload creation..\r\n");
+#endif
ble.gap().onDisconnection(disconnectionCallback);
/* Setup advertising. */
@@ -35,9 +40,9 @@
ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
ble.gap().setAdvertisingInterval(1000);
error = ble.gap().startAdvertising();
-
- printf("ble.gap().startAdvertising() => %u\r\n", error);
-
+#if defined(_DEBUG)
+ pc.printf("ble.gap().startAdvertising() => %u\r\n", error);
+#endif
}
void readSensorCallback(void)
@@ -51,7 +56,9 @@
service->updatePressure(tmp_p);
service->updateTemperature(tmp_t);
service->updateHumidity(tmp_h);
- printf("%04.2f hPa, %2.2f degC, %2.2f %%\r\n", tmp_p, tmp_t, tmp_h );
+#if defined(_DEBUG)
+ pc.printf("%04.2f hPa, %2.2f degC, %2.2f %%\r\n", tmp_p, tmp_t, tmp_h );
+#endif
}
}