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.

[参考译文] CC3220S-LAUNCHXL:启动 TIDC-01005

Guru**** 1624165 points
Other Parts Discussed in Thread: TIDC-01005, UNIFLASH, CC3220S
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/1022072/cc3220s-launchxl-bring-up-tidc-01005

器件型号:CC3220S-LAUNCHXL
主题中讨论的其他器件:TIDC-01005UNIFLASHCC3220S

尊敬的 TI Wifi 专家:

我正在努力推出 TIDC-01005。 首先、我下载并安装了与用户指南相匹配的所有 SDK。

我加载 了预制的 UniFlash ImageCreator 项目、并在 Tera Term 中得到:

[MQTT Thread]连接到代理失败、错误代码:-111桥断开连接

  #define SL_ERROR_BSD_ECONNREFUSED (-111L)/*拒绝连接*/

这很可能 是 Eclipse 经纪人不再活跃。 因此,我要做以下工作:

1.从 mosquitto.org 下载新的 DER 文件

2.将下载文件更改为 eclipsecert.der"

3.从  github.com 下载新的 DER 文件

4. 将下载文件更改为 digicertca.der"

5.转至 uniflash Advance -> userfiles

6.添加所有虚拟文件和两个下载的.der 文件

7.再次刻录和编程映像

8.完成配置后,我收到相同的错误。

您能告诉我错过了什么吗?  

谢谢、

成  

 

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    您是否更新了 MQTT_CLIENT_TASK_c 中的 MQTT 服务器地址? 您将其设置为什么?

    此致、

    Sarah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    我没有更改.c 文件。 我只是在 Uniflash 中使用新的.der 文件加载预制映像。  

    我将按 如下方式更新 CCS 中的 MQTT_CLIENT_Task.c 文件:

    URL:"MQTT://test.mosquitto.org

    IP:"85.119.83.194"

    在 CCS 中构建 app.c 后应该怎么做? 我是否需要创建映像文件并将其加载到开发板、以便可以使用新的.der 文件更新用户文件?

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    您可以使用相同的 ImageCreator 工程、并替换 mcuimg.bin。 您可以从"简单"选项卡或"用户文件"执行此操作。 有关详细信息、请参阅 UniFlash ImageCreator SimpleLink Academy。

    此致、

    Sarah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、  

    上述更新无法解决我的问题。 我概述了我采取的每一个步骤。 如果我错过了任何内容、请告诉我。  

    步骤1 - 按 如下方式更新了 MQTT_CLIENT_TASK_task.c:

    (我还尝试了: "MQTT://test.mosquitto.org 和 "test.mosquitto.org。")

    步骤2 - 在 CCS 中构建(调试)

    步骤3 - 在项目的调试文件夹中找到"wi_doorlock_CC3220S_LAUNCHXL_tirtos_ccs.bin"、并将文件名添加到"mcuimg.bin"

    步骤4 -将重做的 UniFlash ImageCreator 工程加载到 UniFlash 中

    第5步-转到高级将重新制作 的 UniFlash ImageCreator 工程加载到 UniFlash 中

    步骤6 -检测到 sys 文件夹中的现有"mcuimg.bin"以及顶层文件夹中的"digicertca.der"和"eclipsecert.der"文件"

    步骤7 - 在带有"dummy-trusted-cert-key"的 sys 文件夹中添加了新的"mcuimg.bin"(最初为"wi_doorlock_CC3220S_LAUNCHXL_tirtos_ccs.bin")并选择了"dummy-trusted-cert"  

    步骤8 -已将下载 的"digicertca.der"和"eclipsecert.der"文件"添加 到顶层文件夹

    步骤9 -在 UniFlash 中:连接->刻录->编程映像

    步骤10 -将 SOP 更改为100 ->重启

    步骤12 -打开 Tara Term

    步骤11 -完成 AP 配置

    结果-得到相同的-111错误(在~15分钟后、它变为-13)

    谢谢、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    如果您访问 test.mosquitto.org,服务器将提供自己的下载证书。 您是否尝试过此操作?

    还要确保更新了 MQTT_CLIENT_TAST.c 中的 MQTT_Client_SECURE_FILES 以匹配正确的证书。 您应将 eclipsecert.der 替换为 mosquitto.org.crt。

    您可以参考 Wi-Fi MQTT SimpleLink Academy 的安全客户端演示部分。

    此致、

    Sarah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    我按照下载 的参考文件 test.mosquitto.org 更新了用户文件

    更新 MQTT_CLIENT_TASK_c 中的 MQTT_Client_SECURE_FILES

    但我仍然会得到相同的-111误差  

    如果我错过了任何内容、请告诉我。

    谢谢

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

     您的 MQTT_ClientCTx 结构是使用 SERVER_ADDRESS 还是 SERVER_IP_ADDRESS 在 MQTT_CLIENT_TAST.c 中使用吗? 如果要定义 test.mosquitto.org、则应为  SERVER_ADDRESS。

    此致、

    Sarah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    如 上所述、我更新了 MQTT_ClientCtx、但仍收到相同的错误-111。

    Tara 术语:  

    我基于   "simplelink_cc32xx_sdk_2_10_00_04"附加了完整的 MQTT_CLIENT_TASK.c

    /*
     * Copyright (c) 2016, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /****************************************************************************************************************
                       INCLUDES
    ****************************************************************************************************************/
    
    /* Standard includes                                                          */
    #include <unistd.h>
    
    /* SimpleLink includes                                                        */
    #include <ti/drivers/net/wifi/simplelink.h>
    
    /* MQTT Library includes                                                      */
    #include <ti/net/mqtt/mqttclient.h>
    
    /* POSIX includes                                                             */
    #include "pthread.h"
    
    /* TI-Drivers includes                                                        */
    #include <ti/display/Display.h>
    
    /* Application includes                                                       */
    #include "Board.h"
    
    #include "wifi_doorlock_app.h"
    #include "mqtt_client_task.h"
    #include "motor_driver_if.h"
    
    /****************************************************************************************************************
                       DEFINES
    ****************************************************************************************************************/
    /* Define to support NTP */
    #define NTP_START_YEAR              (1900)
    #define CC32XX_MONTH_START_OFFSET   (1)
    
    /* Operate Lib in MQTT 3.1 mode.                                              */
    #define MQTT_3_1_1               false
    #define MQTT_3_1                 true
    
    #define WILL_TOPIC               "Client"
    #define WILL_MSG                 "Client Stopped"
    #define WILL_QOS                 MQTT_QOS_2
    #define WILL_RETAIN              false
    
    #define SECURE_CLIENT
    
    /* Defining Broker IP address and port Number                                 */
    #define SERVER_ADDRESS           "test.mosquitto.org"
    #define SERVER_IP_ADDRESS        "85.119.83.194" //
    #define PORT_NUMBER              1883
    #define SECURED_PORT_NUMBER      8883
    #define LOOPBACK_PORT            1882
    
    /* Clean session flag                                                         */
    #define CLEAN_SESSION            true
    
    /* Retain Flag. Used in publish message.                                      */
    #define RETAIN_ENABLE            1
    
    #define LOCK_CONTROL_CMD_LENGTH  5
    
    #define TOPIC_START_INDEX       (12)
    
    #define CLIENT_NUM_SECURE_FILES 1
    
    /****************************************************************************************************************
                       LOCAL FUNCTION PROTOTYPES
    ****************************************************************************************************************/
    void *  MqttClientThread(void * pvParameters);
    int32_t MqttClient_start();
    void    Mqtt_ClientStop(uint8_t disconnect);
    
    /****************************************************************************************************************
                       GLOBAL VARIABLES
    ****************************************************************************************************************/
    
    /* MQTT RX task handle                                                        */
    pthread_t g_rx_task_hndl        = (pthread_t) NULL;
    
    /* Overall Application App Context                                            */
    extern Application_CB App_CB;
    extern Display_Handle display;
    
    /* Struct with parameters for MQTT connection                                 */
    MQTTClient_Params  MqttClientExample_params;
    
    /* Client ID                                                                  */
    /* If ClientId isn't set, the MAC address of the device will be copied into   */
    /* the ClientID parameter.                                                    */
    char ClientId[13] = {'\0'};
    
    /* Subscription topics and qos values                                         */
    char *topic[SUBSCRIPTION_TOPIC_COUNT] =
            { SUBSCRIPTION_TOPIC0, SUBSCRIPTION_TOPIC1, \
              SUBSCRIPTION_TOPIC2, SUBSCRIPTION_TOPIC3 };
    
    unsigned char qos[SUBSCRIPTION_TOPIC_COUNT] =
            { MQTT_QOS_2, MQTT_QOS_2, MQTT_QOS_2, MQTT_QOS_2 };
    
    /* Publishing topics and messages                                             */
    char *publish_topic[PUBLISH_TOPIC_COUNT] = { PUBLISH_TOPIC0 };
    
    char *publish_data[PUBLISH_DATA_COUNT] = { PUBLISH_TOPIC0_LOCKED, PUBLISH_TOPIC0_UNLOCKED };
    
    #ifdef  SECURE_CLIENT
    char *Mqtt_Client_secure_files[CLIENT_NUM_SECURE_FILES] = {"mosquitto.org.crt"};
    
    /* Initialization structure to be used with sl_ExtMqtt_Init API. In order to  */
    /* use secured socket method, the flag MQTTCLIENT_NETCONN_SEC, cipher,        */
    /* n_files and secure_files must be configured.                               */
    /* certificates also must be programmed  ("ca-cert.pem").                     */
    /* The first parameter is a bit mask which configures server address type and */
    /* security mode.                                                             */
    /* Server address type: IPv4, IPv6 and URL must be declared with The          */
    /* corresponding flag.                                                        */
    /* Security mode: The flag MQTTCLIENT_NETCONN_SEC enables the security (TLS)  */
    /* which includes domain name verification and certificate catalog            */
    /* verification, those verifications can be disabled by adding to the bit mask*/
    /* MQTTCLIENT_NETCONN_SKIP_DOMAIN_NAME_VERIFICATION and                       */
    /* MQTTCLIENT_NETCONN_SKIP_CERTIFICATE_CATALOG_VERIFICATION flags             */
    /* Example: MQTTCLIENT_NETCONN_IP6 | MQTTCLIENT_NETCONN_SEC |                 */
    /* MQTTCLIENT_NETCONN_SKIP_CERTIFICATE_CATALOG_VERIFICATION                   */
    /* For this bit mask, the IPv6 address type will be in use, the security      */
    /* feature will be enable and the certificate catalog verification will be    */
    /* skipped.                                                                   */
    /* Note: The domain name verification requires URL Server address type        */
    /*       otherwise, this verification will be disabled.                       */
    MQTTClient_ConnParams Mqtt_ClientCtx =
    {
         MQTTCLIENT_NETCONN_IP4 | MQTTCLIENT_NETCONN_SEC | MQTT_DEV_NETCONN_OPT_SKIP_CERTIFICATE_CATALOG_VERIFICATION | MQTTCLIENT_NETCONN_SKIP_DOMAIN_NAME_VERIFICATION,
         SERVER_ADDRESS,//SERVER_IP_ADDRESS,
         SECURED_PORT_NUMBER,
         SLNETSOCK_SEC_METHOD_SSLv3_TLSV1_2,
         SLNETSOCK_SEC_CIPHER_FULL_LIST,
         CLIENT_NUM_SECURE_FILES,
         Mqtt_Client_secure_files
    };
    #else
    MQTTClient_ConnParams Mqtt_ClientCtx =
    {
        MQTTCLIENT_NETCONN_URL,
        SERVER_ADDRESS,
        PORT_NUMBER, 0, 0, 0,
        NULL
    };
    #endif
    
    /* Initialize the will_param structure to the default will parameters         */
    MQTTClient_Will will_param =
    {
        WILL_TOPIC,
        WILL_MSG,
        WILL_QOS,
        WILL_RETAIN
    };
    
    uint16_t    mqttKeepAliveTimeout = 43200; // 43200 sec = 12hr * 60 min * 60 sec
    
    //*****************************************************************************
    //
    //! Task implementing MQTT Server plus client bridge
    //!
    //! This function
    //!    1. Initializes network driver and connects to the default AP
    //!    2. Initializes the mqtt client ans server libraries and set up MQTT
    //!       with the remote broker.
    //!    3. set up the button events and their callbacks(for publishing)
    //!    4. handles the callback signals
    //!
    //! \param  none
    //!
    //! \return None
    //!
    //*****************************************************************************
    void * MqttClient(void *pvParameters)
    {
        long lRetVal = -1;
        char *tmpBuff;
        char recvdMsg[256];
        int32_t iCount = 0;
        mqtt_task_states_t    mqttState = MQTT_LIB_INITIALIZATION;
        struct msgQueue queueElemRecv;
    
        memset(recvdMsg, 0x00, sizeof(recvdMsg));
    
        sem_post(&App_CB.mqttReady);
        sem_wait(&App_CB.startBarrier);
    
        while(1)
        {
            switch(mqttState)
            {
            case MQTT_LIB_INITIALIZATION:
            {
                lRetVal = MqttClient_start();
                if (lRetVal == -1)
                {
                    Display_printf(
                            display,
                            0,
                            0,
                            "\t [MQTT Thread] MQTT Client library initialization failed");
                    while (1);
                }
                else
                {
                    Display_printf(
                            display,
                            0,
                            0,
                            "[MQTT Thread] MQTT Client library initialized successfully");
                    SET_STATUS_BIT(App_CB.status, AppStatusBits_MqttInitialized);
    
                    if(GET_STATUS_BIT(App_CB.status, AppStatusBits_Connection) && GET_STATUS_BIT(App_CB.status, AppStatusBits_IpAcquired))
                    {
                        mqttState = MQTT_CLIENT_CONNECTING_TO_BROKER;
                    }
                    else
                    {
                        mqttState = MQTT_WAITING_FOR_NETWORK_CONNECTION;
                    }
                }
            }
                break;
            case MQTT_WAITING_FOR_NETWORK_CONNECTION:
            {
                sem_wait(&App_CB.connectionDoneSignal);
                mqttState = MQTT_CLIENT_CONNECTING_TO_BROKER;
            }
                break;
            case MQTT_CLIENT_CONNECTING_TO_BROKER:
            {
    
    #if CLEAN_SESSION == false
                bool clean = CLEAN_SESSION;
                MQTTClient_set(App_CB.mqttClientHandle, MQTT_CLIENT_CLEAN_CONNECT, (void *)&clean, sizeof(bool));
    #endif
                /* The return code of MQTTClient_connect is the ConnACK value that
                 returns from the server */
                lRetVal = MQTTClient_connect(App_CB.mqttClientHandle);
    
                /* negative lRetVal means error,
                 0 means connection successful without session stored by the server,
                 greater than 0 means successful connection with session stored by
                 the server */
                if (0 > lRetVal)
                {
                    /* lib initialization failed                                      */
                    Display_printf(
                            display,
                            0,
                            0,
                            "\t [MQTT Thread] Connection to broker failed, Error code: %d",
                            lRetVal);
    
                    MQTTClient_disconnect(App_CB.mqttClientHandle);
                    SET_STATUS_BIT(App_CB.status, AppStatusBits_MqttStopInProgress);
                    Mqtt_ClientStop(1);
                    while (GET_STATUS_BIT(App_CB.status,
                                          AppStatusBits_MqttStopInProgress))
                    {
                        sleep(1);
                    }
                    mqttState = MQTT_LIB_INITIALIZATION;
                    sleep(1);
                }
                else
                {
                    SET_STATUS_BIT(App_CB.status, AppStatusBits_MqttConnected);
                    mqttState = MQTT_CLIENT_CONNECTED;
                }
                /* Subscribe to topics when session is not stored by the server       */
                if (GET_STATUS_BIT(App_CB.status, AppStatusBits_MqttConnected)
                        && (0 == lRetVal))
                {
                    uint8_t subIndex;
                    MQTTClient_SubscribeParams subscriptionInfo[SUBSCRIPTION_TOPIC_COUNT];
    
                    for (subIndex = 0; subIndex < SUBSCRIPTION_TOPIC_COUNT;
                            subIndex++)
                    {
                        subscriptionInfo[subIndex].topic = topic[subIndex];
                        subscriptionInfo[subIndex].qos = qos[subIndex];
                    }
    
                    if (MQTTClient_subscribe(App_CB.mqttClientHandle,
                                             subscriptionInfo,
                                             SUBSCRIPTION_TOPIC_COUNT) < 0)
                    {
                        Display_printf(display, 0, 0,
                                       "\t [MQTT Thread] Subscription Error");
                        MQTTClient_disconnect(App_CB.mqttClientHandle);
    
                        /* Manually disconnected, need to reconnect to broker*/
                        SET_STATUS_BIT(App_CB.status,
                                       AppStatusBits_MqttStopInProgress);
                        Mqtt_ClientStop(1);
                        while (GET_STATUS_BIT(App_CB.status,
                                              AppStatusBits_MqttStopInProgress))
                        {
                            sleep(1);
                        }
                        mqttState = MQTT_LIB_INITIALIZATION;
                    }
                    else
                    {
                        for (iCount = 0; iCount < SUBSCRIPTION_TOPIC_COUNT;
                                iCount++)
                        {
                            Display_printf(display, 0, 0,
                                           "[MQTT Thread] Client subscribed on %s",
                                           topic[iCount]);
                        }
                    }
                }
            }
                break;
            case MQTT_CLIENT_CONNECTED:
            {
                /* handling the signals from various callbacks including the push button  */
                /* prompting the client to publish a msg on PUB_TOPIC OR msg received by  */
                /* the server on enrolled topic(for which the on-board client ha enrolled)*/
                /* from a local client(will be published to the remote broker by the      */
                /* client) OR msg received by the client from the remote broker (need to  */
                /* be sent to the server to see if any local client has subscribed on the */
                /* same topic).                                                           */
    
                /* waiting for signals                                                */
                mq_receive(App_CB.mqttQueue, (char*) &queueElemRecv,
                           sizeof(struct msgQueue), NULL);
    
                switch (queueElemRecv.event)
                {
                /* msg received by client from remote broker (on a topic      */
                /* subscribed by local client)                                */
                case MSG_RECV_BY_CLIENT:
                    tmpBuff = (char *) ((char *) queueElemRecv.msgPtr
                            + TOPIC_START_INDEX);
                    if (strncmp(tmpBuff, (const char*) topic[1],
                                queueElemRecv.topLen) == 0)
                    {
                        struct motorMsg queueElem;
    
                        strncpy(recvdMsg,
                                ((char*) queueElemRecv.msgPtr + TOPIC_START_INDEX
                                        + queueElemRecv.topLen + 1),
                                queueElemRecv.msgLen);
                        recvdMsg[queueElemRecv.msgLen] = '\0';
                        if ((strncmp(recvdMsg, "lock", sizeof(queueElemRecv.msgLen))
                                == 0) && !App_CB.locked)
                        {
                            queueElem.event = LOCK_MOTOR_CMD;
                            App_CB.locked = true;
                            if (Motor_SendMsgToQueue(&queueElem))
                            {
                                Display_printf(
                                        display, 0, 0,
                                        "\t [MQTT Thread] Queue is full");
                            }
                        }
                        else if ((strncmp(recvdMsg, "unlock",
                                          sizeof(queueElemRecv.msgLen)) == 0) && App_CB.locked)
                        {
                            queueElem.event = UNLOCK_MOTOR_CMD;
                            App_CB.locked = false;
                            if (Motor_SendMsgToQueue(&queueElem))
                            {
                                Display_printf(
                                        display, 0, 0,
                                        "\t [MQTT Thread] Queue is full");
                            }
                        }
                        else
                        {
                            Display_printf(display, 0, 0,
                                           "[MQTT Thread] Message: %s",
                                           recvdMsg);
                            Display_printf(
                                    display,
                                    0,
                                    0,
                                    "[MQTT Thread] Message ignored because lock is already in requested state or payload is invalid");
                            break;
                        }
                    }
                    else if (strncmp(tmpBuff, (const char*) topic[2],
                                     queueElemRecv.topLen) == 0)
                    {
                        char msg[30] = { '\0' };
    
                        strcpy(msg,
                               (App_CB.locked == true) ?
                               PUBLISH_TOPIC0_LOCKED :
                                                         PUBLISH_TOPIC0_UNLOCKED);
    
                        lRetVal = MQTTClient_publish(
                                App_CB.mqttClientHandle, (char*) publish_topic[0],
                                strlen((char*) publish_topic[0]), (char*) msg,
                                strlen((char*) msg),
                                MQTT_QOS_2 | ((RETAIN_ENABLE) ?
                                MQTT_PUBLISH_RETAIN :
                                                                0));
    
                        Display_printf(
                                display,
                                0,
                                0,
                                "\n\r [MQTT Thread] CC3200 Publishes the following message");
                        Display_printf(display, 0, 0, "[MQTT Thread] Topic: %s",
                                       publish_topic);
                        Display_printf(display, 0, 0, "[MQTT Thread] Data: %s",
                                       msg);
                    }
                    else if (strncmp(tmpBuff, (const char*) topic[3],
                                     queueElemRecv.topLen) == 0)
                    {
                        struct controlMsg controlMsg;
    
                        controlMsg.threadID = 1;
                        controlMsg.msg = CONTROL_MSG_OTA_START;
    
                        if (!GET_STATUS_BIT(App_CB.status,
                                            AppStatusBits_OtaInProgress))
                        {
                            mq_send(App_CB.controlQueue, (char *) &controlMsg,
                                    sizeof(struct controlMsg), NULL);
    
                            SET_STATUS_BIT(App_CB.status,
                                           AppStatusBits_OtaInProgress);
                        }
                    }
    
                    free(queueElemRecv.msgPtr);
                    break;
    
                    /* On-board client disconnected from remote broker, only      */
                    /* local MQTT network will work                               */
                case LOCAL_CLIENT_DISCONNECTION:
                    Display_printf(display, 0, 0,
                                   "\t [MQTT Thread] On-board Client Disconnected");
    
                    if(GET_STATUS_BIT(App_CB.status, AppStatusBits_Connection) && GET_STATUS_BIT(App_CB.status, AppStatusBits_IpAcquired))
                    {
                        MQTTClient_disconnect(App_CB.mqttClientHandle);
                        CLR_STATUS_BIT(App_CB.status, AppStatusBits_MqttConnected);
                        mqttState = MQTT_CLIENT_CONNECTING_TO_BROKER;
                    }
                    else
                    {
                        Mqtt_ClientStop(1);
                        mqttState = MQTT_LIB_INITIALIZATION;
                    }
                    break;
    
                case THREAD_TERMINATE_REQ:
                    Display_printf(display, 0, 0,
                                   "[MQTT Thread] Terminating MQTT Client");
    
                    SET_STATUS_BIT(App_CB.status, AppStatusBits_MqttStopInProgress);
                    Mqtt_ClientStop(1);
                    pthread_exit(0);
                    return NULL;
    
                default:
                    break;
                }
                break;
            }
            }
        }
    }
    
    //*****************************************************************************
    //
    //! MQTT_SendMsgToQueue - Utility function that receive msgQueue parameter and
    //! tries to push it the queue with minimal time for timeout of 0.
    //! If the queue isn't full the parameter will be stored and the function
    //! will return 0.
    //! If the queue is full and the timeout expired (because the timeout parameter
    //! is 0 it will expire immediately), the parameter is thrown away and the
    //! function will return -1 as an error for full queue.
    //!
    //! \param[in] struct msgQueue *queueElement
    //!
    //! \return 0 on success, -1 on error
    //
    //*****************************************************************************
    int32_t MQTT_SendMsgToQueue(struct msgQueue *queueElement)
    {
        struct timespec abstime = { 0 };
    
        clock_gettime(CLOCK_REALTIME, &abstime);
    
        if (App_CB.mqttQueue)
        {
            /* send message to the queue                                         */
            if (mq_timedsend(App_CB.mqttQueue, (char *) queueElement,
                             sizeof(struct msgQueue), 0, &abstime) == 0)
            {
                return 0;
            }
        }
        return -1;
    }
    
    int32_t MqttClient_start()
    {
        int32_t lRetVal = -1;
    
        int32_t threadArg = 100;
        pthread_attr_t pAttrs;
        struct sched_param priParam;
    
        MqttClientExample_params.clientId = ClientId;
        MqttClientExample_params.connParams = &Mqtt_ClientCtx;
        MqttClientExample_params.mqttMode31 = MQTT_3_1;
        MqttClientExample_params.blockingSend = true;
    
        /* Initialize MQTT client lib                                             */
        App_CB.mqttClientHandle = MQTTClient_create(MqttClientCallback,
                                                    &MqttClientExample_params);
        if (App_CB.mqttClientHandle == NULL)
        {
            /* Lib initialization failed */
            Display_printf(display, 0, 0,
                           "\t [MQTT Thread] Error - MQTT client handle is null");
            return -1;
        }
    
        /* Open Client Receive Thread start the receive task. Set priority and    */
        /* stack size attributes                                                  */
        pthread_attr_init(&pAttrs);
        priParam.sched_priority = 4;
        lRetVal = pthread_attr_setschedparam(&pAttrs, &priParam);
        lRetVal |= pthread_attr_setstacksize(&pAttrs, MQTT_CLIENT_RX_TASK_SIZE);
        lRetVal |= pthread_attr_setdetachstate(&pAttrs, PTHREAD_CREATE_DETACHED);
        lRetVal |= pthread_create(&g_rx_task_hndl, &pAttrs, MqttClientThread,
                                  (void *) &threadArg);
        if (lRetVal != 0)
        {
            Display_printf(display, 0, 0,
                           "[MQTT Thread] Client Thread create failed");
            return -1;
        }
    
        /* setting will parameters                                                */
        MQTTClient_set(App_CB.mqttClientHandle, MQTTClient_WILL_PARAM, &will_param,
                       sizeof(will_param));
        MQTTClient_set(App_CB.mqttClientHandle, MQTTClient_KEEPALIVE_TIME,
                       &mqttKeepAliveTimeout, sizeof(mqttKeepAliveTimeout));
    
        return 0;
    }
    
    //*****************************************************************************
    //!
    //! MQTT Client stop - Unsubscribe from the subscription topics and exit the
    //! MQTT client lib.
    //!
    //! \param  none
    //!
    //! \return None
    //!
    //*****************************************************************************
    
    void Mqtt_ClientStop(uint8_t disconnect)
    {
        uint32_t iCount;
    
        MQTTClient_UnsubscribeParams subscriptionInfo[SUBSCRIPTION_TOPIC_COUNT];
    
        for (iCount = 0; iCount < SUBSCRIPTION_TOPIC_COUNT; iCount++)
        {
            subscriptionInfo[iCount].topic = topic[iCount];
        }
    
        MQTTClient_unsubscribe(App_CB.mqttClientHandle, subscriptionInfo,
        SUBSCRIPTION_TOPIC_COUNT);
        for (iCount = 0; iCount < SUBSCRIPTION_TOPIC_COUNT; iCount++)
        {
            Display_printf(display, 0, 0,
                           "[MQTT Thread] Unsubscribed from the topic %s",
                           topic[iCount]);
        }
    
        CLR_STATUS_BIT(App_CB.status, AppStatusBits_MqttConnected);
        CLR_STATUS_BIT(App_CB.status, AppStatusBits_MqttInitialized);
    
        /* exiting the Client library                                             */
        MQTTClient_delete(App_CB.mqttClientHandle);
    
        Display_printf(display, 0, 0, "[MQTT Thread] MQTT Client Handle deleted");
    
        CLR_STATUS_BIT(App_CB.status, AppStatusBits_MqttStopInProgress);
    }
    
    void *MqttClientThread(void * pvParameters)
    {
        struct msgQueue queueElement;
        struct msgQueue queueElemRecv;
    
        MQTTClient_run((MQTTClient_Handle) pvParameters);
    
        /* Check if MQTT thread is already being stopped */
        if(!GET_STATUS_BIT(App_CB.status, AppStatusBits_MqttStopInProgress))
        {
            SET_STATUS_BIT(App_CB.status, AppStatusBits_MqttStopInProgress);
    
            queueElement.event = LOCAL_CLIENT_DISCONNECTION;
            queueElement.msgPtr = NULL;
    
            /* write message indicating disconnect Broker message.                    */
            if (MQTT_SendMsgToQueue(&queueElement))
            {
                Display_printf(
                        display,
                        0,
                        0,
                        "\t [MQTT Thread] Queue is full, throw first msg and send the new one");
                mq_receive(App_CB.mqttQueue, (char*) &queueElemRecv,
                           sizeof(struct msgQueue), NULL);
                MQTT_SendMsgToQueue(&queueElement);
            }
        }
    
        pthread_exit(0);
    
        return NULL;
    }
    

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    您是否遵循了 Wi-Fi MQTT 实验室中的其他步骤?  MQTCLIENT_NETCONN_IP4应为 MQTCLIENT_NETCONN_URL

    此致、

    Sarah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    启动 "配置安全客户端演示"

    任务1:启用受保护的客户端

    步骤1:更新 "MQTTClient_ConnParams MQTT_ClientCtx"

    命令输出现有参数并添加更新 的 MQTTClient_ConnParams MQTT_ClientCtx

    步骤2:  

    步骤3:

    步骤4:我找不到更新日期和时间的位置

    步骤5: 我无法使用函数 WifiInt()和 MQTT_IF_Init()

    ---- 完成代码修改---

    使用新的.bin 和.crt 文件刷写电路板

    运行 trar Term、这次收到订阅错误

      

    如果我错过了任何内容、请告诉我

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    我能够成功运行相同的演示。 您是否对应用程序进行了任何其他更改? MqttClient_subscribe()返回什么错误代码?

    此致、

    Sarah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    我重新导入项目并重新执行代码更新、但仍会遇到与上述相同的错误。 您能否发布您的代码?

    这是我的(我只触及  MQTT_CLIENT_TASK_task.c)

    /*
     * Copyright (c) 2016, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /****************************************************************************************************************
                       INCLUDES
    ****************************************************************************************************************/
    
    /* Standard includes                                                          */
    #include <unistd.h>
    
    /* SimpleLink includes                                                        */
    #include <ti/drivers/net/wifi/simplelink.h>
    
    /* MQTT Library includes                                                      */
    #include <ti/net/mqtt/mqttclient.h>
    
    /* POSIX includes                                                             */
    #include "pthread.h"
    
    /* TI-Drivers includes                                                        */
    #include <ti/display/Display.h>
    
    /* Application includes                                                       */
    #include "Board.h"
    
    #include "wifi_doorlock_app.h"
    #include "mqtt_client_task.h"
    #include "motor_driver_if.h"
    
    /****************************************************************************************************************
                       DEFINES
    ****************************************************************************************************************/
    /* Define to support NTP */
    #define NTP_START_YEAR              (1900)
    #define CC32XX_MONTH_START_OFFSET   (1)
    
    /* Operate Lib in MQTT 3.1 mode.                                              */
    #define MQTT_3_1_1               false
    #define MQTT_3_1                 true
    
    #define WILL_TOPIC               "Client"
    #define WILL_MSG                 "Client Stopped"
    #define WILL_QOS                 MQTT_QOS_2
    #define WILL_RETAIN              false
    
    #define SECURE_CLIENT
    
    /* Defining Broker IP address and port Number                                 */
    
     #define MQTT_CONNECTION_FLAGS       MQTTCLIENT_NETCONN_URL | MQTTCLIENT_NETCONN_SEC \
                                         | MQTTCLIENT_NETCONN_SKIP_CERTIFICATE_CATALOG_VERIFICATION
     #define MQTT_CONNECTION_ADDRESS     "test.mosquitto.org"
     #define MQTT_CONNECTION_PORT_NUMBER  8883
    
    
    #define SERVER_ADDRESS           "m2m.eclipse.org"
    #define SERVER_IP_ADDRESS        "198.41.30.241"
    #define PORT_NUMBER              1883
    #define SECURED_PORT_NUMBER      8883
    #define LOOPBACK_PORT            1882
    
    /* Clean session flag                                                         */
    #define CLEAN_SESSION            true
    
    /* Retain Flag. Used in publish message.                                      */
    #define RETAIN_ENABLE            1
    
    #define LOCK_CONTROL_CMD_LENGTH  5
    
    #define TOPIC_START_INDEX       (12)
    
    #define CLIENT_NUM_SECURE_FILES 1
    
    /****************************************************************************************************************
                       LOCAL FUNCTION PROTOTYPES
    ****************************************************************************************************************/
    void *  MqttClientThread(void * pvParameters);
    int32_t MqttClient_start();
    void    Mqtt_ClientStop(uint8_t disconnect);
    
    /****************************************************************************************************************
                       GLOBAL VARIABLES
    ****************************************************************************************************************/
    
    /* MQTT RX task handle                                                        */
    pthread_t g_rx_task_hndl        = (pthread_t) NULL;
    
    /* Overall Application App Context                                            */
    extern Application_CB App_CB;
    extern Display_Handle display;
    
    /* Struct with parameters for MQTT connection                                 */
    MQTTClient_Params  MqttClientExample_params;
    
    /* Client ID                                                                  */
    /* If ClientId isn't set, the MAC address of the device will be copied into   */
    /* the ClientID parameter.                                                    */
    char ClientId[13] = {'\0'};
    
    /* Subscription topics and qos values                                         */
    char *topic[SUBSCRIPTION_TOPIC_COUNT] =
            { SUBSCRIPTION_TOPIC0, SUBSCRIPTION_TOPIC1, \
              SUBSCRIPTION_TOPIC2, SUBSCRIPTION_TOPIC3 };
    
    unsigned char qos[SUBSCRIPTION_TOPIC_COUNT] =
            { MQTT_QOS_2, MQTT_QOS_2, MQTT_QOS_2, MQTT_QOS_2 };
    
    /* Publishing topics and messages                                             */
    char *publish_topic[PUBLISH_TOPIC_COUNT] = { PUBLISH_TOPIC0 };
    
    char *publish_data[PUBLISH_DATA_COUNT] = { PUBLISH_TOPIC0_LOCKED, PUBLISH_TOPIC0_UNLOCKED };
    
    #ifdef  SECURE_CLIENT
    char *Mqtt_Client_secure_files[CLIENT_NUM_SECURE_FILES] = {"mosquitto.org.crt"};
    
    /* Initialization structure to be used with sl_ExtMqtt_Init API. In order to  */
    /* use secured socket method, the flag MQTTCLIENT_NETCONN_SEC, cipher,        */
    /* n_files and secure_files must be configured.                               */
    /* certificates also must be programmed  ("ca-cert.pem").                     */
    /* The first parameter is a bit mask which configures server address type and */
    /* security mode.                                                             */
    /* Server address type: IPv4, IPv6 and URL must be declared with The          */
    /* corresponding flag.                                                        */
    /* Security mode: The flag MQTTCLIENT_NETCONN_SEC enables the security (TLS)  */
    /* which includes domain name verification and certificate catalog            */
    /* verification, those verifications can be disabled by adding to the bit mask*/
    /* MQTTCLIENT_NETCONN_SKIP_DOMAIN_NAME_VERIFICATION and                       */
    /* MQTTCLIENT_NETCONN_SKIP_CERTIFICATE_CATALOG_VERIFICATION flags             */
    /* Example: MQTTCLIENT_NETCONN_IP6 | MQTTCLIENT_NETCONN_SEC |                 */
    /* MQTTCLIENT_NETCONN_SKIP_CERTIFICATE_CATALOG_VERIFICATION                   */
    /* For this bit mask, the IPv6 address type will be in use, the security      */
    /* feature will be enable and the certificate catalog verification will be    */
    /* skipped.                                                                   */
    /* Note: The domain name verification requires URL Server address type        */
    /*       otherwise, this verification will be disabled.                       */
    MQTTClient_ConnParams Mqtt_ClientCtx =
    {
          MQTT_CONNECTION_FLAGS,                  // connection flags
          MQTT_CONNECTION_ADDRESS,                // server address
          MQTT_CONNECTION_PORT_NUMBER,            // port number of MQTT server
          SLNETSOCK_SEC_METHOD_SSLv3_TLSV1_2,     // method for secure socket
          SLNETSOCK_SEC_CIPHER_FULL_LIST,         // cipher for secure socket
          1,                                      // number of files for secure connection
          Mqtt_Client_secure_files
    
    
         //MQTTCLIENT_NETCONN_IP4 | MQTTCLIENT_NETCONN_SEC | MQTT_DEV_NETCONN_OPT_SKIP_CERTIFICATE_CATALOG_VERIFICATION | MQTTCLIENT_NETCONN_SKIP_DOMAIN_NAME_VERIFICATION,
         //SERVER_IP_ADDRESS,
         //SECURED_PORT_NUMBER,
         //SLNETSOCK_SEC_METHOD_SSLv3_TLSV1_2,
         //SLNETSOCK_SEC_CIPHER_FULL_LIST,
         //CLIENT_NUM_SECURE_FILES,
    
    };
    #else
    MQTTClient_ConnParams Mqtt_ClientCtx =
    {
        //MQTTCLIENT_NETCONN_URL,
        //SERVER_ADDRESS,
        //PORT_NUMBER, 0, 0, 0,
        //NULL
    };
    #endif
    
    /* Initialize the will_param structure to the default will parameters         */
    MQTTClient_Will will_param =
    {
        WILL_TOPIC,
        WILL_MSG,
        WILL_QOS,
        WILL_RETAIN
    };
    
    uint16_t    mqttKeepAliveTimeout = 43200; // 43200 sec = 12hr * 60 min * 60 sec
    
    //*****************************************************************************
    //
    //! Task implementing MQTT Server plus client bridge
    //!
    //! This function
    //!    1. Initializes network driver and connects to the default AP
    //!    2. Initializes the mqtt client ans server libraries and set up MQTT
    //!       with the remote broker.
    //!    3. set up the button events and their callbacks(for publishing)
    //!    4. handles the callback signals
    //!
    //! \param  none
    //!
    //! \return None
    //!
    //*****************************************************************************
    void * MqttClient(void *pvParameters)
    {
        long lRetVal = -1;
        char *tmpBuff;
        char recvdMsg[256];
        int32_t iCount = 0;
        mqtt_task_states_t    mqttState = MQTT_LIB_INITIALIZATION;
        struct msgQueue queueElemRecv;
    
        memset(recvdMsg, 0x00, sizeof(recvdMsg));
    
        sem_post(&App_CB.mqttReady);
        sem_wait(&App_CB.startBarrier);
    
        while(1)
        {
            switch(mqttState)
            {
            case MQTT_LIB_INITIALIZATION:
            {
                lRetVal = MqttClient_start();
                if (lRetVal == -1)
                {
                    Display_printf(
                            display,
                            0,
                            0,
                            "\t [MQTT Thread] MQTT Client library initialization failed");
                    while (1);
                }
                else
                {
                    Display_printf(
                            display,
                            0,
                            0,
                            "[MQTT Thread] MQTT Client library initialized successfully");
                    SET_STATUS_BIT(App_CB.status, AppStatusBits_MqttInitialized);
    
                    if(GET_STATUS_BIT(App_CB.status, AppStatusBits_Connection) && GET_STATUS_BIT(App_CB.status, AppStatusBits_IpAcquired))
                    {
                        mqttState = MQTT_CLIENT_CONNECTING_TO_BROKER;
                    }
                    else
                    {
                        mqttState = MQTT_WAITING_FOR_NETWORK_CONNECTION;
                    }
                }
            }
                break;
            case MQTT_WAITING_FOR_NETWORK_CONNECTION:
            {
                sem_wait(&App_CB.connectionDoneSignal);
                mqttState = MQTT_CLIENT_CONNECTING_TO_BROKER;
            }
                break;
            case MQTT_CLIENT_CONNECTING_TO_BROKER:
            {
    
    #if CLEAN_SESSION == false
                bool clean = CLEAN_SESSION;
                MQTTClient_set(App_CB.mqttClientHandle, MQTT_CLIENT_CLEAN_CONNECT, (void *)&clean, sizeof(bool));
    #endif
                /* The return code of MQTTClient_connect is the ConnACK value that
                 returns from the server */
                lRetVal = MQTTClient_connect(App_CB.mqttClientHandle);
    
                /* negative lRetVal means error,
                 0 means connection successful without session stored by the server,
                 greater than 0 means successful connection with session stored by
                 the server */
                if (0 > lRetVal)
                {
                    /* lib initialization failed                                      */
                    Display_printf(
                            display,
                            0,
                            0,
                            "\t [MQTT Thread] Connection to broker failed, Error code: %d",
                            lRetVal);
    
                    MQTTClient_disconnect(App_CB.mqttClientHandle);
                    SET_STATUS_BIT(App_CB.status, AppStatusBits_MqttStopInProgress);
                    Mqtt_ClientStop(1);
                    while (GET_STATUS_BIT(App_CB.status,
                                          AppStatusBits_MqttStopInProgress))
                    {
                        sleep(1);
                    }
                    mqttState = MQTT_LIB_INITIALIZATION;
                    sleep(1);
                }
                else
                {
                    SET_STATUS_BIT(App_CB.status, AppStatusBits_MqttConnected);
                    mqttState = MQTT_CLIENT_CONNECTED;
                }
                /* Subscribe to topics when session is not stored by the server       */
                if (GET_STATUS_BIT(App_CB.status, AppStatusBits_MqttConnected)
                        && (0 == lRetVal))
                {
                    uint8_t subIndex;
                    MQTTClient_SubscribeParams subscriptionInfo[SUBSCRIPTION_TOPIC_COUNT];
    
                    for (subIndex = 0; subIndex < SUBSCRIPTION_TOPIC_COUNT;
                            subIndex++)
                    {
                        subscriptionInfo[subIndex].topic = topic[subIndex];
                        subscriptionInfo[subIndex].qos = qos[subIndex];
                    }
    
                    if (MQTTClient_subscribe(App_CB.mqttClientHandle,
                                             subscriptionInfo,
                                             SUBSCRIPTION_TOPIC_COUNT) < 0)
                    {
                        Display_printf(display, 0, 0,
                                       "\t [MQTT Thread] Subscription Error");
                        MQTTClient_disconnect(App_CB.mqttClientHandle);
    
                        /* Manually disconnected, need to reconnect to broker*/
                        SET_STATUS_BIT(App_CB.status,
                                       AppStatusBits_MqttStopInProgress);
                        Mqtt_ClientStop(1);
                        while (GET_STATUS_BIT(App_CB.status,
                                              AppStatusBits_MqttStopInProgress))
                        {
                            sleep(1);
                        }
                        mqttState = MQTT_LIB_INITIALIZATION;
                    }
                    else
                    {
                        for (iCount = 0; iCount < SUBSCRIPTION_TOPIC_COUNT;
                                iCount++)
                        {
                            Display_printf(display, 0, 0,
                                           "[MQTT Thread] Client subscribed on %s",
                                           topic[iCount]);
                        }
                    }
                }
            }
                break;
            case MQTT_CLIENT_CONNECTED:
            {
                /* handling the signals from various callbacks including the push button  */
                /* prompting the client to publish a msg on PUB_TOPIC OR msg received by  */
                /* the server on enrolled topic(for which the on-board client ha enrolled)*/
                /* from a local client(will be published to the remote broker by the      */
                /* client) OR msg received by the client from the remote broker (need to  */
                /* be sent to the server to see if any local client has subscribed on the */
                /* same topic).                                                           */
    
                /* waiting for signals                                                */
                mq_receive(App_CB.mqttQueue, (char*) &queueElemRecv,
                           sizeof(struct msgQueue), NULL);
    
                switch (queueElemRecv.event)
                {
                /* msg received by client from remote broker (on a topic      */
                /* subscribed by local client)                                */
                case MSG_RECV_BY_CLIENT:
                    tmpBuff = (char *) ((char *) queueElemRecv.msgPtr
                            + TOPIC_START_INDEX);
                    if (strncmp(tmpBuff, (const char*) topic[1],
                                queueElemRecv.topLen) == 0)
                    {
                        struct motorMsg queueElem;
    
                        strncpy(recvdMsg,
                                ((char*) queueElemRecv.msgPtr + TOPIC_START_INDEX
                                        + queueElemRecv.topLen + 1),
                                queueElemRecv.msgLen);
                        recvdMsg[queueElemRecv.msgLen] = '\0';
                        if ((strncmp(recvdMsg, "lock", sizeof(queueElemRecv.msgLen))
                                == 0) && !App_CB.locked)
                        {
                            queueElem.event = LOCK_MOTOR_CMD;
                            App_CB.locked = true;
                            if (Motor_SendMsgToQueue(&queueElem))
                            {
                                Display_printf(
                                        display, 0, 0,
                                        "\t [MQTT Thread] Queue is full");
                            }
                        }
                        else if ((strncmp(recvdMsg, "unlock",
                                          sizeof(queueElemRecv.msgLen)) == 0) && App_CB.locked)
                        {
                            queueElem.event = UNLOCK_MOTOR_CMD;
                            App_CB.locked = false;
                            if (Motor_SendMsgToQueue(&queueElem))
                            {
                                Display_printf(
                                        display, 0, 0,
                                        "\t [MQTT Thread] Queue is full");
                            }
                        }
                        else
                        {
                            Display_printf(display, 0, 0,
                                           "[MQTT Thread] Message: %s",
                                           recvdMsg);
                            Display_printf(
                                    display,
                                    0,
                                    0,
                                    "[MQTT Thread] Message ignored because lock is already in requested state or payload is invalid");
                            break;
                        }
                    }
                    else if (strncmp(tmpBuff, (const char*) topic[2],
                                     queueElemRecv.topLen) == 0)
                    {
                        char msg[30] = { '\0' };
    
                        strcpy(msg,
                               (App_CB.locked == true) ?
                               PUBLISH_TOPIC0_LOCKED :
                                                         PUBLISH_TOPIC0_UNLOCKED);
    
                        lRetVal = MQTTClient_publish(
                                App_CB.mqttClientHandle, (char*) publish_topic[0],
                                strlen((char*) publish_topic[0]), (char*) msg,
                                strlen((char*) msg),
                                MQTT_QOS_2 | ((RETAIN_ENABLE) ?
                                MQTT_PUBLISH_RETAIN :
                                                                0));
    
                        Display_printf(
                                display,
                                0,
                                0,
                                "\n\r [MQTT Thread] CC3200 Publishes the following message");
                        Display_printf(display, 0, 0, "[MQTT Thread] Topic: %s",
                                       publish_topic);
                        Display_printf(display, 0, 0, "[MQTT Thread] Data: %s",
                                       msg);
                    }
                    else if (strncmp(tmpBuff, (const char*) topic[3],
                                     queueElemRecv.topLen) == 0)
                    {
                        struct controlMsg controlMsg;
    
                        controlMsg.threadID = 1;
                        controlMsg.msg = CONTROL_MSG_OTA_START;
    
                        if (!GET_STATUS_BIT(App_CB.status,
                                            AppStatusBits_OtaInProgress))
                        {
                            mq_send(App_CB.controlQueue, (char *) &controlMsg,
                                    sizeof(struct controlMsg), NULL);
    
                            SET_STATUS_BIT(App_CB.status,
                                           AppStatusBits_OtaInProgress);
                        }
                    }
    
                    free(queueElemRecv.msgPtr);
                    break;
    
                    /* On-board client disconnected from remote broker, only      */
                    /* local MQTT network will work                               */
                case LOCAL_CLIENT_DISCONNECTION:
                    Display_printf(display, 0, 0,
                                   "\t [MQTT Thread] On-board Client Disconnected");
    
                    if(GET_STATUS_BIT(App_CB.status, AppStatusBits_Connection) && GET_STATUS_BIT(App_CB.status, AppStatusBits_IpAcquired))
                    {
                        MQTTClient_disconnect(App_CB.mqttClientHandle);
                        CLR_STATUS_BIT(App_CB.status, AppStatusBits_MqttConnected);
                        mqttState = MQTT_CLIENT_CONNECTING_TO_BROKER;
                    }
                    else
                    {
                        Mqtt_ClientStop(1);
                        mqttState = MQTT_LIB_INITIALIZATION;
                    }
                    break;
    
                case THREAD_TERMINATE_REQ:
                    Display_printf(display, 0, 0,
                                   "[MQTT Thread] Terminating MQTT Client");
    
                    SET_STATUS_BIT(App_CB.status, AppStatusBits_MqttStopInProgress);
                    Mqtt_ClientStop(1);
                    pthread_exit(0);
                    return NULL;
    
                default:
                    break;
                }
                break;
            }
            }
        }
    }
    
    //*****************************************************************************
    //
    //! MQTT_SendMsgToQueue - Utility function that receive msgQueue parameter and
    //! tries to push it the queue with minimal time for timeout of 0.
    //! If the queue isn't full the parameter will be stored and the function
    //! will return 0.
    //! If the queue is full and the timeout expired (because the timeout parameter
    //! is 0 it will expire immediately), the parameter is thrown away and the
    //! function will return -1 as an error for full queue.
    //!
    //! \param[in] struct msgQueue *queueElement
    //!
    //! \return 0 on success, -1 on error
    //
    //*****************************************************************************
    int32_t MQTT_SendMsgToQueue(struct msgQueue *queueElement)
    {
        struct timespec abstime = { 0 };
    
        clock_gettime(CLOCK_REALTIME, &abstime);
    
        if (App_CB.mqttQueue)
        {
            /* send message to the queue                                         */
            if (mq_timedsend(App_CB.mqttQueue, (char *) queueElement,
                             sizeof(struct msgQueue), 0, &abstime) == 0)
            {
                return 0;
            }
        }
        return -1;
    }
    
    int32_t MqttClient_start()
    {
        int32_t lRetVal = -1;
    
        int32_t threadArg = 100;
        pthread_attr_t pAttrs;
        struct sched_param priParam;
    
        MqttClientExample_params.clientId = ClientId;
        MqttClientExample_params.connParams = &Mqtt_ClientCtx;
        MqttClientExample_params.mqttMode31 = MQTT_3_1;
        MqttClientExample_params.blockingSend = true;
    
        /* Initialize MQTT client lib                                             */
        App_CB.mqttClientHandle = MQTTClient_create(MqttClientCallback,
                                                    &MqttClientExample_params);
        if (App_CB.mqttClientHandle == NULL)
        {
            /* Lib initialization failed */
            Display_printf(display, 0, 0,
                           "\t [MQTT Thread] Error - MQTT client handle is null");
            return -1;
        }
    
        /* Open Client Receive Thread start the receive task. Set priority and    */
        /* stack size attributes                                                  */
        pthread_attr_init(&pAttrs);
        priParam.sched_priority = 4;
        lRetVal = pthread_attr_setschedparam(&pAttrs, &priParam);
        lRetVal |= pthread_attr_setstacksize(&pAttrs, MQTT_CLIENT_RX_TASK_SIZE);
        lRetVal |= pthread_attr_setdetachstate(&pAttrs, PTHREAD_CREATE_DETACHED);
        lRetVal |= pthread_create(&g_rx_task_hndl, &pAttrs, MqttClientThread,
                                  (void *) &threadArg);
        if (lRetVal != 0)
        {
            Display_printf(display, 0, 0,
                           "[MQTT Thread] Client Thread create failed");
            return -1;
        }
    
        /* setting will parameters                                                */
        MQTTClient_set(App_CB.mqttClientHandle, MQTTClient_WILL_PARAM, &will_param,
                       sizeof(will_param));
        MQTTClient_set(App_CB.mqttClientHandle, MQTTClient_KEEPALIVE_TIME,
                       &mqttKeepAliveTimeout, sizeof(mqttKeepAliveTimeout));
    
        return 0;
    }
    
    //*****************************************************************************
    //!
    //! MQTT Client stop - Unsubscribe from the subscription topics and exit the
    //! MQTT client lib.
    //!
    //! \param  none
    //!
    //! \return None
    //!
    //*****************************************************************************
    
    void Mqtt_ClientStop(uint8_t disconnect)
    {
        uint32_t iCount;
    
        MQTTClient_UnsubscribeParams subscriptionInfo[SUBSCRIPTION_TOPIC_COUNT];
    
        for (iCount = 0; iCount < SUBSCRIPTION_TOPIC_COUNT; iCount++)
        {
            subscriptionInfo[iCount].topic = topic[iCount];
        }
    
        MQTTClient_unsubscribe(App_CB.mqttClientHandle, subscriptionInfo,
        SUBSCRIPTION_TOPIC_COUNT);
        for (iCount = 0; iCount < SUBSCRIPTION_TOPIC_COUNT; iCount++)
        {
            Display_printf(display, 0, 0,
                           "[MQTT Thread] Unsubscribed from the topic %s",
                           topic[iCount]);
        }
    
        CLR_STATUS_BIT(App_CB.status, AppStatusBits_MqttConnected);
        CLR_STATUS_BIT(App_CB.status, AppStatusBits_MqttInitialized);
    
        /* exiting the Client library                                             */
        MQTTClient_delete(App_CB.mqttClientHandle);
    
        Display_printf(display, 0, 0, "[MQTT Thread] MQTT Client Handle deleted");
    
        CLR_STATUS_BIT(App_CB.status, AppStatusBits_MqttStopInProgress);
    }
    
    void *MqttClientThread(void * pvParameters)
    {
        struct msgQueue queueElement;
        struct msgQueue queueElemRecv;
    
        MQTTClient_run((MQTTClient_Handle) pvParameters);
    
        /* Check if MQTT thread is already being stopped */
        if(!GET_STATUS_BIT(App_CB.status, AppStatusBits_MqttStopInProgress))
        {
            SET_STATUS_BIT(App_CB.status, AppStatusBits_MqttStopInProgress);
    
            queueElement.event = LOCAL_CLIENT_DISCONNECTION;
            queueElement.msgPtr = NULL;
    
            /* write message indicating disconnect Broker message.                    */
            if (MQTT_SendMsgToQueue(&queueElement))
            {
                Display_printf(
                        display,
                        0,
                        0,
                        "\t [MQTT Thread] Queue is full, throw first msg and send the new one");
                mq_receive(App_CB.mqttQueue, (char*) &queueElemRecv,
                           sizeof(struct msgQueue), NULL);
                MQTT_SendMsgToQueue(&queueElement);
            }
        }
    
        pthread_exit(0);
    
        return NULL;
    }
    

    什么错误代码是 MqttClient_subscribe()正在返回?-->我不知道如何检查它。 你能告诉我怎么做,高兴吗?

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    我在错误消息之后添加了一条打印语句,使用%d 返回 Int16_t

    它显示:537051569

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    这不奏效。 您需要使用一个变量来捕获对 MQTTClient_subscribe 的原始调用的返回值(如 ret =...) 并打印该变量。

    此致、

    Sarah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    您的意思是、我需要执行以下操作:

    RET =  MQTTClient_subscribe ();

    那么 、printf ret 在 tera 术语中是什么?

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    可以、但您需要使用句柄、订阅信息和主题计数调用完整的 MQTTClient_subscribe 命令。

    此致、

    Sarah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    它是-7

    谢谢、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    MQTT 库中的(-7)错误可能是 MQTT_PACKE_ERR_NOTCONN。 这是在订阅期间设备未从服务器获得响应的情况。

    您可以尝试另一个接入点或互联网连接吗? 某些公司网络将阻止某些网站或端口。

    此致、

    Sarah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    我正在使用家用 AP。 我有 两 个 Ubiquiti (型号:UAP-AC-Lite) AP、尝试了全部2个 AP、但仍然遇到相同的错误。  我有 几个谷歌家用产品连接到同一个 WiFi AP、没有任何问题。  

    您能建议一种我可以解决此问题的方法吗?

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    我随附的代码按预期工作。 如果这对您不起作用、则 您应 考虑在另一个设置上进行测试。

    e2e.ti.com/.../wifi_5F00_doorlock_5F00_CC3220S_5F00_LAUNCHXL_5F00_tirtos_5F00_ccs.zip

    e2e.ti.com/.../wifi_5F00_doolock_5F00_CC3220S_5F00_UniFlash.zip

    此致、

    Sarah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    感谢您分享您的代码。 遗憾的是、我仍然会得到相同的错误(-7)。

    现在我要查看我的 AP 设置。 您能推荐我应该查看的 AP 设置吗?

    谢谢、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    只需验证在覆盖.bin 文件时是否使用了运动场中的 dummy-trust-cert-key 即可   

    并使用以下文件名  

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    我使用了 dummy-root-ca-cert-key 和 dummy-root-ca-cert 您还可以从简单页面加载二进制文件、它将使用此密钥自动对映像进行签名。

    此致、

    Sarah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    使用了正确的键、但仍然出现相同的错误。 您能给我一个指针、说明在 AP 设置中应查看的内容吗?

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sarah、

    我注意到、以 tera 术语打印的时间不是我当地的时间。  

    提供了详细信息

    它说"如果不将 RTC 设置为当前网络时间、则可以连接到服务器
    否则设备可能会面临不安全的连接。"

    这是否是错误-7的根本原因?

    谢谢、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    是的、这可能会导致问题-您能否验证是否能够正确设置时间?  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Vincent:

    是否有教程教我如何验证它? 我在 wifi Doorlock_app.c 中找不到 setime()  

    谢谢、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

     您应该在示例中有一个 set time 函数-您可以在那里设置断点、然后查看此函数是在之后返回0还是错误代码。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Vincent:

    我在 network_if.c 的 network_if_settime()函数中将 setTime 更新为我的本地时间

    我的时间设置为我的本地时间、是正确的 、但是我仍然遇到-7错误。 您能给我一些有关如何解决此问题的指导吗? 就像 Sarah 说的那样、这是关于我的 AP 设置。 您能给我一些关于我应该查看什么设置的见解吗?

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您能找到哪个特定函数返回-7错误吗? 此外、您是否试用过其他 MQTT 代理?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Vincent:

    它是  MQTTClient_subscribe。 您是否有推荐 的代理?

    Sarah 说:" (-7)错误可能是 MQTT 库中的 MQTT_PACKE_ERR_NOTCONN。 如果设备在订阅期间没有收到服务器的响应、则会出现这种情况。"

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Vincent:

    我的第一个错误是"sl_socket_ASYNC_EVENT 套接字事件2、请重新启动"。 我搜索了表单并找到 了 https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/598998/cc3200-launchxl-sock-event-handler-sock-event---unexpected-event-20x-during-https-get

    建议使用最新的 SDK、但我下载并使用了 Sarah 的代码、因此 SDK 不会出现问题、对吧?

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    此错误通常在服务器没有响应时发生-我会尝试向代理或 IBM 发出蚊帐。 您还可以监听 Wi-Fi 流量、以便能够查看是否收到对服务器的响应。  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我现在正在 使用蚊帐。  

    地址:test.mosquitto.org

    端口:8883

    我还使用 https://test.mosquitto.org/中的.crt 文件

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    是否可以捕获 Wi-Fi 监听器对此的捕获?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    以前从未这么做过。 进行工作。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Vincent:

    这是从开始到-7错误的 WiFi 监听器捕获:

    Tera Term Display (Tera 术语显示):

    谢谢、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    您可以共享文件.pcap 捕获吗?

    谢谢、

    Vince  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    文件 attachede2e.ti.com/.../Wifi-capture.zip

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    谢谢您、我稍后将进行回顾并返回给您。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    您似乎在安全网络(WPA/WPA2)上捕获了这种情况。 是否可以将网络重新配置为打开和重新捕获?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    e2e.ti.com/.../Wifi-capture-_2D00_-open-network.zip

    给你

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    谢谢。 您的捕获数据缺失、或者您正在过滤此捕获数据、我看不到任何显示您连接到 AP 或尝试连接的数据包。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Vincent:

    这次我验证了 myTidevBoard 以 tera 术语连接到 AP

    和我的网络显示屏中

    e2e.ti.com/.../Wifi-capture-_2D00_-open-network_2D00_08272021.zip

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    查看这些捕获、我仍然看不到我们的器件连接到 AP、或者尝试发送数据。 您是否可以使用其他接入点或移动热点进行测试?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Vincent:

    我没有其他 AP 或热点可用。 我再次尝试 OOB 演示、一切正常。 我可以切换 D10、加速计工作正常。

     我的 AP 系统似乎没有网络问题。 我们是否可以在门锁示例中使用不同的协议?  

    谢谢、

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    我不确定原因-从您共享的日志中、设备似乎未连接到 AP。  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Vincent:

    我尝试了 agin

    似乎电路板在-7错误之前尝试进行通信。

    e2e.ti.com/.../Wifi-capture-_2D00_-open-network_2D00_08302021.zip 

    如果我的板不在说话、会导致这种情况的原因是什么?

    谢谢

    成  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    您的捕获仍然不显示与网络的连接、但确实显示您已连接、因为您正在发送这些特定的数据包。 您的监听器设置可能不正确、并且缺少数据包。