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

Warning passing data to mqttsn_client_publish

Hello,

Starting with the example of mqtt_sn_client_publisher in the nRF5 SDK for Thread and Zigbee and I want to publish an array of data like this one

uint8_t readInfo[] = {0xBB, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x7E};

in a MQTT topic. For doing so, I`m using the function which is used in the example:

mqttsn_client_publish(&m_client, m_topic.topic_id, &readInfo, sizeof(readInfo), &m_msg_id);

using my array and his lenght as parameters. The code compiles but in the line where I call the function, segger shows a warning about incompatible pointer types.

I can´t check if the broker receives the data because I`ve not the gateway currently set up.

Could anyone provide some example code or an explanation of how should I do to publish messages with more than one byte??

Thanks!

Alex

Parents
  • The code compiles but in the line where I call the function, segger shows a warning about incompatible pointer types.

    Post the complete text of the message - it usually includes a description of which parameter it's talking about, and why it thinks them "incompatible"

    Remember that an array name in C is, effectively, a pointer to the 1st element - so you don't need the &.

    If you do use the &, it should be &readInfo[0]

    http://c-faq.com/aryptr/index.html - in particualr, c-faq.com/.../aryptrequiv.html

  • The warning pointed to the third argument of the function which should be: 

    /**@brief Publishes data to given topic.  
     *
     * @param[inout] p_client       Pointer to initialized and connected client.
     * @param[in]    topic_id       Value of previously registered topic ID. 
     * @param[in]    p_payload      Data to be published.
     * @param[in]    payload_len    Length of data to be published.
     * @param[out]   msg_id         (optional) Pointer to message ID assigned to the message by client. 
     *
     * @return       NRF_SUCCESS if the publish request has been sent successfully.
     *               Otherwise error code is returned.
     */
    uint32_t mqttsn_client_publish(mqttsn_client_t * p_client,
                                   uint16_t          topic_id,
                                   const uint8_t   * p_payload,
                                   uint16_t          payload_len,
                                   uint16_t        * msg_id);

    Deleting the & did the trick and the warning is disabled now.

    Thank you!!

Reply
  • The warning pointed to the third argument of the function which should be: 

    /**@brief Publishes data to given topic.  
     *
     * @param[inout] p_client       Pointer to initialized and connected client.
     * @param[in]    topic_id       Value of previously registered topic ID. 
     * @param[in]    p_payload      Data to be published.
     * @param[in]    payload_len    Length of data to be published.
     * @param[out]   msg_id         (optional) Pointer to message ID assigned to the message by client. 
     *
     * @return       NRF_SUCCESS if the publish request has been sent successfully.
     *               Otherwise error code is returned.
     */
    uint32_t mqttsn_client_publish(mqttsn_client_t * p_client,
                                   uint16_t          topic_id,
                                   const uint8_t   * p_payload,
                                   uint16_t          payload_len,
                                   uint16_t        * msg_id);

    Deleting the & did the trick and the warning is disabled now.

    Thank you!!

Children
No Data
Related