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.

CC3120: MQTT stack integration and testing

Part Number: CC3120
Other Parts Discussed in Thread: CC3100

Hello Ti support team,

Let me explain the project background.

Host MCU: K61P256M150SF3RM

OS: MQX RTOS

Wi-Fi interface : CC3120 through SPI protocol.

IDE: Codewarrior ver10.6

I've already configured cc3120 Wi-fi chip to my host MCU which running on MQX RTOS. I could successfully run http webserver, telnet and FTP services etc,. Recently I got a new requirement that need to
broadcast information from host MCU when ever a new events occurred. We have selected MQTT protocol as a broadcast protocol. I've gone through Wi-fi MQTT wiki ()

and added source files from simplelink_sdk_wifi_plugin_4_20_00_10 SP release. I've modified POSIX related dependency from Ti RTOS and added MQX related APIs such as semaphore, task, mutex and message queue, etc. I try to execute mqtt_client_app example and could not succeed so far.

Note: I am still using CC3120 Gen1 stack due to some technical challenge and time constrain issues. I hope mqtt will support with Gen1 stack.

Here is my doubts,
1. Is there any porting document available for MQTT stack?
2. Will it work if I directly replaced RTOS components (POSIX dependencies)?
3. How can I test whether my code is running or not?
4. How can I test with a public mqtt broker which installed in my PC and connected to same network which CC3120 connected.

Basically I stuck in mqtt stack porting and testing part.

It would be great if someone could help me.

Thanks in advance.

BR,
Paul

  • Hello Support team,

    I've debugged my code and tired to track the exact function where it stuck,

    MQTTClient_connect(App_CB.mqttClientHandle); --> 

    /* Connect to the server */
    ret = MQTTClientCore_sendConnectMsg(clientCtx->cliHndl, MQTTClient_connectCfg.clean, MQTTClient_connectCfg.keepAliveTimeout);  -->

    rv = clCtxConnStateTryLocked(clCtx, ref, buf - ref, kaSecs, cleanSession, mqp); -->

     rv = netConnect(clCtx); -->

    clCtx->net = MQTTClientCore_netOps->open(client->nwconnOpts | MQTT_DEV_NETCONN_OPT_TCP,
    client->serverAddr, client->portNumber,&client->nwSecurity);

     


    my code is getting stuck inside MQTTClientCore_netOps->open()  function and never return. currently I am not using secure connection but will use if this issue solved.

    Note: I try to print arguments which I'm passing in MQTTClientCore_netOps->open()  function and here is the log.

    Please let me know. Thanks in advance.

    BR,

    Paul Jins

     

  • Hi Paul,

    To clarify your situation, are you using the CC3100 host driver with the CC3120? The CC3120 requires the use the host driver from the Wi-Fi plugin, and not that of the CC3100 SDK. Without the appropriate host driver, there might be unexpected behavior.

    That being said, I do not think the issue you are running into has to do with the host driver incompatibility, as it looks like it has to do with the porting of the MQTT library. The MQTT library distributed with the Wi-Fi plugin depends on the SlNetSock layer. Have you ported it as well?

    There is no available separate porting document for the SlNetSock layer or the MQTT library, as it's assumed that it would be ported along with the rest of the needed RTOS components for the CC3120 host driver. The simplest thing you could try would be replace all of the SlNetSock layer functionality with the appropriate low-level host driver calls. The platform integration between the CC3120 host driver and the MQTT library should be in the mqtt_net_func.c file. Attached is a reference from an older version of the MQTT library that did not use the SlNetSock layer that might be useful:

    /cfs-file/__key/communityserver-discussions-components-files/968/cc32xx_5F00_sl_5F00_net.c

    To test your code, I suggest you use the basic mqtt_client demo code provided in the SDK. While the examples are for TI platforms, you can take the basic functionality and MQTT library calls to the provided MQTT server/port to test functionality. Once you have the CC3120 connected to an MQTT server, you can use another client on your PC or phone to connect to the same server and exchange test data.

    Regards,

    Michael

  • Hello Michael,

    Thanks for your kind reply.

    To clarify your situation, are you using the CC3100 host driver with the CC3120?

    Ans: No. I am not using CC3100 SDK and took code from simplelink_sdk_wifi_plugin_4_20_00_10. But I am using simplelink Gen1 stack for Wi-Fi and Http webserver related services. 

    The MQTT library distributed with the Wi-Fi plugin depends on the SlNetSock layer. Have you ported it as well?

    Ans: I am not sure that I have done complete slNetSock layer porting. I have only added below code before Wi-Fi initialization.

    	case WLAN_START :
    	{
    #if 1		
    #define SLNET_IF_WIFI_PRIO          (5)
    		/* Initialize SlNetSock layer with CC31xx/CC32xx interface */
    		Status = SlNetIf_init(0);
    		if(Status == 0)
    		{
    			Status = SlNetSock_init(0);
    		}
    		if(Status == 0)
    		{
    			Status = SlNetUtil_init(0);
    		}
    		if(Status == 0)
    		{
    			Status = SlNetIf_add(SLNETIF_ID_1, "CC32xx",
    					(const SlNetIf_Config_t *)&SlNetIfConfigWifi,
    					SLNET_IF_WIFI_PRIO); 
    		}
    		if(0 != Status)
    		{
    			printf("Failed to initialize SlNetSock\n\r");
    		}
    #endif		
    

     The simplest thing you could try would be replace all of the SlNetSock layer functionality with the appropriate low-level host driver calls. The platform integration between the CC3120 host driver and the MQTT library should be in the mqtt_net_func.c file.

    Ans: I've modified mqtt_net_func.c file as suggested and able to solve issue that  code is getting stuck inside MQTTClientCore_netOps->open()  function then  never return.

    I am getting follow debug prints from MQTT connect..

    /************************************************/

    Success MQTT_IF_Init
    Subscribed to all topics successfully

    mqttAppThread creation success
    nwconnOpts = 9
    serverAddr =test.mosquitto.org
    portNumber= 1883
    Connected to server ....

    TCP send invoked for data with len 52

    Sent Data = :
    CONTEXT THREAD: RUNNING

    /*****************************************************/

    based on above logs I think now I am able to  connect to server  and send some data , but CONNACK is not coming from server or broker side.

    MQTT_IF_Connect() function is getting stuck 

    /* Wait for a CONNACK here */
    	MQTTClient_ackRxSignalWait(&clientCtx->ackSyncObj);

    Can you please help me to find out the  reason for why am I not getting CONNACK from server side? 

    About Broker:


    I have followed  this link to setup mosquitto mqtt broker in my windows PC.

    About Test setup:

    Both PC and CC3120 chip module  are connecting  to same Access point (router with internet access).  I could not use an another client in PC or Mobile and test my code due server CONNACK response issue.


    Can you please confirm me that my test procedure is correct or not?

    Thanks in advance.

    BR,

    Paul Jins

  • Hi Paul,

    Are you unable to get the CONNACK on both your CC3120 and your PC? In that case, the issue is most likely with the MQTT connection settings. This can be something with the clientID used, the topics you're subscribing to, or it could be that the MQTT server is not setup correctly to accept new MQTT connections. I am not familiar with the mosquitto server, so I can't tell specifically why your device is not able to connect to it.

    That being said, as part of a couple SimpleLink Academy modules there are some tested and known-good MQTT settings that you can use:

    https://dev.ti.com/tirex/explore/node?node=AHJ8YEDDQKAGTuUKvUm0ig__fc2e6sr__LATEST

    https://dev.ti.com/tirex/explore/node?node=AOU6wxqd7QK3nTF1q4CG3g__fc2e6sr__LATEST

    If you change your MQTT server config to one of the examples above, are you able to get a CONNACK?

    Regards,

    Michael

  • Hello Michael,

    Are you unable to get the CONNACK on both your CC3120 and your PC?

    Ans: I believe Yes, because I could connect to test.mosquitto.org broker when I run mqtt client (MQTTlens) app in my PC (I am able successfully subscribe and publish topic).

    The issue is most likely with the MQTT connection settings. This can be something with the clientID used, the topics you're subscribing to, or it could be that the MQTT server is not setup correctly to accept new MQTT connections. 

    Ans: I tired different clientID but same results. same topic is running in mqtt app (in PC). I tried few MQTT client in my PC and able to connect to the broker.

    I've done few excises but still CONNACK is not receiving.

    Excise-1. Try to ping google IP from CC3120:

    	_i16 Status;
    		SlNetAppPingReport_t report;
    		SlNetAppPingCommand_t pingCommand;
    		pingCommand.Ip = SL_IPV4_VAL(8,8,8,8); /* destination IP address is 10.1.1.200 */
    		pingCommand.PingSize = 150; /* size of ping, in bytes */
    		pingCommand.PingIntervalTime = 100; /* delay between pings, in milliseconds */
    		pingCommand.PingRequestTimeout = 1000; /* timeout for every ping in milliseconds */
    		pingCommand.TotalNumberOfAttempts = 20; /* number of ping requests */
    		pingCommand.Flags = 0; /* report only when finished */
    		Status = sl_NetAppPing( &pingCommand, SL_AF_INET, &report, NULL );
    		if (Status)
    		{
    			printf("\n ERROR!!! sl_NetAppPing Failed");
    		}
    		else
    		{
    			printf("\n Success!!! Ping worked");
    		}
    		//SlNetAppPingCommand_t pingCommand;
    		pingCommand.Ip = 0;
    		Status = sl_NetAppPing( &pingCommand, SL_AF_INET, &report, NULL ) ;
    		if (Status)
    			{
    				printf("\n ERROR!!! sl_NetAppPing Failed");
    			}
    			else
    			{
    				printf("\n Success!!! sl_NetAppPing worked");
    			}
    		
    		printf("\n report.PacketsReceived =%d \t report.PacketsSent=%d  ",report.PacketsReceived,report.PacketsSent);

    Result :I could successfully to ping google

    same experiment I tried for broker IP 

    	pingCommand.Ip = SL_IPV4_VAL(5,196,95,208); /* destination IP address is 10.1.1.200 */

    Result: I could successfully to ping broker ip

    Excise-2. I've tried with different QoS values, i.e

    //#define MQTT_WILL_QOS               MQTT_QOS_2 
    #define MQTT_WILL_QOS               MQTT_QOS_1

    Result: Could not receive CONNACK response

    Excise-3. Tried with different AP

    Result: Could not getCONNACK response.

    Excise-4:  Try to disable below SlNet related code before initializing the Wi-Fi STA.

    #if 1		
    #define SLNET_IF_WIFI_PRIO          (5)
    		/* Initialize SlNetSock layer with CC31xx/CC32xx interface */
    		Status = SlNetIf_init(0);
    		if(Status == 0)
    		{
    			Status = SlNetSock_init(0);
    		}
    		if(Status == 0)
    		{
    			Status = SlNetUtil_init(0);
    		}
    		if(Status == 0)
    		{
    			Status = SlNetIf_add(SLNETIF_ID_1, "CC32xx",
    					(const SlNetIf_Config_t *)&SlNetIfConfigWifi,
    					SLNET_IF_WIFI_PRIO); 
    		}
    		if(0 != Status)
    		{
    			printf("Failed to initialize SlNetSock\n\r");
    		}
    #endif	

    Result: Could not get CONNACK response.

    Doubt: Do I need to replace these SlNet functions with sl_ functions? I could not find any alternative functions from SL_

    Excise-5: Previously I was disabled complete function body of MQTTNet_rtcSecs() but now I replaced with clock_gettime() with MQX GetTime() function

    Result: Could not get CONNACK response.

    Even I have tried with different public brokers ( )but same result.

    Can you please tell how can I receive CONNACK?

    BR,

    Paul

     

  • Hello Again,

    I've tried  below brokers as well but observed same result.

    But when I used 

    #define MQTT_CONNECTION_ADDRESS       "mqtt.eclipse.org"

    I could not make any connection and got below error

    /*********************************************************/

    mMQTTContext.moduleState initialised !!!!
    Success MQTT_IF_Init
    Subscribed to all topics successfully

    mqttAppThread creation success
    MQTTClient_connect


    nwconnOpts = 9
    serverAddr =mqtt.eclipse.org
    portNumber= 1883


    ERROR: sl_Connect failed -111.
    ERROR: Could not establish connection to server.

    ERROR: Closing the socket.

    connect failed: -1

    waiting for CONNACK

    /***********************************************/

    and PC mqtt client also failed to connect to mqtt.eclipse.org

    When I have modified  address to 

    #define MQTT_CONNECTION_ADDRESS       "mqtt.eclipseprojects.io"

    Then at least my PC mqtt client is working but CC3120 is not receiving any CONNACK

    Please let me know how can I solve this CONNACK issue.

    BR,

    Paul Jins

  • Hello Michael,

    Do you have any update? Please let me know.

    I am awaiting your reply.

    BR,

    Paul

  • Hi Paul,

    The error -111 you're getting from eclipse.org indicates that the connection was refused. Maybe the server details have changed since we last updated the SimpleLink Academy module.

    As for why you're not getting CONNACKs with the mosquitto server, there might be some issue with the MQTT library porting. Do you have access to a Wi-Fi air sniffer? I am curious as to what data is actually sent by the CC3120 during the MQTT connection. You can also put a breakpoint in debug mode in the sl_Send() command to see the raw data being sent on the MQTT socket. If you do the same on your PC and compare the connection sequence, what differences do you notice?

    Regards,

    Michael

  • Hello Michael,

    About raw data being sent on the socket, please find debug prints.

    /**************************************************/

    MQTTNet_commOpen called
    CONTEXT THREAD: RUNNING

    createSocket called

    Connected to server ....

    MQTTNet_tcpSend called

    TCP send invoked for data with len 63

    Sent Data = : 10 3d 00 06 4d 51 49 73 64 70 03 0e 00 19 00 0c
    35 30 66 31 34 61 65 65 64 64 39 32 00 11 63 63
    33 32 78 78 5f 77 69 6c 6c 5f 74 6f 70 69 63 00
    0e 77 69 6c 6c 5f 6d 73 67 5f 77 6f 72 6b 73

    sl_Send =63

    /********************************************************/

    BR,

    Paul

  • Hi Paul,

    If you check what your PC sends to the same broker using a packet capture tool such as Wireshark, what differences do you see between the CC3120 connection packet and the PC connection packet?

    I unfortunately do not know the exact raw output expected to connect to mosquitto, but comparing the two packets will show you what might be wrong with the CC3120 connection attempt, and lead you to the cause of the issue.

    Regards,

    Michael