From a033864241c27fe0521c2b97c0bf805c7584e683 Mon Sep 17 00:00:00 2001 From: jptrsn Date: Tue, 25 Jun 2019 09:13:22 -0400 Subject: [PATCH] Modified telemetry reporting. --- ESP32-mqtt-room.ino | 31 +++++++++++++++++-------------- README.md | 14 +++++--------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/ESP32-mqtt-room.ino b/ESP32-mqtt-room.ino index 98bfd35..a435d0b 100644 --- a/ESP32-mqtt-room.ino +++ b/ESP32-mqtt-room.ino @@ -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;iclearResults(); } else { Serial.println("Cannot report; mqtt disconnected"); } diff --git a/README.md b/README.md index c0318e3..616264d 100644 --- a/README.md +++ b/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)