MqttClient folder with Mosquitto?

Hi guys!
I want to enstabilish a MQTT communication between:

  • Mosquitto MQTT for the broker side
  • MqttClient APP for the client side
    I read that alternatively I can use paho for the client side, but I didn’t understand how.

I compiled the MqttClient App that is in the mangOH project:

I included it in the main green.sdef:

So I updated it on my mangOH and the app is wrightly started:
image

I obtain the following log, I can see an error:

Can you say me if I have to do other things. Can you give me same exmamples to implement on my mangOH green in order to understand if the mqtt commununication works well?

I installed yesterday mosquitto MQTT:

Successful log should be like this

You can see here on how to run mqtt

Thank you for the quickly answer, but I don’t have paho.mqtt.c in 3rdParty folder. Have I to download it? I thought I had to use the application in your mangOH layer …

Seems to be here

okay, I found it, it was in a different path. I can to run it, thank you

When I start app start start mqttPublisher and app start mqttSubscriber of your example I obtain this log…

you need to debug why there is socket error…
e.g. capturing wireshark log, adding debug message , etc

what are these commands and where have I to write them?
image

okay I compiled this example, I launched
image

The log:

But:

What am I wrong?

it asked you to type -help.
Actually you have the source code, you should able to add debug message for debugging.
Also mosquitto is 3rd application, I have no knowledge on it.

I have a connection error…

I think it is a good chance for you to debug and adding debug message on testsubscriber.c.

Enjoy!

okay
you say in the Component init part? But then is the same thing of helloWorld example?
#include “interfaces.h”

//--------------------------------------------------------------------------------------------------
/**

  • Whether connection to MQTT server is secured
    */
    //--------------------------------------------------------------------------------------------------
    #define MQTT_SERVER_USE_SECURED_CONNECTION 0

//--------------------------------------------------------------------------------------------------
/**

  • Device IMEI, used as a unique device identifier
    */
    //--------------------------------------------------------------------------------------------------
    char DeviceIMEI[LE_INFO_IMEI_MAX_BYTES];

//--------------------------------------------------------------------------------------------------
/**

  • MQTT session reference
    */
    //--------------------------------------------------------------------------------------------------
    mqtt_SessionRef_t MQTTSession;

//--------------------------------------------------------------------------------------------------
/**

  • Call-back function called on lost connection
    /
    //--------------------------------------------------------------------------------------------------
    void OnConnectionLost
    (
    void
    context
    )
    {
    LE_ERROR(“Connection lost!”);
    }

//--------------------------------------------------------------------------------------------------
/**

  • Call-back function called on arrived message
    /
    //--------------------------------------------------------------------------------------------------
    void OnMessageArrived
    (
    const char
    topic,
    const uint8_t* payload,
    size_t payloadLen,
    void* context
    )
    {
    char payloadStr[payloadLen + 1];
    memcpy(payloadStr, payload, payloadLen);
    payloadStr[payloadLen] = ‘\0’;
    LE_INFO(“Received message! topic: “%s”, payload: “%s””, topic, payloadStr);
    }

COMPONENT_INIT
{
// server is running on the Linux workstation connected to the target
#if MQTT_SERVER_USE_SECURED_CONNECTION
const char mqttBrokerURI = “ssl://192.168.2.3:8883”;
const uint8_t mqttPassword = {‘S’, ‘W’, ‘I’};
#else
const char mqttBrokerURI = “tcp://192.168.2.3:1883”;
#endif
LE_ASSERT_OK(le_info_GetImei(DeviceIMEI, NUM_ARRAY_MEMBERS(DeviceIMEI)));
char clientId[32];
snprintf(clientId, sizeof(clientId), “%s-sub”, DeviceIMEI);
LE_ASSERT_OK(mqtt_CreateSession(mqttBrokerURI, clientId, &MQTTSession));

const uint16_t keepAliveInSeconds = 60;
const bool cleanSession = true;
const char* username = DeviceIMEI;
const uint16_t connectTimeout = 20;
const uint16_t retryInterval = 10;
mqtt_SetConnectOptions(
    MQTTSession,
    keepAliveInSeconds,
    cleanSession,
    username,

#if MQTT_SERVER_USE_SECURED_CONNECTION
mqttPassword,
NUM_ARRAY_MEMBERS(mqttPassword),
#else
NULL,
0,
#endif
connectTimeout,
retryInterval);

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

int rc = mqtt_Connect(MQTTSession);
if (rc != LE_OK)
{
    LE_ERROR("Connection failed! error %d", rc);
}
else
{
    char subscribeTopic[64];
    snprintf(subscribeTopic, sizeof(subscribeTopic), "%s/messages/json", DeviceIMEI);
    LE_FATAL_IF(
        mqtt_Subscribe(MQTTSession, subscribeTopic, MQTT_QOS0_TRANSMIT_ONCE) != LE_OK,
        "failed to subscribe to %s",
        subscribeTopic);
    LE_INFO("Subscribed to topic (%s)", subscribeTopic);

    snprintf(subscribeTopic, sizeof(subscribeTopic), "%s/errors", DeviceIMEI);
    LE_FATAL_IF(
        mqtt_Subscribe(MQTTSession, subscribeTopic, MQTT_QOS0_TRANSMIT_ONCE) != LE_OK,
        "failed to subscribe to %s",
        subscribeTopic);
    LE_INFO("Subscribed to topic (%s)", subscribeTopic);
}

}

seems mqtt_Connect() is returning the error, probably you need to debug \3rdParty\paho.mqtt.c\src\MQTTClient.c

Good luck!

I don’t know how to modify this file…

You can use gedit or vi tool to add debug message

I have a connection error -6 but don’t understand why

No one can help me? I have to make this example start… 3rd party does not work

@jyijyi I run mqttClient folder in your mangOH green 2-7-19 and it seems to commect:


What does it mean? Can I use it to send/receive messages?

I never use that application.
BTW, you have all the source code, you should be able to debug by yourself.