Skip to content

Commit

Permalink
Removed gatt ble service
Browse files Browse the repository at this point in the history
  • Loading branch information
mp-se committed Aug 27, 2024
1 parent e8ac798 commit d7281d7
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 84 deletions.
53 changes: 0 additions & 53 deletions src/ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ SOFTWARE.
// Tilt data format is described here. Only SG and Temp is transmitted over BLE.
// https://kvurd.com/blog/tilt-hydrometer-ibeacon-data-format/

class CharacteristicCallbacks : public NimBLECharacteristicCallbacks {
private:
volatile bool _isRead = false;

public:
void clearReadFlag() { _isRead = false; }
bool isRead() { return _isRead; }

void onRead(NimBLECharacteristic* pCharacteristic) {
#if LOG_LEVEL == 6
Log.verbose(F("BLE : Remote reading data" CR));
#endif
_isRead = true;
}
};

static CharacteristicCallbacks myCharCallbacks;

void BleSender::init() {
if (_initFlag) return;

Expand Down Expand Up @@ -218,46 +200,11 @@ void BleSender::sendCustomBeaconData(float battery, float tempC, float gravity,
_advertising->stop();
}

void BleSender::sendGravitymonData(String payload) {
Log.info(F("BLE : Updating data for gravitymon data transmission" CR));

_advertising->stop();

if (!_server) {
Log.info(
F("BLE : Creating BLE server for gravitymon data transmission" CR));

_server = BLEDevice::createServer();
_service = _server->createService(BLEUUID("180a"));
_characteristic = _service->createCharacteristic(
BLEUUID("2ac4"), NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::BROADCAST);
_characteristic->setCallbacks(&myCharCallbacks);
_service->start();
_advertising->addServiceUUID(BLEUUID("180a"));
_advertising->setName("gravitymon");
_advertising->setScanResponse(false);
_advertising->setMinPreferred(0x06);
_advertising->setMaxPreferred(0x12);
}

myCharCallbacks.clearReadFlag();

if (payload.length() > 510) {
writeErrorLog("BLE : Payload is to long for sending over BLE");
payload = "{\"error\":\"payload to long\"}";
}

_characteristic->setValue(payload);
_advertising->start();
}

void BleSender::dumpPayload(const char* p, int len) {
for (int i = 0; i < len; i++) {
EspSerial.printf("%X%X ", (*(p + i) & 0xf0) >> 4, (*(p + i) & 0x0f));
}
EspSerial.println();
}

bool BleSender::isGravitymonDataSent() { return myCharCallbacks.isRead(); }

#endif // ENABLE_BLE
4 changes: 0 additions & 4 deletions src/ble.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ class BleSender {
void sendEddystone(float battery, float tempC, float gravity, float angle);
void sendCustomBeaconData(float battery, float tempC, float gravity,
float angle);

// Use GATT
void sendGravitymonData(String payload);
bool isGravitymonDataSent();
};

#endif // ENABLE_BLE
Expand Down
1 change: 0 additions & 1 deletion src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ enum BleFormat {
BLE_DISABLED = 0,
BLE_TILT = 1,
BLE_TILT_PRO = 2,
BLE_GRAVITYMON_SERVICE = 3,
BLE_GRAVITYMON_EDDYSTONE = 4,
BLE_GRAVITYMON_IBEACON = 5
};
Expand Down
26 changes: 0 additions & 26 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,6 @@ bool loopReadGravity() {
myBleSender.sendEddystone(myBatteryVoltage.getVoltage(), tempC,
gravitySG, angle);
} break;
case BleFormat::BLE_GRAVITYMON_SERVICE: {
TemplatingEngine engine;
GravmonPush push(&myConfig);
push.setupTemplateEngine(engine, angle, gravitySG, corrGravitySG,
tempC, (millis() - runtimeMillis) / 1000,
myBatteryVoltage.getVoltage());
String tpl = push.getTemplate(GravmonPush::TEMPLATE_BLE);
String payload = engine.create(tpl.c_str());
myBleSender.sendGravitymonData(payload);
} break;
}
}
#endif // ESP32 && !ESP32S2
Expand Down Expand Up @@ -362,22 +352,6 @@ bool loopReadGravity() {
(millis() - runtimeMillis) / 1000);
}
}

#if defined(ESP32) && !defined(ESP32S2)
if (myConfig.getBleFormat() == BleFormat::BLE_GRAVITYMON_SERVICE) {
Log.notice(F("Main: Waiting for ble service to be read." CR));
int i = 0;
while (!myBleSender.isGravitymonDataSent() && i < 10) {
delay(500);
EspSerial.print(".");
i++;
}
EspSerial.print(CR);
if (myBleSender.isGravitymonDataSent())
Log.notice(F("Main: Ble service was read by client." CR));
}
#endif // ESP32 && !ESP32S2

PERF_END("loop-push");

// Send stats to influx after each push run.
Expand Down

0 comments on commit d7281d7

Please sign in to comment.