From ed3ac0eb11a04630f7f08124a484a854eea13569 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 13 Apr 2025 13:03:53 +0200 Subject: rename and describe bluetooth examples --- Mussel/examples/sensor/sensor.ino | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Mussel/examples/sensor/sensor.ino (limited to 'Mussel/examples/sensor/sensor.ino') diff --git a/Mussel/examples/sensor/sensor.ino b/Mussel/examples/sensor/sensor.ino new file mode 100644 index 0000000..73e0966 --- /dev/null +++ b/Mussel/examples/sensor/sensor.ino @@ -0,0 +1,54 @@ +/* + EddystoneTLM beacon by BeeGee based on https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_Eddystone_TLM_deepsleep/ESP32_Eddystone_TLM_deepsleep.ino + EddystoneTLM frame specification https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md +*/ + +#include + +#include "BLEDevice.h" +#include "BLEBeacon.h" +#include "BLEAdvertising.h" +#include "BLEEddystoneTLM.h" + +Mussel mussel(2); + +#define BEACON_POWER ESP_PWR_LVL_N12 + +// See the following for generating UUIDs: +// https://www.uuidgenerator.net/ +BLEAdvertising *pAdvertising; + +#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d" // UUID 1 128-Bit (may use linux tool uuidgen or random numbers via https://www.uuidgenerator.net/) + +// Check +// https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md +// and http://www.hugi.scene.org/online/coding/hugi%2015%20-%20cmtadfix.htm +// for the temperature value. It is a 8.8 fixed-point notation +void setBeacon() { + BLEEddystoneTLM EddystoneTLM; + EddystoneTLM.setTemp(mussel.read()); // 3000 = 30.00 ˚C + Serial.printf("Temperature is %.2f°C\n", EddystoneTLM.getTemp()); + + BLEAdvertisementData oAdvertisementData = BLEAdvertisementData(); + BLEAdvertisementData oScanResponseData = BLEAdvertisementData(); + oScanResponseData.setServiceData(BLEUUID((uint16_t)0xFEAA), String(EddystoneTLM.getData().c_str(), EddystoneTLM.getData().length())); + + oAdvertisementData.setName("ESP32 TLM Beacon"); + pAdvertising->setAdvertisementData(oAdvertisementData); + pAdvertising->setScanResponseData(oScanResponseData); +} + +void setup() { + Serial.begin(115200); + mussel.begin(); + BLEDevice::init("TLMBeacon"); + BLEDevice::setPower(BEACON_POWER); + pAdvertising = BLEDevice::getAdvertising(); + setBeacon(); + pAdvertising->start(); +} + +void loop() { + setBeacon(); + delay(500); +} -- cgit v1.2.3