Skip to content

Commit

Permalink
Sending BLE data
Browse files Browse the repository at this point in the history
  • Loading branch information
cjoshmartin committed May 22, 2024
1 parent b2aebcb commit c1a4632
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ardunio_code/ble_code/ble_code.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h>
#include <string>
#include <iostream>

BLEServer *pServer;
#define DEVICE_NAME "MyESP32"
Expand All @@ -10,6 +12,27 @@ BLEServer *pServer;
BLECharacteristic *pStepCountCharacteristic;
#define STEPCOUNT_CHARACTERISTIC_UUID "fbb6411e-26a7-44fb-b7a3-a343e2b011fe"

int heartRate = 0;
BLECharacteristic *pHeartRateCharacteristic;
# define HEARTRATE_CHARACTERISTIC_UUID "c58b67c8-f685-40d2-af4c-84bcdaf3b22e"

int readValue(BLECharacteristic *characteristic) {
if (characteristic == NULL) {
return -1;
}
std::string value = std::string(
(
characteristic->getValue()
).c_str()
);

try{
return stoi(value);
} catch(...) {
return -1;
}
}

class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
}
Expand Down Expand Up @@ -43,6 +66,7 @@ void setup() {
BLEService *pService = pServer->createService(SERVICE_UUID);

pStepCountCharacteristic = createCharacteristic(STEPCOUNT_CHARACTERISTIC_UUID, pService);
pHeartRateCharacteristic = createCharacteristic(HEARTRATE_CHARACTERISTIC_UUID, pService);

//start the service
pService->start();
Expand All @@ -66,5 +90,16 @@ void loop() {

Serial.print("Value is: ");
Serial.println(stepCount);

heartRate = readValue(pHeartRateCharacteristic);
Serial.print("heart rate value is: ");
if (heartRate > 0){
Serial.println(heartRate);
}
else {
Serial.println("No Heart rate value received");
}


delay(500);
}

0 comments on commit c1a4632

Please sign in to comment.