Modified telemetry reporting.
This commit is contained in:
parent
79ca903ba4
commit
a033864241
|
@ -33,7 +33,7 @@ extern "C" {
|
|||
#include "BLEBeacon.h"
|
||||
#include "BLEEddystoneTLM.h"
|
||||
#include "BLEEddystoneURL.h"
|
||||
#include "Settings_a.h"
|
||||
#include "Settings_d.h"
|
||||
|
||||
BLEScan* pBLEScan;
|
||||
int scanTime = singleScanTime; //In seconds
|
||||
|
@ -96,18 +96,23 @@ float calculateDistance(int rssi, int txPower) {
|
|||
|
||||
}
|
||||
|
||||
bool sendTelemetry(int deviceCount) {
|
||||
bool sendTelemetry(int deviceCount = -1, int reportCount = -1) {
|
||||
StaticJsonDocument<256> tele;
|
||||
tele["room"] = room;
|
||||
tele["ip"] = localIp;
|
||||
tele["hostname"] = WiFi.getHostname();
|
||||
tele["scan_duration"] = scanTime;
|
||||
tele["wait_duration"] = waitTime;
|
||||
tele["max_distance"] = maxDistance;
|
||||
tele["scan_dur"] = scanTime;
|
||||
tele["wait_dur"] = waitTime;
|
||||
tele["max_dist"] = maxDistance;
|
||||
|
||||
if (deviceCount > -1) {
|
||||
Serial.printf("devices_reported: %d\n\r",deviceCount);
|
||||
tele["devices_reported"] = deviceCount;
|
||||
Serial.printf("devices_discovered: %d\n\r",deviceCount);
|
||||
tele["disc_ct"] = deviceCount;
|
||||
}
|
||||
|
||||
if (reportCount > -1) {
|
||||
Serial.printf("devices_reported: %d\n\r",reportCount);
|
||||
tele["rept_ct"] = reportCount;
|
||||
}
|
||||
|
||||
char teleMessageBuffer[258];
|
||||
|
@ -182,7 +187,7 @@ void onMqttConnect(bool sessionPresent) {
|
|||
Serial.println("Error sending message");
|
||||
}
|
||||
|
||||
sendTelemetry(-1);
|
||||
sendTelemetry();
|
||||
|
||||
}
|
||||
|
||||
|
@ -240,8 +245,9 @@ bool reportDevice(BLEAdvertisedDevice advertisedDevice) {
|
|||
// Serial.printf("Eddystone Frame Type (Unencrypted Eddystone-TLM) \n");
|
||||
// Serial.printf(oBeacon.toString().c_str());
|
||||
} else {
|
||||
Serial.println("service data");
|
||||
for (int i=0;i<strServiceData.length();i++) {
|
||||
// Serial.printf("[%X]",cServiceData[i]);
|
||||
Serial.printf("[%X]",cServiceData[i]);
|
||||
}
|
||||
}
|
||||
// Serial.printf("\n");
|
||||
|
@ -279,10 +285,6 @@ bool reportDevice(BLEAdvertisedDevice advertisedDevice) {
|
|||
doc["txPower"] = oBeacon.getSignalPower();
|
||||
doc["distance"] = distance;
|
||||
|
||||
// Serial.printf("iBeacon Frame\n");
|
||||
// Serial.printf("Major: %d Minor: %d UUID: %s Power: %d Rssi: %d Distance: %f\n",ENDIAN_CHANGE_U16(oBeacon.getMajor()),ENDIAN_CHANGE_U16(oBeacon.getMinor()),proximityUUID.c_str(),oBeacon.getSignalPower(), rssi, distance);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
if (advertisedDevice.haveTXPower()) {
|
||||
|
@ -375,7 +377,8 @@ void scanForDevices(void * parameter) {
|
|||
devicesReported++;
|
||||
}
|
||||
}
|
||||
sendTelemetry(devicesReported);
|
||||
sendTelemetry(devicesCount, devicesReported);
|
||||
pBLEScan->clearResults();
|
||||
} else {
|
||||
Serial.println("Cannot report; mqtt disconnected");
|
||||
}
|
||||
|
|
14
README.md
14
README.md
|
@ -31,10 +31,11 @@ sensor:
|
|||
|
||||
binary_sensor:
|
||||
|
||||
# One entry per sensor node to understand when the device is online/offline
|
||||
# One entry per sensor node to understand when the device is online/offline and see device metadata such as IP address and settings values
|
||||
- platform: mqtt
|
||||
name: ESP32 Room Presence
|
||||
state_topic: "presence_nodes/esp32"
|
||||
json_attributes_topic: "presence_nodes/esp32/tele"
|
||||
payload_on: "CONNECTED"
|
||||
payload_off: "DISCONNECTED"
|
||||
device_class: connectivity
|
||||
|
@ -48,20 +49,15 @@ Generic beacon hardware should be compatible, provided it meets a beacon standar
|
|||
In order to track your Android phone as a BLE Beacon, you will need to emulate Beacon adertisement packets from your phone. This is the opposite to what most beacon apps do (i.e. scanning for beacons instead of emulating one). I have had success using the [Beacon Scope](https://play.google.com/store/apps/details?id=com.davidgyoungtech.beaconscanner) app. Configure a transmitter, and specify the device ID in your Home Assistant configuration files.
|
||||
|
||||
### Tracking iPhone
|
||||
Unfortunately, Apple does not allow devices to advertise iBeacon data in the background.
|
||||
Unfortunately, Apple does not allow devices to advertise iBeacon data in the background. As I do not own an iPhone, I will not attempt to implement scanning and reporting by device name, but I welcome pull requests.
|
||||
|
||||
#### Future Development Tasks
|
||||
- [x] Implement basic BLE packet discovery
|
||||
- [x] Implement iBeacon data packet parsing
|
||||
- [x] Setup instructions in README.md
|
||||
- [ ] Address watchdog issue
|
||||
- [ ] Match configuration options to Room Assistant
|
||||
- [x] Address watchdog issue
|
||||
- [ ] Implement Mi Flora data parsing and reporting
|
||||
- [ ] Whitelist functionality
|
||||
- [ ] Blacklist functionality
|
||||
- [ ] Maximum distance limit
|
||||
- [x] Maximum distance limit (rounded to two decimal places)
|
||||
- [x] Scan interval Settings
|
||||
- [ ] Configuration via Web UI
|
||||
- [ ] Wifi Manager for managing access point credentials
|
||||
- [x] Implement Over-The-Air (OTA) updates
|
||||
- [x] Build and upload via [PlatformIO](platformio.org)
|
||||
|
|
Loading…
Reference in New Issue