mqttClient Service Connect error?

No idea then…

You might try other mqtt server

On the other hand the socket error is just a warning (seeing the code). Instead, the error is the following:

Didn’t LE_FAULT is -6

I’m trying to analyze this error…thanks for the advice

Then that means it is not MQTTCLIENT_NULL_PARAMETER

 switch (connectResult)
        case SOCKET_ERROR:
            LE_WARN("Socket error");
            result = LE_FAULT;

            result = LE_BAD_PARAMETER;

I’m so sorry for bothering you. In this post:

Legato Forum – 19 Feb 21

How to use component 3rdParty paho.mqtt.c

using the real ip I got the error return -6 Feb 19 14:56:41 fx30s Legato: INFO | testPublisher[4655]/testPublisher T=main | testPublisher.c _testPublisher_COMPONENT_INIT() 111 | mqttBrokerURI tcp:// Feb 19 14:56:41…

the guy has my same problem:

and the solution seems to be:

I’m wondering if I could be in the same case

you might give a try on that.

You might also try other mqtt server

Hi @jyijyi as always I’m so sorry for bothering you. Unfortunately the supervisors necessarily want me to use mosquitto. I am desperate. In your opinion, could a COMPONENT_INIT calling functions like this be correct? I do not know what to do. I can’t find any errors, debugging the MQTT_Connect function.

const char mqttBrokerURI = “ssl://”;
//const char mqttBrokerURI = “ssl://”;
const uint8_t mqttPassword = {‘S’, ‘W’, ‘I’};
const char mqttBrokerURI = “tcp://”;
//const char mqttBrokerURI = “tcp://”;
//const char mqttBrokerURI = “tcp://”;
//const char mqttBrokerURI = “tcp://”;
//const char mqttBrokerURI = “tcp://”;
//const uint8_t mqttPassword = {‘S’, ‘W’, ‘I’};
//char clientId[32] = “kineton”;
char clientId[32];
snprintf(clientId, sizeof(clientId), “%s-pub”, DeviceIMEI);
//Create memory pools*/
MQTTSessionPoolRef = le_mem_CreatePool(“MQTT session pool”, sizeof(mqtt_Session));
le_mem_ExpandPool(MQTTSessionPoolRef, MQTT_SESSION_MAX);
le_mem_SetDestructor(MQTTSessionPoolRef, mqttSessionDestructor);

UsernamePoolRef = le_mem_CreatePool("MQTT username pool", MQTT_MAX_USERNAME_LENGTH);
PasswordPoolRef = le_mem_CreatePool("MQTT password pool", MQTT_MAX_PASSWORD_LENGTH);
MessagePoolRef = le_mem_CreatePool("MQTT message pool", sizeof(mqtt_Message));
TopicPoolRef = le_mem_CreatePool("MQTT topic pool", MQTT_MAX_TOPIC_LENGTH);
PayloadPoolRef = le_mem_CreatePool("MQTT payload pool", MQTT_MAX_PAYLOAD_LENGTH);

// MessageHandlerRefMap is created with size (MQTT_SESSION_MAX * 2) since each MQTT session
// may have 2 handlers, i.e. 1 message arrived handler and 1 connection lost handler
SessionRefMap = le_ref_CreateMap("MQTT sessions", MQTT_SESSION_MAX);
MessageHandlerRefMap = le_ref_CreateMap("MQTT message handlers", MQTT_SESSION_MAX * 2);

ReceiveThreadEventId = le_event_CreateId(
    "MqttClient receive notification", sizeof(mqtt_Message*));
    "MqttClient receive notification", ReceiveThreadEventId, MessageReceivedEventHandler);

ConnectionLostThreadEventId = le_event_CreateId(
    "MqttClient connection lost notification", sizeof(mqtt_Message*));
    "MqttClient connection lost notification",

res = mqtt_CreateSession(mqttBrokerURI, clientId, &MQTTSession);
  if (res != LE_OK){
      LE_INFO ("tutto male :( ");
  else {
      LE_INFO("tutto ok");

//inizia il mio codice

const uint16_t keepAliveInSeconds = 30;
const bool cleanSession = true;
const char* username = DeviceIMEI;
//const char* username = “kienton”;
const uint16_t connectTimeout = 20;
const uint16_t retryInterval = 10;

mqtt_AddConnectionLostHandler(MQTTSession, &OnConnectionLost, NULL);
mqtt_AddMessageArrivedHandler(MQTTSession, &OnMessageArrived, NULL);

sleep (5);
sleep (5);

/*res = mqtt_Connect(MQTTSession);
if (res == LE_OK)
    LE_ERROR("Connection failed! error %d", res);
    LE_INFO("Connected to server '%s'", mqttBrokerURI);
//finisce il mio codice


LE_FATAL_IF(mqtt_Connect(MQTTSession) != LE_OK, “Connection failed”);

le_timer_Ref_t timer = le_timer_Create("MQTT Publish");
LE_ASSERT_OK(le_timer_SetHandler(timer, &publishTimerHandler));
LE_ASSERT_OK(le_timer_SetMsInterval(timer, 5000));
LE_ASSERT_OK(le_timer_SetRepeat(timer, 0));
LE_INFO("Publish timer started");
le_msg_AddServiceCloseHandler(mqtt_GetServiceRef(), DestroyAllOwnedSessions, NULL);

MQTTClient_init_options initOptions = MQTTClient_init_options_initializer;
initOptions.do_openssl_init = 1;


I used a timer in order to recall the function until there isn’t a connection to the server.
I configured the broker in this way:

As you can see, i’m trying also with AirVantage adress, but the error is the same

You can try other mqtt application if yours does not work

okay thank you. But is GCould free? In my company they don’t want to use it. Can I use it for free with a personal account?


No idea, you need to ask google

I can’t use it, I should pay. I can only use mosquitto :disappointed_relieved:

I would advise not trying to use mosquitto on the VM. We have this same setup functional on a desktop running linux(ubuntu 18.04) natively. There is some routing issue where traffic won’t traverse to a VM. Its too complicated to troubleshoot. You can also run mosquitto server on a cheap raspberry pi.

1 Like

I think that another parameter that comes me to have error is the url tcp or ssl.
If I put tcp:// or tcp:// I obtain

If I put local adress such as I obtain only socket error.
Can someone explain to me how to connect to a broker URL (I will be happy also with a local URL)

That is another issue that the program cannot resolver the ip by dns server

The root of my problems could be the fact that I’m using Ubuntu VM on virtual box and so a local adress is not simple to give?

You might try with rea pc then

In our case, we got an error when trying to connect to mqtt server URL when it was set to non-secured (TCP). When connecting to server over SSL (over port 8883), the issue resolved itself. For some reason, DNS resolution doesn’t work and we are forced to use the ip address of the server when SSL isn’t enabled.

Following this page(and all the associated linked pages) on the internet was enough to get us functional setup: Using The Mosquitto_pub and Mosquitto_sub MQTT Client Tools- Examples

I tried, but unfortunately this is not the solution either. However, I noticed another thing. I have Mosquitto server installed on windows of another PC and from my Ubuntu I can ping (seeing the connection attempt on the other side):

But if I repeat the same operation from my mangOH nothing happens:


It’s a normal thing? Should my mangOH be configured on a door? Because at this point it’s really not clear to me what I’m wrong
I want to clarify that my mangOH is on Internet (also with WiFi and Data) so that I can ping google