mqttClient Service Connect error?

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

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

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

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

To know why there is error -6???

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;

}

Ok, then you know where to debug

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…

What is the failure cause here

case MQTTCLIENT_NULL_PARAMETER:
case MQTTCLIENT_BAD_STRUCTURE:
case MQTTCLIENT_BAD_UTF8_STRING

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

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?

I’m trying to debug and study this function, but the error is always the same :frowning: 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:

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:

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 :frowning:strong text

then why did MQTTClient_connectAll() returning wrongly after your study?

Why do you say MQTTClient_connectAll()? Do you refer to mqtt_Connect, right?
maqqClientServicee.txt (36.7 KB) Here is the code I’m working on…

Inside MQTTClient_connect(), it is calling MQTTClient_connectAll()

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

Do you see the source code of MQTTClient_connect ?

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

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?

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?

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?

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

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

But mosquitto is not in local?!