Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jptrsn committed Jun 26, 2021
2 parents 1b9070e + 6148131 commit 73a5dc2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions docs/home_assistant.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Home Assistant Configuration
Once the ESP32 is running, it is important to configure Home Assistant to use the information from the MQTT topic to determine what devices to track. You can read the full documentation [on the Home Assistant website](https://www.home-assistant.io/components/sensor.mqtt_room/). It is critical that you configure your device IDs to include the Major and Minor versions, in the format `{{beacon uuid}}-{{major}}-{{minor}}`

To obtain a `{{beacon uuid}}-{{major}}-{{minor}}`, you need to setup a beacon following one of the guides:
- [Android](./android.md)
- [Beacons](./beacons.md)
- [generic_ble](./generic_ble.md)

### configuration.yaml
Here is an example of how an entry into your `configuration.yaml` file should look:
```yaml
Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ board = esp32dev
lib_deps = ArduinoJson@^6, ESP32 BLE Arduino@^1.0.1, AsyncMqttClient@^0.8.2, AsyncTCP
lib_ignore = ESPAsyncTCP
board_build.partitions = partitions_singleapp.csv
monitor_speed = 115200
30 changes: 24 additions & 6 deletions src/ESP32-mqtt-room.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C" {
#include "BLEBeacon.h"
#include "BLEEddystoneTLM.h"
#include "BLEEddystoneURL.h"
#include "Settings_f.h"
#include "Settings.h"

#ifdef htuSensorTopic
#define tempTopic htuSensorTopic "/temperature"
Expand Down Expand Up @@ -318,6 +318,25 @@ bool reportDevice(BLEAdvertisedDevice advertisedDevice) {
String mac_address = advertisedDevice.getAddress().toString().c_str();
mac_address.replace(":","");
mac_address.toLowerCase();


//Check scanned MAC Address against a list of allowed MAC Addresses

if (allowedListCheck) {
bool allowedListFound = false;
for (uint32_t x = 0; x < allowedListNumberOfItems; x++) {
if (mac_address == allowedList[x]) {
allowedListFound = true;
}
}

if (allowedListFound == false) {
return false;
}
}
// --------------


// Serial.print("mac:\t");
// Serial.println(mac_address);
int rssi = advertisedDevice.getRSSI();
Expand Down Expand Up @@ -346,11 +365,11 @@ bool reportDevice(BLEAdvertisedDevice advertisedDevice) {

if (advertisedDevice.getServiceDataUUID().equals(BLEUUID(beaconUUID))==true) { // found Eddystone UUID
// Serial.printf("is Eddystone: %d %s length %d\n", advertisedDevice.getServiceDataUUID().bitSize(), advertisedDevice.getServiceDataUUID().toString().c_str(),strServiceData.length());
// Update distance variable for Eddystone BLE devices
BLEBeacon oBeacon = BLEBeacon();
distance = calculateDistance(rssi, oBeacon.getSignalPower());
doc["distance"] = distance;

// Update distance variable for Eddystone BLE devices
BLEBeacon oBeacon = BLEBeacon();
distance = calculateDistance(rssi, oBeacon.getSignalPower());
doc["distance"] = distance;

if (cServiceData[0]==0x10) {
BLEEddystoneURL oBeacon = BLEEddystoneURL();
Expand Down Expand Up @@ -581,7 +600,6 @@ void setup() {

BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(activeScan);
pBLEScan->setInterval(bleScanInterval);
pBLEScan->setWindow(bleScanWindow);
Expand Down
7 changes: 7 additions & 0 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@

// MQTT topic for sensor values from HTU21D temperature and humidity sensor
//#define htuSensorTopic "presence_nodes/" hostname "/sensor"


//List of allowed MAC Addresses for MQTT Publish. All others will be ignored.
//Feature is disabled by default.
#define allowedListCheck false
String allowedList[] = {"11223344aabb", "11223344aabb"};
uint32_t allowedListNumberOfItems = 2;

0 comments on commit 73a5dc2

Please sign in to comment.