use -1 to disable presence detection
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#define preference_query_interval_battery "batInterval"
|
#define preference_query_interval_battery "batInterval"
|
||||||
#define preference_cred_user "crdusr"
|
#define preference_cred_user "crdusr"
|
||||||
#define preference_cred_password "crdpass"
|
#define preference_cred_password "crdpass"
|
||||||
|
#define preference_presence_detection_timeout "prdtimeout"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
#include "PresenceDetection.h"
|
#include "PresenceDetection.h"
|
||||||
|
#include "PreferencesKeys.h"
|
||||||
|
|
||||||
PresenceDetection::PresenceDetection(BleScanner *bleScanner, Network* network)
|
PresenceDetection::PresenceDetection(Preferences* preferences, BleScanner *bleScanner, Network* network)
|
||||||
: _bleScanner(bleScanner),
|
: _preferences(preferences),
|
||||||
|
_bleScanner(bleScanner),
|
||||||
_network(network)
|
_network(network)
|
||||||
{
|
{
|
||||||
_csv = new char[presence_detection_buffer_size];
|
_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()
|
PresenceDetection::~PresenceDetection()
|
||||||
@@ -25,8 +37,9 @@ void PresenceDetection::initialize()
|
|||||||
|
|
||||||
void PresenceDetection::update()
|
void PresenceDetection::update()
|
||||||
{
|
{
|
||||||
vTaskDelay( 5000 / portTICK_PERIOD_MS);
|
vTaskDelay( 10000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
if(_timeout < 0) return;
|
||||||
if(_devices.size() == 0) return;
|
if(_devices.size() == 0) return;
|
||||||
|
|
||||||
memset(_csv, 0, presence_detection_buffer_size);
|
memset(_csv, 0, presence_detection_buffer_size);
|
||||||
@@ -34,7 +47,7 @@ void PresenceDetection::update()
|
|||||||
long ts = millis();
|
long ts = millis();
|
||||||
for(auto it : _devices)
|
for(auto it : _devices)
|
||||||
{
|
{
|
||||||
if(ts - 20000 < it.second.timestamp)
|
if(ts - _timeout < it.second.timestamp)
|
||||||
{
|
{
|
||||||
buildCsv(it.second);
|
buildCsv(it.second);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ struct PdDevice
|
|||||||
class PresenceDetection : public BLEScannerSubscriber
|
class PresenceDetection : public BLEScannerSubscriber
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PresenceDetection(BleScanner* bleScanner, Network* network);
|
PresenceDetection(Preferences* preferences, BleScanner* bleScanner, Network* network);
|
||||||
virtual ~PresenceDetection();
|
virtual ~PresenceDetection();
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
@@ -27,12 +27,11 @@ public:
|
|||||||
private:
|
private:
|
||||||
void buildCsv(const PdDevice& device);
|
void buildCsv(const PdDevice& device);
|
||||||
|
|
||||||
|
Preferences* _preferences;
|
||||||
BleScanner* _bleScanner;
|
BleScanner* _bleScanner;
|
||||||
Network* _network;
|
Network* _network;
|
||||||
char* _csv = {0};
|
char* _csv = {0};
|
||||||
std::map<long long, PdDevice> _devices;
|
std::map<long long, PdDevice> _devices;
|
||||||
uint _timeout = 20000;
|
int _timeout = 20000;
|
||||||
int _csvIndex = 0;
|
int _csvIndex = 0;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -129,6 +129,11 @@ bool WebCfgServer::processArgs()
|
|||||||
_preferences->putInt(preference_query_interval_battery, value.toInt());
|
_preferences->putInt(preference_query_interval_battery, value.toInt());
|
||||||
configChanged = true;
|
configChanged = true;
|
||||||
}
|
}
|
||||||
|
else if(key == "PRDTMO")
|
||||||
|
{
|
||||||
|
_preferences->putInt(preference_presence_detection_timeout, value.toInt());
|
||||||
|
configChanged = true;
|
||||||
|
}
|
||||||
else if(key == "CREDUSER")
|
else if(key == "CREDUSER")
|
||||||
{
|
{
|
||||||
if(value == "#")
|
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, "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, "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, "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("</table>");
|
||||||
|
|
||||||
response.concat("<br><INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Save\">");
|
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("<button type=\"submit\">Edit</button>");
|
||||||
response.concat("</form>");
|
response.concat("</form>");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
response.concat("</BODY>\n");
|
response.concat("</BODY>\n");
|
||||||
response.concat("</HTML>\n");
|
response.concat("</HTML>\n");
|
||||||
}
|
}
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@@ -79,7 +79,7 @@ void setup()
|
|||||||
webCfgServer->initialize();
|
webCfgServer->initialize();
|
||||||
nuki->initialize();
|
nuki->initialize();
|
||||||
|
|
||||||
presenceDetection = new PresenceDetection(nuki->bleScanner(), network);
|
presenceDetection = new PresenceDetection(preferences, nuki->bleScanner(), network);
|
||||||
presenceDetection->initialize();
|
presenceDetection->initialize();
|
||||||
|
|
||||||
setupTasks();
|
setupTasks();
|
||||||
|
|||||||
Reference in New Issue
Block a user