Fix errant iBeacon w/ positive calRssi

This commit is contained in:
DTTerastar 2021-08-23 18:10:53 -04:00
parent 56d3c93d05
commit 1da95e5467
4 changed files with 27 additions and 15 deletions

View File

@ -92,7 +92,8 @@ BleFingerprint::BleFingerprint(BLEAdvertisedDevice *advertisedDevice, float fcmi
id = "iBeacon:" + proximityUUID;
Serial.printf(", ID: %s", id.c_str());
calRssi = -oBeacon.getSignalPower();
calRssi = oBeacon.getSignalPower();
if (calRssi > 0) calRssi = defaultTxPower;
}
else
{
@ -179,15 +180,15 @@ bool BleFingerprint::report(JsonDocument *doc, int maxDistance)
if (!hasValue)
return false;
if (maxDistance > 0 && output.value.position > maxDistance)
return false;
// if (maxDistance > 0 && output.value.position > maxDistance)
// return false;
if (reported)
return false;
auto now = esp_timer_get_time();
if (abs(output.value.position - lastReported) < 0.05f && abs(now - lastReportedMicros) < 5000000)
if (abs(output.value.position - lastReported) < 0.1f && abs(now - lastReportedMicros) < 15000000)
return false;
lastReportedMicros = now;

View File

@ -11,9 +11,6 @@
//Replace with your Wifi password; example: #define password "12345678"
#define DEFAULT_WIFI_PASSWORD "$WIFI_PASSWORD$"
//Replace with a human-friendly host name. Must not contain spaces or special characters and be unique on your network
#define DEFAULT_HOSTNAME "esp32_room_presence"
//Replace with your MQTT Broker address
#define DEFAULT_MQTT_HOST "mqtt.z13.org"
@ -26,8 +23,8 @@
//Replace with your MQTT Broker password
#define DEFAULT_MQTT_PASSWORD ""
//Replace with the room name where the node will be placed
#define DEFAULT_ROOM "living-room"
// Maximum distance (in meters) to report. Devices that are calculated to be further than this distance in meters will not be reported
#define DEFAULT_MAX_DISTANCE 16
#ifdef M5STICK
@ -69,9 +66,6 @@
#define BLE_SCAN_INTERVAL 40 // Used to determine antenna sharing between Bluetooth and WiFi. Do not modify unless you are confident you know what you're doing
#define BLE_SCAN_WINDOW 30 // Used to determine antenna sharing between Bluetooth and WiFi. Do not modify unless you are confident you know what you're doing
// Maximum distance (in meters) to report. Devices that are calculated to be further than this distance in meters will not be reported
#define MAX_DISTANCE 16
// Max number of mac addresses to keep track of
#define MAX_MAC_ADDRESSES 50

View File

@ -48,9 +48,15 @@ bool sendTelemetry(int totalSeen = -1, int totalReported = -1, int totalAdverts
}
}
auto now = esp_timer_get_time();
if (abs(now - lastTeleMicros) < 15000000)
return false;
lastTeleMicros = now;
StaticJsonDocument<512> tele;
tele["ip"] = localIp;
tele["hostname"] = WiFi.getHostname();
tele["uptime"] = getUptimeSeconds();
tele["firm"] = String(FIRMWARE);
tele["rssi"] = WiFi.RSSI();
@ -117,9 +123,11 @@ void connectToWifi()
mqttUser = WiFiSettings.string("mqtt_user", DEFAULT_MQTT_USER);
mqttPass = WiFiSettings.string("mqtt_pass", DEFAULT_MQTT_PASSWORD);
room = WiFiSettings.string("room", ESPMAC);
WiFiSettings.heading("Preferences");
publishTele = WiFiSettings.checkbox("pub_tele", true, "Send to telemetry topic");
publishRooms = WiFiSettings.checkbox("pub_rooms", true, "Send to rooms topic");
publishDevices = WiFiSettings.checkbox("pub_devices", true, "Send to devices topic");
maxDistance = WiFiSettings.integer("max_dist", DEFAULT_MAX_DISTANCE, "Maximum distance to report (in meters)");
WiFiSettings.hostname = "espresense-" + room;
@ -134,6 +142,13 @@ void connectToWifi()
Serial.println(WiFi.getHostname());
Serial.print("Room: ");
Serial.println(room);
Serial.print("Telemetry: ");
Serial.println(publishRooms ? "enabled" : "disabled");
Serial.print("Rooms: ");
Serial.println(publishRooms ? "enabled" : "disabled");
Serial.print("Devices: ");
Serial.println(publishDevices ? "enabled" : "disabled");
Serial.printf("Max Distance: %d\n", maxDistance);
localIp = WiFi.localIP().toString();
roomsTopic = CHANNEL + "/rooms/" + room;
@ -210,7 +225,7 @@ private:
bool reportDevice(BleFingerprint *f)
{
StaticJsonDocument<512> doc;
if (!f->report(&doc, MAX_DISTANCE))
if (!f->report(&doc, maxDistance))
return false;
char JSONmessageBuffer[512];

View File

@ -28,8 +28,10 @@ TaskHandle_t scannerTask;
bool updateInProgress = false;
String localIp;
int64_t lastTeleMicros;
int reconnectTries = 0;
int teleFails = 0;
bool online; // Have we successfully sent status=online
String mqttHost;
int mqttPort;
@ -42,7 +44,7 @@ String roomsTopic;
bool publishTele;
bool publishRooms;
bool publishDevices;
bool online; // Have we successfully sent status=online
int maxDistance;
static SemaphoreHandle_t fingerprintSemaphore;
static std::list<BleFingerprint *> fingerprints;