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 --- .../read_to_EddystoneTLM/EddystoneTLM_Beacon.md | 14 ------ Mussel/examples/read_to_EddystoneTLM/ci.json | 6 --- .../read_to_EddystoneTLM/read_to_EddystoneTLM.ino | 54 --------------------- .../read_to_EddystoneTLM/read_to_EddystoneTLM.puml | 26 ---------- Mussel/examples/sensor/Mussel_Sensor_Beacon.md | 7 +++ Mussel/examples/sensor/sensor.ino | 54 +++++++++++++++++++++ Mussel/examples/sensor/sensor.puml | 26 ++++++++++ Mussel/examples/vote/Mussel_Beacon_Voting.md | 20 ++++++++ Mussel/examples/vote/vote.ino | 55 ++++++++++++++++++++++ Mussel/examples/vote/vote.puml | 27 +++++++++++ .../voting_from_EddystoneTLM/Beacon_Scanner.md | 9 ---- Mussel/examples/voting_from_EddystoneTLM/ci.json | 6 --- .../voting_from_EddystoneTLM.ino | 55 ---------------------- .../voting_from_EddystoneTLM.puml | 28 ----------- 14 files changed, 189 insertions(+), 198 deletions(-) delete mode 100644 Mussel/examples/read_to_EddystoneTLM/EddystoneTLM_Beacon.md delete mode 100644 Mussel/examples/read_to_EddystoneTLM/ci.json delete mode 100644 Mussel/examples/read_to_EddystoneTLM/read_to_EddystoneTLM.ino delete mode 100644 Mussel/examples/read_to_EddystoneTLM/read_to_EddystoneTLM.puml create mode 100644 Mussel/examples/sensor/Mussel_Sensor_Beacon.md create mode 100644 Mussel/examples/sensor/sensor.ino create mode 100644 Mussel/examples/sensor/sensor.puml create mode 100644 Mussel/examples/vote/Mussel_Beacon_Voting.md create mode 100644 Mussel/examples/vote/vote.ino create mode 100644 Mussel/examples/vote/vote.puml delete mode 100644 Mussel/examples/voting_from_EddystoneTLM/Beacon_Scanner.md delete mode 100644 Mussel/examples/voting_from_EddystoneTLM/ci.json delete mode 100644 Mussel/examples/voting_from_EddystoneTLM/voting_from_EddystoneTLM.ino delete mode 100644 Mussel/examples/voting_from_EddystoneTLM/voting_from_EddystoneTLM.puml (limited to 'Mussel/examples') diff --git a/Mussel/examples/read_to_EddystoneTLM/EddystoneTLM_Beacon.md b/Mussel/examples/read_to_EddystoneTLM/EddystoneTLM_Beacon.md deleted file mode 100644 index 2e34029..0000000 --- a/Mussel/examples/read_to_EddystoneTLM/EddystoneTLM_Beacon.md +++ /dev/null @@ -1,14 +0,0 @@ -## Eddystone TLM beacon -EddystoneTLM beacon by BeeGee based on -[pcbreflux ESP32 Eddystone TLM deepsleep](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) - - Create a BLE server that will send periodic Eddystone TLM frames. - The design of creating the BLE server is: - 1. Create a BLE Server - 2. Create advertising data - 3. Start advertising. - 4. wait - 5. Stop advertising. - 6. deep sleep diff --git a/Mussel/examples/read_to_EddystoneTLM/ci.json b/Mussel/examples/read_to_EddystoneTLM/ci.json deleted file mode 100644 index abe13a7..0000000 --- a/Mussel/examples/read_to_EddystoneTLM/ci.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "fqbn_append": "PartitionScheme=huge_app", - "requires": [ - "CONFIG_SOC_BLE_SUPPORTED=y" - ] -} diff --git a/Mussel/examples/read_to_EddystoneTLM/read_to_EddystoneTLM.ino b/Mussel/examples/read_to_EddystoneTLM/read_to_EddystoneTLM.ino deleted file mode 100644 index 73e0966..0000000 --- a/Mussel/examples/read_to_EddystoneTLM/read_to_EddystoneTLM.ino +++ /dev/null @@ -1,54 +0,0 @@ -/* - 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); -} diff --git a/Mussel/examples/read_to_EddystoneTLM/read_to_EddystoneTLM.puml b/Mussel/examples/read_to_EddystoneTLM/read_to_EddystoneTLM.puml deleted file mode 100644 index 3f033d1..0000000 --- a/Mussel/examples/read_to_EddystoneTLM/read_to_EddystoneTLM.puml +++ /dev/null @@ -1,26 +0,0 @@ -@startuml -'start -:instantiate mussel object; -:instantiate bluetooth object; -group init -:setup mussel sensors; -:setup bluetooth beacon; -end group -split -while (each 500ms) -group loop { -:read sensors; -:normalize sensor data -as a gape angle; -:add gape angle to beacon; -end group -endwhile --[hidden]-> -kill -split again -while (each 100ms) -:broadcast beacon; -endwhile --[hidden]-> -kill -@enduml diff --git a/Mussel/examples/sensor/Mussel_Sensor_Beacon.md b/Mussel/examples/sensor/Mussel_Sensor_Beacon.md new file mode 100644 index 0000000..a9269c6 --- /dev/null +++ b/Mussel/examples/sensor/Mussel_Sensor_Beacon.md @@ -0,0 +1,7 @@ +## Mussel Sensor Beacon + +1. Reads sensors. + +2. Normalises sensor data as a gape angle in the range of 0°C-90°C. + +3. Broadcasts normalised sensor data as a beacon on a bluetooth network. 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); +} diff --git a/Mussel/examples/sensor/sensor.puml b/Mussel/examples/sensor/sensor.puml new file mode 100644 index 0000000..3f033d1 --- /dev/null +++ b/Mussel/examples/sensor/sensor.puml @@ -0,0 +1,26 @@ +@startuml +'start +:instantiate mussel object; +:instantiate bluetooth object; +group init +:setup mussel sensors; +:setup bluetooth beacon; +end group +split +while (each 500ms) +group loop { +:read sensors; +:normalize sensor data +as a gape angle; +:add gape angle to beacon; +end group +endwhile +-[hidden]-> +kill +split again +while (each 100ms) +:broadcast beacon; +endwhile +-[hidden]-> +kill +@enduml diff --git a/Mussel/examples/vote/Mussel_Beacon_Voting.md b/Mussel/examples/vote/Mussel_Beacon_Voting.md new file mode 100644 index 0000000..33a0893 --- /dev/null +++ b/Mussel/examples/vote/Mussel_Beacon_Voting.md @@ -0,0 +1,20 @@ +## Mussel Beacon Voting + +1. Scans bluetooth network for beacons. + +2. Collects mussel name and gape angle +as decoded from each detected beacon, +together with the time of detection in milliseconds since boot. + +3. Aligns the collected data +to the format of ballots for a water quality vote. + +4. Qualifies the ballots for criteria of the water quality vote +(e.g. timeliness and sanity of gape angles). + +5. Concludes a vote based on collected, aligned and qualified ballots. + +6. Acts on the voting result, +e.g. turns on a steady light for "code green" +or a blinking light for "code yellow", +or turns on a blinking light and shuts off a valve for "code red". diff --git a/Mussel/examples/vote/vote.ino b/Mussel/examples/vote/vote.ino new file mode 100644 index 0000000..25c4720 --- /dev/null +++ b/Mussel/examples/vote/vote.ino @@ -0,0 +1,55 @@ +/* + Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp + Ported to Arduino ESP32 by Evandro Copercini + Changed to a beacon scanner to report iBeacon, EddystoneURL and EddystoneTLM beacons by beegee-tokyo + Upgraded Eddystone part by Tomas Pilny on Feb 20, 2023 +*/ + +#include +#include + +#include +#include +#include +#include +#include + +Mussel mussel(10); + +int scanTime = 1; //In seconds +BLEScan *pBLEScan; + +class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { + void onResult(BLEAdvertisedDevice advertisedDevice) { + if (advertisedDevice.haveName() + && advertisedDevice.getFrameType() == BLE_EDDYSTONE_TLM_FRAME + ) { + BLEEddystoneTLM EddystoneTLM(&advertisedDevice); + mussel.push( + advertisedDevice.getName(), + millis(), + EddystoneTLM.getTemp() + ); + } + } +}; + +void setup() { + Serial.begin(115200); + mussel.begin(); + + BLEDevice::init(""); + pBLEScan = BLEDevice::getScan(); //create new scan + pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); + pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster + pBLEScan->setInterval(100); + pBLEScan->setWindow(99); // less or equal setInterval value +} + +void loop() { + // put your main code here, to run repeatedly: + BLEScanResults *foundDevices = pBLEScan->start(scanTime, false); + pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory + mussel.printStack(); + delay(500); +} diff --git a/Mussel/examples/vote/vote.puml b/Mussel/examples/vote/vote.puml new file mode 100644 index 0000000..a4958f7 --- /dev/null +++ b/Mussel/examples/vote/vote.puml @@ -0,0 +1,27 @@ +@startuml +:instantiate mussel object; +:instantiate bluetooth object; +group init +:setup mussel voting; +:setup bluetooth scanner; +end group +split +while (each beacon detected) +group "bluetooth callback" { +:collect beacon data; +end group +endwhile +-[hidden]-> +kill +split again +while (each 500ms) +group loop { +:allign beacon data as ballots; +:qualify ballots for a vote; +:conclude vote result; +:act on vote result; +end group +endwhile +-[hidden]-> +kill +@enduml diff --git a/Mussel/examples/voting_from_EddystoneTLM/Beacon_Scanner.md b/Mussel/examples/voting_from_EddystoneTLM/Beacon_Scanner.md deleted file mode 100644 index 34101fe..0000000 --- a/Mussel/examples/voting_from_EddystoneTLM/Beacon_Scanner.md +++ /dev/null @@ -1,9 +0,0 @@ -## BLE Beacon Scanner - -Initiates a BLE device scan. -Checks if the discovered devices are -- an iBeacon -- an Eddystone TLM beacon -- an Eddystone URL beacon - -and sends the decoded beacon information over Serial log diff --git a/Mussel/examples/voting_from_EddystoneTLM/ci.json b/Mussel/examples/voting_from_EddystoneTLM/ci.json deleted file mode 100644 index abe13a7..0000000 --- a/Mussel/examples/voting_from_EddystoneTLM/ci.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "fqbn_append": "PartitionScheme=huge_app", - "requires": [ - "CONFIG_SOC_BLE_SUPPORTED=y" - ] -} diff --git a/Mussel/examples/voting_from_EddystoneTLM/voting_from_EddystoneTLM.ino b/Mussel/examples/voting_from_EddystoneTLM/voting_from_EddystoneTLM.ino deleted file mode 100644 index 25c4720..0000000 --- a/Mussel/examples/voting_from_EddystoneTLM/voting_from_EddystoneTLM.ino +++ /dev/null @@ -1,55 +0,0 @@ -/* - Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp - Ported to Arduino ESP32 by Evandro Copercini - Changed to a beacon scanner to report iBeacon, EddystoneURL and EddystoneTLM beacons by beegee-tokyo - Upgraded Eddystone part by Tomas Pilny on Feb 20, 2023 -*/ - -#include -#include - -#include -#include -#include -#include -#include - -Mussel mussel(10); - -int scanTime = 1; //In seconds -BLEScan *pBLEScan; - -class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { - void onResult(BLEAdvertisedDevice advertisedDevice) { - if (advertisedDevice.haveName() - && advertisedDevice.getFrameType() == BLE_EDDYSTONE_TLM_FRAME - ) { - BLEEddystoneTLM EddystoneTLM(&advertisedDevice); - mussel.push( - advertisedDevice.getName(), - millis(), - EddystoneTLM.getTemp() - ); - } - } -}; - -void setup() { - Serial.begin(115200); - mussel.begin(); - - BLEDevice::init(""); - pBLEScan = BLEDevice::getScan(); //create new scan - pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); - pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster - pBLEScan->setInterval(100); - pBLEScan->setWindow(99); // less or equal setInterval value -} - -void loop() { - // put your main code here, to run repeatedly: - BLEScanResults *foundDevices = pBLEScan->start(scanTime, false); - pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory - mussel.printStack(); - delay(500); -} diff --git a/Mussel/examples/voting_from_EddystoneTLM/voting_from_EddystoneTLM.puml b/Mussel/examples/voting_from_EddystoneTLM/voting_from_EddystoneTLM.puml deleted file mode 100644 index caafc05..0000000 --- a/Mussel/examples/voting_from_EddystoneTLM/voting_from_EddystoneTLM.puml +++ /dev/null @@ -1,28 +0,0 @@ -@startuml -'start -:instantiate mussel object; -:instantiate bluetooth object; -group init -:setup mussel voting; -:setup bluetooth scanner; -end group -split -while (each beacon detected) -group "bluetooth callback" { -:collect beacon data; -end group -endwhile --[hidden]-> -kill -split again -while (each 500ms) -group loop { -:allign beacon data as ballots; -:qualify ballots for a vote; -:conclude vote result; -:act on vote result; -end group -endwhile --[hidden]-> -kill -@enduml -- cgit v1.2.3