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.

关于例程MQTT Server

Other Parts Discussed in Thread: CC3200

在例程MQTT Server中,是使用其中一块3200作为本地的服务器,其他的CC3200作为本地客户端。本地客户端可以通过本地服务器将数据上传到远端的服务器,同样也可以下载。我现在知道作为本地服务器的那块CC3200同时兼顾着和远端服务器通信和管理本地MQTT网络的功能,也可以使用它和远端服务器进行通信了。但是我现在不清楚怎么样才能将其他的板子和这块作为本地服务器的CC3200通过MQTT协议进行连接,然后进行本地通信。文档里面是这么说的,

8. Connect one or multiple local MQTT client to the MQTT server, it can be a PC or another CC3200 device. A
local functional MQTT network can now be used to communicate between multiple local clients.

这个local functional MQTT network应该怎么搭建起来呢?是需要本地服务器的那块CC3200的地址和端口吗?为什么在代码里面没有找到有对应的地方。麻烦TI工程师能指点一下。

  • 你可以参考一下API sl_ExtLib_MqttServerInit的里面参数的设置就知道了。

  • sl_ExtLib_MqttServerInit( &Mqtt_Server,&server_callbacks); 这个API里面有两个参数,第一个是和参数配置有关的。

    在代码里面,第一个参数的结构体是下面这样的

    SlMqttServerCfg_t Mqtt_Server={
    {
    0,
    NULL,
    PORT_NUMBER,
    0,
    0,
    0,
    NULL
    },
    LOOPBACK_PORT,
    TASK_PRIORITY,
    RCV_TIMEOUT,
    true,
    (long(*)(const char *, ...))UART_PRINT
    };

    其中,我找到的定义如下

    typedef struct
    {
    SlMqttServerParams_t server_info; /**< Server information */
    _u16 loopback_port; /**< Loopback port to manage lib internal functioning - Mandatory */
    _u32 rx_tsk_priority; /**< Priority of the receive task in server */
    _u32 resp_time; /**< Reasonable response wait time (seconds) for server */
    bool aux_debug_en; /**< Assert to indicate additional debug info */
    _i32 (*dbg_print)(_const char *pcFormat, ...); /**< Print debug information */
    } SlMqttServerCfg_t;

    typedef struct {

    #define SL_MQTT_SRVR_NETCONN_IP6 0x01 /**< Assert for IPv6 connection, otherwise IPv4 */
    #define SL_MQTT_SRVR_NETCONN_URL 0x02 /**< Server address is an URL and not IP address */
    #define SL_MQTT_SRVR_NETCONN_SEC 0x04 /**< Connection to server must be secure (TLS) */

    _u32 netconn_flags; /**< Enumerate connection type */
    _const char *server_addr; /**< Server Address: URL or IP */
    _u16 port_number; /**< Port number of MQTT server */
    _u8 method; /**< Method to tcp secured socket */
    _u32 cipher; /**< Cipher to tcp secured socket */
    _u32 n_files; /**< Number of files for secure transfer */
    char * _const *secure_files; /*SL needs 4 files*/

    } SlMqttServerParams_t;

    这里的几个参数我还是不太理解,是说我需要把这里的server_addr和port_number改成自己设的,作为这块板子的地址和端口,然户在其他的MQTT Client板子上将地址和端口改成相同,这样就可以连接了?但我试了一下为什么连接不上。另外这个loopback_port又是起到什么作用呢?(看注释没有明白 T T)