Tracing the MQTT client for C

Set the environment variable MQTT_C_CLIENT_TRACE to trace an MQTT client C app

Before you begin

MQTT client for C trace is available for both the pre-built Windows and Linux® MQTT client for C libraries, and for the iOS libraries you build yourself.

About this task

Set the environment variable MQTT_C_CLIENT_TRACE to a path to a file that is to contain the trace output. Trace output is written to the file.

Procedure

Set MQTT_C_CLIENT_TRACE=mqttcclient.log before running your MQTT client C app.
  1. For example, modify the sample script in Getting started with the MQTT client for C:
    @echo off
    setlocal
    set MQTT_C_CLIENT_TRACE=mqttcclient.log
    call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
    cl  /nologo /D "WIN32" /I "..\include" "MQTTV3Sample.c" /link /nologo ..\windows_ia32\mqttv3c.lib
    set path=%path%;..\windows_ia32;
    start "MQTT Subscriber" MQTTV3Sample -a subscribe -b localhost -p 1883
    @rem Sleep for 2 seconds
    ping -n 2 127.0.0.1 > NUL 2>&1
    MQTTV3Sample -b localhost -p 1883
    pause
    endlocal
  2. Run the script from the %sdkroot%/sdk/client/c/samples directory.

Results

The trace output files starts with the following lines:
=========================================================
                   Trace Output
=========================================================
19700101 000000.000 (8084)  (1)> Socket_outInitialize:113
19700101 000000.000 (8084)   (2)> SocketBuffer_initialize:81
19700101 000000.000 (8084)   (2)< SocketBuffer_initialize:85
19700101 000000.000 (8084)  (1)< Socket_outInitialize:129
19700101 000000.000 (8084)  (1)> Thread_create_sem:189
19700101 000000.000 (8084)  (1)< Thread_create_sem:222 (0)
19700101 000000.000 (8084)  (1)> Thread_create_sem:189
19700101 000000.000 (8084)  (1)< Thread_create_sem:222 (0)
19700101 000000.000 (8084)  (1)> Thread_create_sem:189
19700101 000000.000 (8084)  (1)< Thread_create_sem:222 (0)
19700101 000000.000 (8084)  (1)> Thread_create_sem:189
19700101 000000.000 (8084)  (1)< Thread_create_sem:222 (0)
19700101 000000.000 (8084)  (1)> MQTTPersistence_create:43
19700101 000000.000 (8084)  (1)< MQTTPersistence_create:89 (0)
19700101 000000.000 (8084)  (1)> MQTTPersistence_initialize:104
19700101 000000.000 (8084)  (1)< MQTTPersistence_initialize:112 (0)
19700101 000000.000 (8084) (0)< MQTTClient_create:267 (0)
19700101 000000.000 (8084) (0)> MQTTClient_connect:701
19700101 000000.000 Connecting to serverURI localhost:1883
20130201 125912.234 (8084)  (1)> MQTTProtocol_connect:93
20130201 125912.234 (8084)   (2)> MQTTProtocol_addressPort:43
20130201 125912.234 (8084)   (2)< MQTTProtocol_addressPort:68
20130201 125912.234 (8084)   (2)> Socket_new:594
20130201 125912.234 New socket 1860 for localhost, port 1883