dawidchyrzynski / arduino-home-assistant

ArduinoHA allows to integrate an Arduino/ESP based device with Home Assistant using MQTT.
https://dawidchyrzynski.github.io/arduino-home-assistant/
GNU Affero General Public License v3.0
463 stars 112 forks source link

_mqtt->setBufferSize #202

Closed qibao07 closed 5 months ago

qibao07 commented 8 months ago

Support setBufferSize.

bool HAMqtt::begin(
    const IPAddress serverIp,
    const uint16_t serverPort,
    const char* username,
    const char* password,
    const uint16_t bufferSize
)
{
    ARDUINOHA_DEBUG_PRINT(F("AHA: init server "))
    ARDUINOHA_DEBUG_PRINT(serverIp)
    ARDUINOHA_DEBUG_PRINT(F(":"))
    ARDUINOHA_DEBUG_PRINTLN(serverPort)

    if (_device.getUniqueId() == nullptr) {
        ARDUINOHA_DEBUG_PRINTLN(F("AHA: init failed. Missing device unique ID"))
        return false;
    }

    if (_initialized) {
        ARDUINOHA_DEBUG_PRINTLN(F("AHA: already initialized"))
        return false;
    }

    _username = username;
    _password = password;
    _initialized = true;

    _mqtt->setServer(serverIp, serverPort);
    _mqtt->setCallback(onMessageReceived);
    _mqtt->setBufferSize(bufferSize);

    return true;
}
dawidchyrzynski commented 6 months ago

Hi @qibao07, what's the use case?

qibao07 commented 6 months ago

@dawidchyrzynski Thank you for your reply. Sometimes the received message is too long, causing the message to be truncated. Modifying this value can only modify imported code files.

dawidchyrzynski commented 6 months ago

@qibao07 Do you mean the messages that the library handles/generates, or are you handling your custom messages?

qibao07 commented 6 months ago

@dawidchyrzynski I implemented HAText myself with reference to HANumber. It was found that long messages require large buffer. Custom messages are also required.

dawidchyrzynski commented 5 months ago

This feature will be available in the upcoming version of the library. Please refer to the linked Pull Request for more information.