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
480 stars 116 forks source link

How use WiFiClient and WiFiClientSecure both? For global object #148

Closed taiwansensor closed 1 year ago

taiwansensor commented 1 year ago

I have a project and encountered a problem. I want to use both WiFiClientSecure and WiFiClient. My program defines a variable "mqtt_secure", which is true when using WiFiClientSecure and false when using WiFiClient. However, I cannot handle this in the global variable declaration. The following is my code. Can you please help me? Because of the following code:

instances need to be initialized once globally or as a part of another global object.

HADevice device; HAMqtt mqtt(eClient, device); HASensorNumber alaSensor("aLaInput", HASensorNumber::PrecisionP1); It cannot be set in the setup() function, it is declared globally. How can I modify it to switch the eClient part of HAMqtt mqtt(eClient, device) based on my variable "mqtt_secure" in the future?