This commit is contained in:
Rémi Heredero
2021-04-16 21:15:54 +02:00
commit fec6f19309
19 changed files with 1122 additions and 0 deletions

View File

@ -0,0 +1,50 @@
#include <Arduino.h>
#include <BLEDevice.h>
#include <vector>
#include <string>
#include <Bluetooth.h>
static BLEAddress *pServerAddress;
BLEScan* pBLEScan;
BLEClient* pClient;
std::vector<BeaconBLE> beacons;
unsigned long entry;
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
//Called for each advertising BLE server.
void onResult(BLEAdvertisedDevice advertisedDevice) {
pServerAddress = new BLEAddress(advertisedDevice.getAddress());
BeaconBLE tag;
tag.adresse = pServerAddress->toString().c_str();
tag.qualite = advertisedDevice.getRSSI();
beacons.push_back(tag);
/*
Serial.println();
Serial.print("Device found: ");
Serial.print(tag.adresse);
Serial.print(" => ");
Serial.print(tag.qualite);
*/
}
}; // MyAdvertisedDeviceCallbacks
void setup_ble(){
Serial.println("Starting Arduino BLE Client application...");
BLEDevice::init("");
pClient = BLEDevice::createClient();
Serial.println(" - Created client");
pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true);
}
std::vector<BeaconBLE> loop_ble(){
beacons.clear();
BLEScanResults scanResults = pBLEScan->start(1);
return beacons;
}

12
lib/Bluetooth/Bluetooth.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef BLUETOOTH_H_INCLUDED
#define BLUETOOTH_H_INCLUDED
struct BeaconBLE {
String adresse;
int qualite;
};
void setup_ble();
std::vector<BeaconBLE> loop_ble();
#endif