reduce scan interval; publish rssi

This commit is contained in:
technyon
2022-04-06 18:24:17 +02:00
parent b5e5c4da60
commit 7ce71b8bea
3 changed files with 39 additions and 3 deletions

View File

@@ -31,7 +31,7 @@ void NukiWrapper::initialize()
{
_bleScanner = new BleScanner();
_bleScanner->initialize();
_bleScanner->setScanDuration(30);
_bleScanner->setScanDuration(10);
_nukiBle.initialize();
_nukiBle.registerBleScanner(_bleScanner);

View File

@@ -53,7 +53,7 @@ void PresenceDetection::update()
}
// Prevent csv buffer overflow
if(_csvIndex > presence_detection_buffer_size - (sizeof(it.second.name) + sizeof(it.second.address) + 3))
if(_csvIndex > presence_detection_buffer_size - (sizeof(it.second.name) + sizeof(it.second.address) + 10))
{
break;
}
@@ -82,6 +82,24 @@ void PresenceDetection::buildCsv(const PdDevice &device)
++_csvIndex;
++i;
}
_csv[_csvIndex] = ';';
++_csvIndex;
if(device.hasRssi)
{
char rssiStr[20] = {0};
itoa(device.rssi, rssiStr, 10);
int i=0;
while(rssiStr[i] != 0x00 && i < 20)
{
_csv[_csvIndex] = rssiStr[i];
++_csvIndex;
++i;
}
}
_csv[_csvIndex] = '\n';
_csvIndex++;
}
@@ -136,16 +154,32 @@ void PresenceDetection::onResult(NimBLEAdvertisedDevice *device)
_devices[addr] = pdDevice;
}
if(device->haveRSSI())
{
pdDevice.hasRssi = true;
pdDevice.rssi = device->getRSSI();
}
}
else
{
it->second.timestamp = millis();
if(device->haveRSSI())
{
it->second.hasRssi = true;
it->second.rssi = device->getRSSI();
}
}
// if(device->haveName())
// {
// Serial.print(" | ");
// Serial.print(device->getName().c_str());
// if(device->haveRSSI())
// {
// Serial.print(" | ");
// Serial.print(device->getRSSI());
// }
// }
// Serial.println();

View File

@@ -8,7 +8,9 @@ struct PdDevice
{
char address[18] = {0};
char name[30] = {0};
unsigned long timestamp;
unsigned long timestamp = 0;
int rssi = 0;
bool hasRssi = false;
};
#define presence_detection_buffer_size 4096