This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220SF-LAUNCHXL: How to run two mqtt client

Part Number: CC3220SF-LAUNCHXL
Other Parts Discussed in Thread: CC3220SF

We are going to use two mqtt client parallel.

1) Normal TLS based MQTT

2)Watson IoT

if i run two client parallel one(mqtt)  MQTTClient_create return success and another one(watson iot) return error why return error ?

Normal MQTT :

    MqttClient_params.clientId = ClientId;
    MqttClient_params.connParams = &Mqtt_ClientCtx;
    MqttClient_params.mqttMode31 = MQTT_3_1;
    MqttClient_params.blockingSend = true;

    /* Initialize MQTT client lib                   */
    WiFi_Connect.mqttClientHandle = MQTTClient_create(MqttClientCallback,
                                                       &MqttClient_params);
    if (WiFi_Connect.mqttClientHandle == NULL)
    {
        UART_PRINT("[MQTT Thread] Error - MQTT client handle is null \r\n");
        return -1;
    }

Watson IoT : 

IBMClient_params.clientId = IBM_ClientId;
    IBMClient_params.connParams = &IBM_ClientCtx;
    IBMClient_params.mqttMode31 = MQTT_3_1;
    IBMClient_params.blockingSend = true;

    /* Initialize Watson_IoI Client Lib */
    WiFi_Connect.IBM_ClientHandle = MQTTClient_create(IBMClientCallback,
                                                      &IBMClient_params);
    if (WiFi_Connect.IBM_ClientHandle == NULL)
    {
        /* Lib initialization failed */
        UART_PRINT("[IBM Thread] Error - MQTT client handle is null \r\n");
        return -1;
    }

I having doubt on this one also 

MQTTClient_run((MQTTClient_Handle) pvParameters);

Questions :

  1. Why i am getting error on another one MQTTClient_create call ?
  2. one mqtt (SLNETIF_ID_2) another one (SLNETIF_ID_3) this is correct ?
  3. MQTTClient_run can i pass handle directly why example code passing pvParameters  instant of handle ?
  4. Maximum how many mqtt client we can run parallel ?

Please help me to solve this issue.

Thank You

  Vasu

  • Hi Vasu,

    It looks like there is a check in the MQTT library in the MQTTClient_create() call that prevents that function from being called more than once without the library being uninitialized. This means that you cannot connect to two different servers at the same time. I will look more closely at this to see if this is intended behavior or if there is a method/workaround to have multiple connections at the same time.

    Regards,
    Michael
  • Hi Michael,

    I checked Mqtt_Client library two server connection not allowed at the same time only single mqtt client connection possible.

    cc3220sf supports 16 tcp connection and 6 secure connection possible.

    Questions:

    1. Already one Mqtt_client(IBM IoT) is running if i want one more means can i modify original source code of mqtt_client library based on my requirement this is possible ?
    2. Otherwise i need write own mqtt_client function using tcp sockets ? 
    3. Any other solution ?

    Thank You

      Vasu

  • Hi Vasu,

    Modifying the MQTTClient library might be possible, but from a cursory look at the code it will most likely be a tedious task. Not only is there the check in MQTTClient_create(), but there are other sections of code that bake in the one-connection-only assumption.

    You would probably be better off finding another MQTT library that does allow for concurrent connections if you must connect to more than one server at a time. There should be third-party open source libraries that you can use online.

    Regards,
    Michael
  • Hi Michael,

    Thank you for you suggestion.