diff options
author | Jonas Smedegaard <dr@jones.dk> | 2025-04-13 13:03:53 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2025-04-13 13:03:53 +0200 |
commit | ed3ac0eb11a04630f7f08124a484a854eea13569 (patch) | |
tree | db1abdc77f1bca0d757d9f14d73830ff8509c400 /Mussel/examples/vote/vote.ino | |
parent | 9c84a009850a06e090b258b6b160ca2cdb41706e (diff) |
rename and describe bluetooth examples
Diffstat (limited to 'Mussel/examples/vote/vote.ino')
-rw-r--r-- | Mussel/examples/vote/vote.ino | 55 |
1 files changed, 55 insertions, 0 deletions
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 <Mussel.h> +#include <Arduino.h> + +#include <BLEDevice.h> +#include <BLEScan.h> +#include <BLEAdvertisedDevice.h> +#include <BLEEddystoneTLM.h> +#include <BLEBeacon.h> + +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); +} |