BLE_HTS_Demo
This BLE_HTS_Demo program enables you to collect Temperature and Humidity data reading from sensor and transmit to collector device such as smartphone.
Below documents teach you how to install app that can connect and read data from our DELTA-DFCM-NNN40 development board. There are two versions, Android and iPhone.
/media/uploads/Marcomissyou/ios_app_for_environment_sensor_0518.pdf
/media/uploads/Marcomissyou/android_app_for_environment_sensor.pdf
Revision 9:2ff66a3d164a, committed 2017-07-18
- Comitter:
- silviaChen
- Date:
- Tue Jul 18 09:34:06 2017 +0000
- Parent:
- 8:4653319ba675
- Child:
- 10:5220f45c8ec1
- Commit message:
- update mbed-os so both NNN50 and NQ620 (as well as NQ624 module) platform are supported; Add config in mbed_app.json to fix NQ620 use internal RC issue ; remove the unused shield folder;update BLE_API;Modify SCL/SDA pin
Changed in this revision
--- a/BLE_API.lib Fri Oct 21 02:35:31 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#65474dc93927
--- a/hts221.cpp Fri Oct 21 02:35:31 2016 +0000 +++ b/hts221.cpp Tue Jul 18 09:34:06 2017 +0000 @@ -16,7 +16,7 @@ #include <mbed.h> #include "hts221.h" -I2C i2c(p22, p20); //SDA, SCL +I2C i2c(p26, p27); //SDA, SCL /*lint ++flb "Enter library region" */
--- a/main.cpp Fri Oct 21 02:35:31 2016 +0000
+++ b/main.cpp Tue Jul 18 09:34:06 2017 +0000
@@ -15,14 +15,13 @@
*/
#include "mbed.h"
-#include "BatteryService.h"
-#include "DeviceInformationService.h"
-#include "BLE.h"
+#include "ble/services/BatteryService.h"
+#include "ble/services/DeviceInformationService.h"
+#include "ble/BLE.h"
#include "hts221.h"
#include "uvis25.h"
-BLEDevice ble;
DigitalOut led1(LED1);
static const uint8_t UUID_HUMI_AND_UVI[] = {0xf5, 0x59, 0xa2, 0x49, 0xbe, 0xb1, 0x4c, 0x54, 0xa1, 0x0a, 0xc7, 0x95, 0x7e, 0x17, 0xf8, 0x67};
@@ -59,7 +58,7 @@
//
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
{
- ble.startAdvertising();
+ BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising(); // restart advertising
}
void periodicCallback(void)
@@ -70,6 +69,34 @@
* heavy-weight sensor polling from the main thread. */
triggerSensorPolling = true;
}
+
+void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
+{
+ BLE &ble = params->ble;
+ ble_error_t error = params->error;
+
+ if (error != BLE_ERROR_NONE) {
+ return;
+ }
+
+ ble.gap().onDisconnection(disconnectionCallback);
+
+ /* Setup auxiliary services. */
+ BatteryService battery(ble);
+ DeviceInformationService deviceInfo(ble, "Delta", "NQ620", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
+
+ /* Setup advertising. */
+ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
+ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
+ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
+ ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+ ble.gap().setAdvertisingInterval(1000); /* 1000ms */
+ ble.gap().startAdvertising();
+
+ ble.addService(htsService);
+}
+
/**************************************************************************/
/*!
@brief Program entry point
@@ -87,25 +114,17 @@
Ticker ticker;
ticker.attach(periodicCallback, 2);
- ble.init();
- ble.onDisconnection(disconnectionCallback);
+ BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
+ ble.init(bleInitComplete);
+
+ //ble.init();
+// ble.onDisconnection(disconnectionCallback);
- /* Setup auxiliary services. */
- BatteryService battery(ble);
- DeviceInformationService deviceInfo(ble, "Delta", "NNN40_1.0", "SN", "EVB_1.0", "B230-n80-m92", "T_0128b");
-
- /* Setup advertising. */
- ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
- ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
- ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
- ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
- ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
- ble.setAdvertisingInterval(1600);
- ble.startAdvertising();
+ /* SpinWait for initialization to complete. This is necessary because the
+ * BLE object is used in the main loop below. */
+ while (ble.hasInitialized() == false) { /* spin loop */ }
- ble.addService(htsService);
-
- while (true) {
+ while (1) {
if(hts221_verify_product_id())
HTS221_ReadTempHumi(&tempCelsius, &humi);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Jul 18 09:34:06 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#c9e63f14085f5751ff5ead79a7c0382d50a813a2
--- a/mbed.bld Fri Oct 21 02:35:31 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json Tue Jul 18 09:34:06 2017 +0000
@@ -0,0 +1,17 @@
+{
+ "config": {
+ "lf_clock_rc_calib_timer_interval": {
+ "value": 16,
+ "macro_name": "MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_TIMER_INTERVAL"
+ },
+ "lf_clock_rc_calib_mode_config": {
+ "value": 0,
+ "macro_name": "MBED_CONF_NORDIC_NRF_LF_CLOCK_CALIB_MODE_CONFIG"
+ },
+ "uart_hwfc": {
+ "help": "Value: 1 for enable, 0 for disable",
+ "value": 0,
+ "macro_name": "MBED_CONF_NORDIC_UART_HWFC"
+ }
+ }
+}
\ No newline at end of file
--- a/nRF51822.lib Fri Oct 21 02:35:31 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#c90ae1400bf2
--- a/uvis25.cpp Fri Oct 21 02:35:31 2016 +0000 +++ b/uvis25.cpp Tue Jul 18 09:34:06 2017 +0000 @@ -16,7 +16,7 @@ #include <mbed.h> #include "uvis25.h" -I2C i2c_uvi(p22, p20); //SDA, SCL +I2C i2c_uvi(p26, p27); //SDA, SCL static const char uvis25_expected_who_am_i = 0xCAU; //!< Expected value to get from WHO_AM_I register.