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

What does poll function do in mqtt_simple sample program in nRF9160?

I have been studying MQTT these days.

I'm testing the program below.
https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/samples/nrf9160/mqtt_simple/src/main.c

In this sample program, poll function is used on line 370. I guess it waits for an incoming data for an assigned duration, CONFIG_MQTT_KEEPALIVE.

However, it does not wait at all even though no data comes. Why? I'm confused.

Parents Reply
  • Thank you for your reply.

    I'm using this code below: tag/v0.4.0.
    https://github.com/NordicPlayground/fw-nrfconnect-nrf

    after poll function. this message comes up.

    	while (1) {
    		err = poll(&fds, 1, K_SECONDS(CONFIG_MQTT_KEEPALIVE));
    		if (err < 0) {
    			printk("ERROR: poll %d\n", errno);
    			break;
    		}
    
            printk("after poll\n"); // ADD THIS LINE
    
    		err = mqtt_live(&client);
    		if (err != 0) {
    			printk("ERROR: mqtt_live %d\n", err);
    			break;
    		}

    ***** Booting Zephyr OS v1.14.99-ncs1 *****
    The MQTT simple sample started
    LTE Link Connecting ...
    LTE Link Connected!
    IPv4 Address found 0xxxxxxxxx
    after poll
    [mqtt_evt_handler:169] MQTT client connected!
    Subscribing to: mySubTopic len 10
    after poll
    [mqtt_evt_handler:219] SUBACK packet id: 1234
    after poll
    after poll
    after poll
    after poll

    I see it's working. "After poll" shows up every 60sec

    By the way, in this polling, MCU is sleeping? I care about power consumption during polling.

Children
Related