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: BMP280 MtSense01 SHT2X
Fork of MtConnect04S_MtSense01 by
Diff: source/main.cpp
- Revision:
- 1:67bf70088281
- Parent:
- 0:6eacca6939a9
- Child:
- 3:3957bdf33fb7
diff -r 6eacca6939a9 -r 67bf70088281 source/main.cpp
--- a/source/main.cpp Mon May 22 08:54:56 2017 +0000
+++ b/source/main.cpp Fri Jun 02 06:49:32 2017 +0000
@@ -19,17 +19,19 @@
#include "ble/BLE.h"
#include "ble/Gap.h"
#include "ble/services/BatteryService.h"
+#include "ble/services/EnvironmentalService.h"
+#include "MtSense01.h"
/* UART printf */
Serial pc(p5, p4);
-
+I2C i2c(p3, p2);
DigitalOut led1(p16, 1);
+MtSense01 mtsense1(i2c);
-const static char DEVICE_NAME[] = "MtConnect01_Test";
-static const uint16_t uuid16_list[] = {GattService::UUID_BATTERY_SERVICE};
+const static char DEVICE_NAME[] = "MtSense01_Test";
+static const uint16_t uuid16_list[] = {0x1822, 0x181A};
-static uint8_t batteryLevel = 50;
-static BatteryService* batteryServicePtr;
+static EnvironmentalService *environmentalServicePtr;
static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE);
@@ -38,13 +40,24 @@
BLE::Instance().gap().startAdvertising();
}
-void updateSensorValue() {
- batteryLevel++;
- if (batteryLevel > 100) {
- batteryLevel = 20;
+void initMtSense01() {
+ mtsense1.Initial();
+}
+
+void readMtSense01() {
+ int pressPa;
+ float tempC, humidity;
+
+ mtsense1.readData(&tempC, &pressPa, &humidity);
+ BLE &ble = BLE::Instance();
+ if (ble.gap().getState().connected) {
+ environmentalServicePtr->updateHumidity(humidity);
+ environmentalServicePtr->updatePressure(pressPa);
+ environmentalServicePtr->updateTemperature(tempC);
}
-
- batteryServicePtr->updateBatteryLevel(batteryLevel);
+
+// pc.printf("tempC: %8f, pressPa: %8d, humidity: %8f \r\n", tempC, pressPa, humidity);
+
}
void blinkCallback(void)
@@ -52,9 +65,6 @@
led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
BLE &ble = BLE::Instance();
- if (ble.gap().getState().connected) {
- eventQueue.call(updateSensorValue);
- }
}
/**
@@ -87,14 +97,14 @@
ble.gap().onDisconnection(disconnectionCallback);
/* Setup primary service */
- batteryServicePtr = new BatteryService(ble, batteryLevel);
+ environmentalServicePtr = new EnvironmentalService(ble);
/* 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::COMPLETE_LOCAL_NAME, (uint8_t *) DEVICE_NAME, sizeof(DEVICE_NAME));
ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
- ble.gap().setAdvertisingInterval(1000); /* 1000ms */
+ ble.gap().setAdvertisingInterval(100); /* 100ms */
ble.gap().startAdvertising();
}
@@ -110,7 +120,11 @@
pc.printf("\r\n");
pc.printf("Welcome MTM Node !\r\n");
+
eventQueue.call_every(500, blinkCallback);
+
+ initMtSense01();
+ eventQueue.call_every(1000, readMtSense01); // 1000 ms repeat
BLE &ble = BLE::Instance();
ble.onEventsToProcess(scheduleBleEventsProcessing);
