aboutsummaryrefslogtreecommitdiff
path: root/Mussel/examples/sensor/sensor.ino
blob: 73e096661aee34ee0def85e78dcf9e68b01a36db (plain)
  1. /*
  2.    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
  3. EddystoneTLM frame specification https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md
  4. */
  5. #include <Mussel.h>
  6. #include "BLEDevice.h"
  7. #include "BLEBeacon.h"
  8. #include "BLEAdvertising.h"
  9. #include "BLEEddystoneTLM.h"
  10. Mussel mussel(2);
  11. #define BEACON_POWER ESP_PWR_LVL_N12
  12. // See the following for generating UUIDs:
  13. // https://www.uuidgenerator.net/
  14. BLEAdvertising *pAdvertising;
  15. #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/)
  16. // Check
  17. // https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md
  18. // and http://www.hugi.scene.org/online/coding/hugi%2015%20-%20cmtadfix.htm
  19. // for the temperature value. It is a 8.8 fixed-point notation
  20. void setBeacon() {
  21. BLEEddystoneTLM EddystoneTLM;
  22. EddystoneTLM.setTemp(mussel.read()); // 3000 = 30.00 ˚C
  23. Serial.printf("Temperature is %.2f°C\n", EddystoneTLM.getTemp());
  24. BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
  25. BLEAdvertisementData oScanResponseData = BLEAdvertisementData();
  26. oScanResponseData.setServiceData(BLEUUID((uint16_t)0xFEAA), String(EddystoneTLM.getData().c_str(), EddystoneTLM.getData().length()));
  27. oAdvertisementData.setName("ESP32 TLM Beacon");
  28. pAdvertising->setAdvertisementData(oAdvertisementData);
  29. pAdvertising->setScanResponseData(oScanResponseData);
  30. }
  31. void setup() {
  32. Serial.begin(115200);
  33. mussel.begin();
  34. BLEDevice::init("TLMBeacon");
  35. BLEDevice::setPower(BEACON_POWER);
  36. pAdvertising = BLEDevice::getAdvertising();
  37. setBeacon();
  38. pAdvertising->start();
  39. }
  40. void loop() {
  41. setBeacon();
  42. delay(500);
  43. }