+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ESP32-mqtt-room.ino b/ESP32-mqtt-room.ino
index 5cfc2ec..2522b5d 100644
--- a/ESP32-mqtt-room.ino
+++ b/ESP32-mqtt-room.ino
@@ -1,18 +1,17 @@
/*
-
+
Major thank you to the following contributors for their efforts:
pcbreflux for the original version of this code, as well as the eddystone handlers.
Andreis Speiss for his work on YouTube and his invaluable github at sensorsiot
-
+
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
*/
#include
#include
#include
-
#include
#include
#include
@@ -23,7 +22,7 @@
#include "Settings_local.h"
BLEScan* pBLEScan;
-int scanTime = 5; //In seconds
+int scanTime = 10; //In seconds
int waitTime = scanInterval; //In seconds
uint16_t beconUUID = 0xFEAA;
@@ -104,6 +103,10 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
+ unsigned long started = millis();
+ Serial.printf("\n\n");
+ Serial.println("onResult started");
+
StaticJsonBuffer<500> JSONbuffer;
JsonObject& JSONencoder = JSONbuffer.createObject();
@@ -116,14 +119,18 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
JSONencoder["uuid"] = mac_address;
JSONencoder["rssi"] = rssi;
+ Serial.println("Parsed id");
+
if (advertisedDevice.haveName()){
String nameBLE = String(advertisedDevice.getName().c_str());
+ Serial.print("Name: ");
+ Serial.println(nameBLE);
JSONencoder["name"] = nameBLE;
} else {
JSONencoder["name"] = "unknown";
}
- Serial.printf("\n\n");
+ // Serial.printf("\n\n");
Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
std::string strServiceData = advertisedDevice.getServiceData();
uint8_t cServiceData[100];
@@ -153,7 +160,7 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
} else {
if (advertisedDevice.haveManufacturerData()==true) {
std::string strManufacturerData = advertisedDevice.getManufacturerData();
-
+ Serial.println("Got manufacturer data");
uint8_t cManufacturerData[100];
strManufacturerData.copy((char *)cManufacturerData, strManufacturerData.length(), 0);
@@ -198,10 +205,7 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
Serial.printf("strManufacturerData: %d \n",strManufacturerData.length());
// TODO: parse manufacturer data
-// for (int i=0;i (waitTime * 1000)) {
+ // vTaskDelay(10); // watchdog timer
+
+ if (millis() - last > (waitTime * 1000) || last == 0) {
Serial.println("Scanning...");
BLEScanResults foundDevices = pBLEScan->start(scanTime);
Serial.printf("\nScan done! Devices found: %d\n",foundDevices.getCount());
last = millis();
}
- vTaskDelay(10); // watchdog timer
+
}
diff --git a/README.md b/README.md
index e91c000..f398a7a 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,10 @@ An ESP32 based presence detection node for use with the Home Assistant mqtt_room
This depends heavily on the hard work done by [pcbreflux](https://github.com/pcbreflux) and [nkolban](https://github.com/nkolban) both on GitHub and on their YouTube Channels. Specifically, it is a modified version of pcbreflux's [ESP32_BLE_beaconscan](https://github.com/pcbreflux/espressif/tree/master/esp32/arduino/sketchbook/ESP32_BLE_beaconscan).
## Getting Started
-1. You can get started by cloning this repository to your local machine using git. Alternatively, you can [download the zip](https://github.com/jptrsn/ESP32-mqtt-room/archive/master.zip).
+
+You can get started by cloning this repository to your local machine using git. Alternatively, you can [download the zip](https://github.com/jptrsn/ESP32-mqtt-room/archive/master.zip). To get the code onto your device, you can load it via the Arduino IDE or, thanks to some great work by [kylegordon](https://github.com/kylegordon), you can now build and upload using PlatformIO.
+
+
2. Make a copy of the `Settings.h` file, and rename it `Settings_local.h`. Fill in the required information in your local settings file (the local file is ignored by GitHub, so you won't upload your sensitive information).
### Configuration
diff --git a/BLEEddystoneTLM.cpp b/lib/BLEEddystoneTLM/BLEEddystoneTLM.cpp
similarity index 100%
rename from BLEEddystoneTLM.cpp
rename to lib/BLEEddystoneTLM/BLEEddystoneTLM.cpp
diff --git a/BLEEddystoneTLM.h b/lib/BLEEddystoneTLM/BLEEddystoneTLM.h
similarity index 100%
rename from BLEEddystoneTLM.h
rename to lib/BLEEddystoneTLM/BLEEddystoneTLM.h
diff --git a/BLEEddystoneURL.cpp b/lib/BLEEddystoneURL/BLEEddystoneURL.cpp
similarity index 100%
rename from BLEEddystoneURL.cpp
rename to lib/BLEEddystoneURL/BLEEddystoneURL.cpp
diff --git a/BLEEddystoneURL.h b/lib/BLEEddystoneURL/BLEEddystoneURL.h
similarity index 100%
rename from BLEEddystoneURL.h
rename to lib/BLEEddystoneURL/BLEEddystoneURL.h
diff --git a/lib/readme.txt b/lib/readme.txt
new file mode 100644
index 0000000..cfa16df
--- /dev/null
+++ b/lib/readme.txt
@@ -0,0 +1,41 @@
+
+This directory is intended for project specific (private) libraries.
+PlatformIO will compile them to static libraries and link them to executable files.
+
+The source code of each library should be placed in separate directories, like
+"lib/private_lib/[here are source files]".
+
+For example, see the structure of the following two libraries `Foo` and `Bar`:
+
+|--lib
+| |
+| |--Bar
+| | |--docs
+| | |--examples
+| | |--src
+| | |- Bar.c
+| | |- Bar.h
+| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
+| |
+| |--Foo
+| | |- Foo.c
+| | |- Foo.h
+| |
+| |- readme.txt --> THIS FILE
+|
+|- platformio.ini
+|--src
+ |- main.c
+
+Then in `src/main.c` you should use:
+
+#include
+#include
+
+// rest H/C/CPP code
+
+PlatformIO will find your libraries automatically, configure preprocessor's
+include paths and build them.
+
+More information about PlatformIO Library Dependency Finder
+- https://docs.platformio.org/page/librarymanager/ldf.html
diff --git a/platformio.ini b/platformio.ini
index 77daa69..6d80167 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -15,5 +15,6 @@ src_dir = .
platform = espressif32
framework = arduino
board = esp32dev
-lib_deps = PubSubClient, ArduinoJSON
+lib_deps = PubSubClient@2.6.0, ArduinoJSON@5.13.2, ESP32 BLE Arduino, AsyncMqttClient@0.8.2, AsyncTCP@1.0.1
board_build.partitions = partitions_singleapp.csv
+upload_port = COM13