diff --git a/Network.cpp b/Network.cpp index 31af0ee..0339e76 100644 --- a/Network.cpp +++ b/Network.cpp @@ -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() diff --git a/Network.h b/Network.h index 05c4d8c..ff5890f 100644 --- a/Network.h +++ b/Network.h @@ -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); diff --git a/main.cpp b/main.cpp index 9c09801..fa36029 100644 --- a/main.cpp +++ b/main.cpp @@ -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); diff --git a/networkDevices/NetworkDevice.h b/networkDevices/NetworkDevice.h index 09e064a..28a76a8 100644 --- a/networkDevices/NetworkDevice.h +++ b/networkDevices/NetworkDevice.h @@ -20,5 +20,6 @@ public: virtual bool isConnected() = 0; protected: + const uint16_t _mqttMaxBufferSize = 16384; const String _hostname; }; \ No newline at end of file diff --git a/networkDevices/W5500Device.cpp b/networkDevices/W5500Device.cpp index 87210e3..1041046 100644 --- a/networkDevices/W5500Device.cpp +++ b/networkDevices/W5500Device.cpp @@ -38,6 +38,7 @@ void W5500Device::initialize() Ethernet.init(ETHERNET_CS_PIN); _ethClient = new EthernetClient(); _mqttClient = new PubSubClient(*_ethClient); + _mqttClient->setBufferSize(_mqttMaxBufferSize); reconnect(); diff --git a/networkDevices/WifiDevice.cpp b/networkDevices/WifiDevice.cpp index 0dc14ef..87633f1 100644 --- a/networkDevices/WifiDevice.cpp +++ b/networkDevices/WifiDevice.cpp @@ -47,6 +47,8 @@ void WifiDevice::initialize() Serial.print(F("WiFi connected: ")); Serial.println(WiFi.localIP().toString()); } + + _mqttClient.setBufferSize(_mqttMaxBufferSize); } void WifiDevice::reconfigure()