# mqttClient Service Connect error?

**URL:** <https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093>\
**Category:** Uncategorized\
**Created:** [April 28, 2021, 10:01am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093 "2021-04-28T10:01:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gavinoimparato1](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gavinoimparato1](https://mangoh.discourse.group/u/gavinoimparato1)\
**Post date:** [April 28, 2021, 10:01am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/1 "2021-04-28T10:01:12Z")

</div>

Hi! I’m developing a SW to connect with mosquitto broker. I started from the source code in apps/platformservices of Legato environment.  
I can right build the project, create the session, but I have problem when I have to connect to the broker:  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/2X/2/2399ecdcd116a8bb32206b899de6ab1006b75391.png)

I’m trying to connect without user and password (I’m beginning!) and this is the result:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/2X/0/0903e55947155f2ddb6f93c4ffe905d1494cfe78.png)

Obviously I connected my mangOH green to internet thought both WiFi and Sim.  
Which could be the problem?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 28, 2021, 11:02am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/2 "2021-04-28T11:02:10Z")

</div>

Did you add debug message in \3rdParty\paho.mqtt.c\src\MQTTClient.c

To know why there is error -6???

---

<div class="post-metadata">

**Author:** ![gavinoimparato1](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gavinoimparato1](https://mangoh.discourse.group/u/gavinoimparato1)\
**Post date:** [April 28, 2021, 11:07am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/3 "2021-04-28T11:07:12Z")

</div>

yes, the problem is in the following function:  
le\_result\_t mqtt\_Connect  
(  
mqtt\_SessionRef\_t sessionRef ///\< [IN] Session to connect  
)  
{  
mqtt\_Session\* s = le\_ref\_Lookup(SessionRefMap, sessionRef);  
if (s == NULL)  
{  
LE\_KILL\_CLIENT(“Session doesn’t exist”);  
return LE\_FAULT;  
}  
if (s-\>clientSession != mqtt\_GetClientSessionRef())  
{  
LE\_KILL\_CLIENT(“Session doesn’t belong to this client”);  
return LE\_FAULT;  
}

```
const int connectResult = MQTTClient_connect(s->client, &s->connectOptions);
le_result_t result;
switch (connectResult)
{
    **case SOCKET_ERROR:**

```

\*\* LE\_WARN(“Socket error”);\*\*  
\*\* result = LE\_FAULT;\*\*  
\*\* break;\*\*

```
    case MQTTCLIENT_NULL_PARAMETER:
    case MQTTCLIENT_BAD_STRUCTURE:
    case MQTTCLIENT_BAD_UTF8_STRING:
        result = LE_BAD_PARAMETER;
        break;

    case MQTTCLIENT_SUCCESS:
        result = LE_OK;
        break;

     default:
        LE_WARN("Paho connect returned (%d)", connectResult);
        result = LE_FAULT;
        break;
 }

return result;

```

}

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 28, 2021, 11:08am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/4 "2021-04-28T11:08:06Z")

</div>

Ok, then you know where to debug

---

<div class="post-metadata">

**Author:** ![gavinoimparato1](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gavinoimparato1](https://mangoh.discourse.group/u/gavinoimparato1)\
**Post date:** [April 28, 2021, 11:12am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/5 "2021-04-28T11:12:23Z")

</div>

Where do you think the problem could be? In the connection? In the fact that I didn’t set a password? I don’t understand why this socket error…

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 28, 2021, 11:20am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/6 "2021-04-28T11:20:00Z")

</div>

What is the failure cause here

case MQTTCLIENT\_NULL\_PARAMETER:  
case MQTTCLIENT\_BAD\_STRUCTURE:  
case MQTTCLIENT\_BAD\_UTF8\_STRING

---

<div class="post-metadata">

**Author:** ![gavinoimparato1](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gavinoimparato1](https://mangoh.discourse.group/u/gavinoimparato1)\
**Post date:** [April 28, 2021, 12:09pm UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/7 "2021-04-28T12:09:18Z")

</div>

I think that in my code the cases you mentioned ar not a problem ( or at least not yet at this point): I have a socket error problem:  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/2X/7/79b970f516a4a106a853ec38be39d20b1aaeec14.png)

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 28, 2021, 3:43pm UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/12 "2021-04-28T15:43:23Z")

</div>

you can debug in MQTTClient\_connectAll() and see why it returns SOCKET\_ERROR

BTW, have you tried unsandboxed the application in .adef and see if it works?

---

<div class="post-metadata">

**Author:** ![gavinoimparato1](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gavinoimparato1](https://mangoh.discourse.group/u/gavinoimparato1)\
**Post date:** [April 28, 2021, 8:38pm UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/13 "2021-04-28T20:38:15Z")

</div>

I’m trying to debug and study this function, but the error is always the same ☹ I don’t know if it is a connection error… . Anyway I also unsandboxed the application and also in this case the result is the same:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/2X/7/7b57cb2615d8f2d10eb9f3d79ec1d72f7e12c033.png)

I can ping 8.8.8.8 so it is not a connection error. I installed mosquitto server on my VM with the command line ctrl **sudo snap install mosquitto** and I can publish and subscribe a message in **local** host (opening two terminals)

On the other side, if I put in the code the **AirVantage** broker adress, I see:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/2X/1/18ff5441673d79eaca69e8fdacbb8f10e9a5c859.png)

So I don’t think I got anything wrong in the code, but at the same time I can’t even say why it doesn’t work ☹strong text

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 29, 2021, 12:48am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/14 "2021-04-29T00:48:31Z")

</div>

then why did MQTTClient\_connectAll() returning wrongly after your study?

---

<div class="post-metadata">

**Author:** ![gavinoimparato1](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gavinoimparato1](https://mangoh.discourse.group/u/gavinoimparato1)\
**Post date:** [April 29, 2021, 6:06am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/15 "2021-04-29T06:06:49Z")

</div>

Why do you say MQTTClient\_connectAll()? Do you refer to **mqtt\_Connect** , right?  
[maqqClientServicee.txt](https://mangoh.discourse.group/uploads/short-url/xGE8aoSIg13heRKMRsg8MEGqfOq.txt) (36.7 KB) Here is the code I’m working on…

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 29, 2021, 6:10am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/16 "2021-04-29T06:10:26Z")

</div>

Inside MQTTClient\_connect(), it is calling MQTTClient\_connectAll()

---

<div class="post-metadata">

**Author:** ![gavinoimparato1](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gavinoimparato1](https://mangoh.discourse.group/u/gavinoimparato1)\
**Post date:** [April 29, 2021, 7:15am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/17 "2021-04-29T07:15:17Z")

</div>

Sorry but I can’t see this function…  
EDIT oh maybe do you refer to **MQTTClient\_connec** t in **const int connectResult = MQTTClient\_connect(s-\>client, &s-\>connectOptions);**  
I don’t see problems in this function…

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 29, 2021, 8:07am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/18 "2021-04-29T08:07:12Z")

</div>

Do you see the source code of **MQTTClient\_connect**?

---

<div class="post-metadata">

**Author:** ![gavinoimparato1](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gavinoimparato1](https://mangoh.discourse.group/u/gavinoimparato1)\
**Post date:** [April 29, 2021, 9:14am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/19 "2021-04-29T09:14:03Z")

</div>

sorry @jyijyi since I think that it is a permission problem and not a SW problem. For now this is my **COMPONENT\_INIT**

 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/2X/2/2b4b1917c57a81e438495bbc3fbdf84f723bc6a4.png) and i don’t see problems in MQTTClient\_connect, also because I did not modify the function and it works well to other users that I saw on the forum.  
Is there a way to see on the terminal if my board can “talk” with mqtt mosquitto broker at the adress tcp://192.168.2.3:1883?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 29, 2021, 9:19am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/20 "2021-04-29T09:19:15Z")

</div>

What do you mean by “it is a permission problem”?  
Why suddenly it works?  
BTW, you can capture wireshark log in ubuntu and see if there is incoming packet on port 1883?

---

<div class="post-metadata">

**Author:** ![gavinoimparato1](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gavinoimparato1](https://mangoh.discourse.group/u/gavinoimparato1)\
**Post date:** [April 29, 2021, 9:21am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/21 "2021-04-29T09:21:20Z")

</div>

I meant that maybe there could be communication problems with the 1883 gate … I can’t give myself any other explanations. Do you happen to know how to see active ports on Ubuntu (how to open wireshark log for this port)? I simply installed Mosquitto and activated the session locally: might it not be enough?

---

<div class="post-metadata">

**Author:** ![gavinoimparato1](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gavinoimparato1](https://mangoh.discourse.group/u/gavinoimparato1)\
**Post date:** [April 29, 2021, 9:29am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/22 "2021-04-29T09:29:14Z")

</div>

On wireshark I see only this…so mosquitto is not running in realty?

 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/2X/d/d66d951af60e8f27abac57785bf597c8f3bd7f69.png)

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 29, 2021, 9:30am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/23 "2021-04-29T09:30:44Z")

</div>

i don’t know, you should capture the wireshark from USB ECM interface.

---

<div class="post-metadata">

**Author:** ![gavinoimparato1](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gavinoimparato1](https://mangoh.discourse.group/u/gavinoimparato1)\
**Post date:** [April 29, 2021, 9:31am UTC](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093/24 "2021-04-29T09:31:22Z")

</div>

But mosquitto is not in local?!

[Next page](https://mangoh.discourse.group/t/mqttclient-service-connect-error/9093.md?page=2)
