@@ -27,8 +27,8 @@ MqttProtocol::~MqttProtocol() {
2727 vEventGroupDelete (event_group_handle_);
2828}
2929
30- void MqttProtocol::Start () {
31- StartMqttClient (false );
30+ bool MqttProtocol::Start () {
31+ return StartMqttClient (false );
3232}
3333
3434bool MqttProtocol::StartMqttClient (bool report_error) {
@@ -90,7 +90,16 @@ bool MqttProtocol::StartMqttClient(bool report_error) {
9090 });
9191
9292 ESP_LOGI (TAG, " Connecting to endpoint %s" , endpoint_.c_str ());
93- if (!mqtt_->Connect (endpoint_, 8883 , client_id_, username_, password_)) {
93+ std::string broker_address;
94+ int broker_port = 8883 ;
95+ size_t pos = endpoint_.find (' :' );
96+ if (pos != std::string::npos) {
97+ broker_address = endpoint_.substr (0 , pos);
98+ broker_port = std::stoi (endpoint_.substr (pos + 1 ));
99+ } else {
100+ broker_address = endpoint_;
101+ }
102+ if (!mqtt_->Connect (broker_address, broker_port, client_id_, username_, password_)) {
94103 ESP_LOGE (TAG, " Failed to connect to endpoint" );
95104 SetError (Lang::Strings::SERVER_NOT_CONNECTED);
96105 return false ;
0 commit comments