This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

mqtt_simple connect to AWS

I have an AWS account and I am comfortable with the AWS IOT operation in general. I have used it in the past. I am trying to get the sample mqtt_simple to connect to AWS IOT and be able to send packets and receive packets to the nRF9160dk board.

 I am not sure how to set up mqtt_simple parameters? I have created a thing and certificates. I have named the thing "nrf-IMEI" as recommended so it has the board ID in it. All I want to do is to be able to publish a packet to a topic on my AWS account and receive a packet from a topic in my AWS account. I have done this several times in the past with other systems so I am comfortable with AWS IOT operations and formats. I just do not understand how to get mqtt_simple to publish from my board to AWS and subscribe to messages from AWS.

Is this the correct program to use. It seems like all the pieces are there I just do not know how to use them.

I appreciate any help you can give, This is an essential requirement of our production system. right now we are using the pre-production system with a modified version of asset_tracker to send sensor data to the nRF Connect site. We need to be able to send sensor data to our AWS site.

Parents
  • client_init was changed to the following and CONFIG_MQTT_LIB_TLS was set to y in prj.conf. I also added the following at the top of the code

    #if defined(CONFIG_MQTT_LIB_TLS)
    static sec_tag_t sec_tag_list[] = { CONFIG_CLOUD_CERT_SEC_TAG };
    #define CONFIG_PEER_VERIFY 0
    #endif /* defined(CONFIG_MQTT_LIB_TLS) */


    /**@brief Initialize the MQTT client structure
    */
    static void client_init(struct mqtt_client *client)
    {
    mqtt_client_init(client);

    broker_init();

    /* MQTT client configuration */
    client->broker = &broker;
    client->evt_cb = mqtt_evt_handler;
    client->client_id.utf8 = (u8_t *)CONFIG_MQTT_CLIENT_ID;
    client->client_id.size = strlen(CONFIG_MQTT_CLIENT_ID);
    client->password = NULL;
    client->user_name = NULL;
    client->protocol_version = MQTT_VERSION_3_1_1;

    /* MQTT buffers configuration */
    client->rx_buf = rx_buffer;
    client->rx_buf_size = sizeof(rx_buffer);
    client->tx_buf = tx_buffer;
    client->tx_buf_size = sizeof(tx_buffer);

    #if defined(CONFIG_MQTT_LIB_TLS)
    struct mqtt_sec_config *tls_config = &client->transport.tls.config;

    client->transport.type = MQTT_TRANSPORT_SECURE;

    tls_config->peer_verify = CONFIG_PEER_VERIFY;
    tls_config->cipher_count = 0;
    tls_config->cipher_list = NULL;
    tls_config->sec_tag_count = ARRAY_SIZE(sec_tag_list);
    tls_config->sec_tag_list = sec_tag_list;
    tls_config->hostname = CONFIG_MQTT_BROKER_HOSTNAME;
    #else /* MQTT transport configuration */
    client->transport.type = MQTT_TRANSPORT_NON_SECURE;
    #endif /* defined(CONFIG_MQTT_LIB_TLS) */
    }

Reply
  • client_init was changed to the following and CONFIG_MQTT_LIB_TLS was set to y in prj.conf. I also added the following at the top of the code

    #if defined(CONFIG_MQTT_LIB_TLS)
    static sec_tag_t sec_tag_list[] = { CONFIG_CLOUD_CERT_SEC_TAG };
    #define CONFIG_PEER_VERIFY 0
    #endif /* defined(CONFIG_MQTT_LIB_TLS) */


    /**@brief Initialize the MQTT client structure
    */
    static void client_init(struct mqtt_client *client)
    {
    mqtt_client_init(client);

    broker_init();

    /* MQTT client configuration */
    client->broker = &broker;
    client->evt_cb = mqtt_evt_handler;
    client->client_id.utf8 = (u8_t *)CONFIG_MQTT_CLIENT_ID;
    client->client_id.size = strlen(CONFIG_MQTT_CLIENT_ID);
    client->password = NULL;
    client->user_name = NULL;
    client->protocol_version = MQTT_VERSION_3_1_1;

    /* MQTT buffers configuration */
    client->rx_buf = rx_buffer;
    client->rx_buf_size = sizeof(rx_buffer);
    client->tx_buf = tx_buffer;
    client->tx_buf_size = sizeof(tx_buffer);

    #if defined(CONFIG_MQTT_LIB_TLS)
    struct mqtt_sec_config *tls_config = &client->transport.tls.config;

    client->transport.type = MQTT_TRANSPORT_SECURE;

    tls_config->peer_verify = CONFIG_PEER_VERIFY;
    tls_config->cipher_count = 0;
    tls_config->cipher_list = NULL;
    tls_config->sec_tag_count = ARRAY_SIZE(sec_tag_list);
    tls_config->sec_tag_list = sec_tag_list;
    tls_config->hostname = CONFIG_MQTT_BROKER_HOSTNAME;
    #else /* MQTT transport configuration */
    client->transport.type = MQTT_TRANSPORT_NON_SECURE;
    #endif /* defined(CONFIG_MQTT_LIB_TLS) */
    }

Children
Related