better fix for presence detection

This commit is contained in:
technyon
2022-06-12 10:52:01 +02:00
parent 6ee529b2d9
commit 584eb031d5
6 changed files with 14 additions and 13 deletions

View File

@@ -205,7 +205,12 @@ void Network::update()
if(_presenceCsv != nullptr && strlen(_presenceCsv) > 0)
{
publishString_P(mqtt_topic_presence, _presenceCsv);
bool success = publishString(mqtt_topic_presence, _presenceCsv);
if(!success)
{
Serial.println(F("Failed to publish presence CSV data."));
Serial.println(_presenceCsv);
}
_presenceCsv = nullptr;
}
@@ -387,18 +392,11 @@ void Network::publishBool(const char *topic, const bool value)
_device->mqttClient()->publish(path, str);
}
void Network::publishString(const char *topic, const char *value)
bool Network::publishString(const char *topic, const char *value)
{
char path[200] = {0};
buildMqttPath(topic, path);
_device->mqttClient()->publish(path, value);
}
void Network::publishString_P(const char *topic, const char *value)
{
char path[200] = {0};
buildMqttPath(topic, path);
_device->mqttClient()->publish_P(path, value, true);
return _device->mqttClient()->publish(path, value);
}
bool Network::isMqttConnected()

View File

@@ -54,8 +54,7 @@ private:
void publishInt(const char* topic, const int value);
void publishUInt(const char* topic, const unsigned int value);
void publishBool(const char* topic, const bool value);
void publishString(const char* topic, const char* value);
void publishString_P(const char* topic, const char* value);
bool publishString(const char* topic, const char* value);
void buildMqttPath(const char* path, char* outPath);
void subscribe(const char* path);

View File

@@ -87,7 +87,7 @@ void setupTasks()
{
// configMAX_PRIORITIES is 25
xTaskCreate(networkTask, "ntw", 32768, NULL, 3, NULL);
xTaskCreate(networkTask, "ntw", 65536, NULL, 3, NULL);
xTaskCreate(nukiTask, "nuki", 8192, NULL, 2, NULL);
xTaskCreate(presenceDetectionTask, "prdet", 1024, NULL, 5, NULL);
xTaskCreate(checkMillisTask, "mlchk", 512, NULL, 1, NULL);

View File

@@ -20,5 +20,6 @@ public:
virtual bool isConnected() = 0;
protected:
const uint16_t _mqttMaxBufferSize = 16384;
const String _hostname;
};

View File

@@ -38,6 +38,7 @@ void W5500Device::initialize()
Ethernet.init(ETHERNET_CS_PIN);
_ethClient = new EthernetClient();
_mqttClient = new PubSubClient(*_ethClient);
_mqttClient->setBufferSize(_mqttMaxBufferSize);
reconnect();

View File

@@ -47,6 +47,8 @@ void WifiDevice::initialize()
Serial.print(F("WiFi connected: "));
Serial.println(WiFi.localIP().toString());
}
_mqttClient.setBufferSize(_mqttMaxBufferSize);
}
void WifiDevice::reconfigure()