use -1 to disable presence detection

This commit is contained in:
technyon
2022-04-05 23:03:12 +02:00
parent 2b68a51a23
commit 28687d2b96
5 changed files with 28 additions and 12 deletions

View File

@@ -10,6 +10,7 @@
#define preference_query_interval_battery "batInterval"
#define preference_cred_user "crdusr"
#define preference_cred_password "crdpass"
#define preference_presence_detection_timeout "prdtimeout"

View File

@@ -1,10 +1,22 @@
#include "PresenceDetection.h"
#include "PreferencesKeys.h"
PresenceDetection::PresenceDetection(BleScanner *bleScanner, Network* network)
: _bleScanner(bleScanner),
PresenceDetection::PresenceDetection(Preferences* preferences, BleScanner *bleScanner, Network* network)
: _preferences(preferences),
_bleScanner(bleScanner),
_network(network)
{
_csv = new char[presence_detection_buffer_size];
_timeout = _preferences->getInt(preference_presence_detection_timeout) * 1000;
if(_timeout == 0)
{
_timeout = 60000;
_preferences->putInt(preference_presence_detection_timeout, 60);
}
Serial.print(F("Presence detection timeout (ms): "));
Serial.println(_timeout);
}
PresenceDetection::~PresenceDetection()
@@ -25,8 +37,9 @@ void PresenceDetection::initialize()
void PresenceDetection::update()
{
vTaskDelay( 5000 / portTICK_PERIOD_MS);
vTaskDelay( 10000 / portTICK_PERIOD_MS);
if(_timeout < 0) return;
if(_devices.size() == 0) return;
memset(_csv, 0, presence_detection_buffer_size);
@@ -34,7 +47,7 @@ void PresenceDetection::update()
long ts = millis();
for(auto it : _devices)
{
if(ts - 20000 < it.second.timestamp)
if(ts - _timeout < it.second.timestamp)
{
buildCsv(it.second);
}

View File

@@ -16,7 +16,7 @@ struct PdDevice
class PresenceDetection : public BLEScannerSubscriber
{
public:
PresenceDetection(BleScanner* bleScanner, Network* network);
PresenceDetection(Preferences* preferences, BleScanner* bleScanner, Network* network);
virtual ~PresenceDetection();
void initialize();
@@ -27,12 +27,11 @@ public:
private:
void buildCsv(const PdDevice& device);
Preferences* _preferences;
BleScanner* _bleScanner;
Network* _network;
char* _csv = {0};
std::map<long long, PdDevice> _devices;
uint _timeout = 20000;
int _timeout = 20000;
int _csvIndex = 0;
};

View File

@@ -129,6 +129,11 @@ bool WebCfgServer::processArgs()
_preferences->putInt(preference_query_interval_battery, value.toInt());
configChanged = true;
}
else if(key == "PRDTMO")
{
_preferences->putInt(preference_presence_detection_timeout, value.toInt());
configChanged = true;
}
else if(key == "CREDUSER")
{
if(value == "#")
@@ -205,6 +210,7 @@ void WebCfgServer::buildHtml(String& response)
printInputField(response, "MQTTPATH", "MQTT Path", _preferences->getString(preference_mqtt_path).c_str(), 180);
printInputField(response, "LSTINT", "Query interval lock state (seconds)", _preferences->getInt(preference_query_interval_lockstate), 10);
printInputField(response, "BATINT", "Query interval battery (seconds)", _preferences->getInt(preference_query_interval_battery), 10);
printInputField(response, "PRDTMO", "Presence detection timeout (seconds, -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10);
response.concat("</table>");
response.concat("<br><INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Save\">");
@@ -218,9 +224,6 @@ void WebCfgServer::buildHtml(String& response)
response.concat("<button type=\"submit\">Edit</button>");
response.concat("</form>");
//
response.concat("</BODY>\n");
response.concat("</HTML>\n");
}

View File

@@ -79,7 +79,7 @@ void setup()
webCfgServer->initialize();
nuki->initialize();
presenceDetection = new PresenceDetection(nuki->bleScanner(), network);
presenceDetection = new PresenceDetection(preferences, nuki->bleScanner(), network);
presenceDetection->initialize();
setupTasks();