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

customize publish function in mqtt sample

Hi, I  am currently testing the MQTT Communication with our IoT-Platform. 

I am successfully connected to the broker and I am able to receive messages from the subscribed topic. 

Now I want to publish my own messages and not just reply the received message from the subscribe function. 

Therefore I need to know how to edit the data_publish function and subsequently the MQTT_EVT_PUBLISH case in the mqtt_simple sample. 

Thanks in advance and best regards, 

Manuel

Parents Reply
  • Hi, 

    yes, ofc I can call this and it is being successfully published, but I would like to call it on a event, for example on button press. Or publish the current button state.

    In would have used gpio_pin_read in while (1) and the use the data_publish function, but that does not work. 

    while (1) {
    
                    u32_t val = 0;
                    gpio_pin_read(gpiob, PIN, &val);
                    printk("Button: %d\n", val);
    
                    char buffer[2];
    
                    
                    data_publish(&client, MQTT_QOS_1_AT_LEAST_ONCE,sprintf(buffer,"%u",val), 1);

    Also tried it without conversion to string. 

    Do you have a better solution how to solve that? 

    Thanks!

Children
Related