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

Socket poll in MQTT sample never waits? Is nrf_poll not fully working on nRF9160 yet?

I am working on a MQTT related application on nRF9160 DK, and grabbed mqtt_simple as a baseline for development.  All of my libraries are back at the last tagged releases: v1.13.99-ncs2 for Zephyr, and v0.3.0 for nrf/nrfxlib.

I have recently been investigating the fact that the call to "poll" in the main loop is never waiting even when there's nothing to be read.  I tried tracking back through the libraries to see what it was doing, but hit a blind wall when I got to nrf_poll in nrfxlib since that's only available as a pre-compiled library from what I've found.

I've tried this both with and without TLS enabled with the same result.

I looked through the git commits to nrfxlib after the tag and nothing looks relevant to this.

I first discovered this on my own application, but it also happens with an unmodified mqtt_simple.

Is it expected for nrfxlib socket polling to have the ability to wait yet?  Is there something wrong in the configuration or calling as done in mqtt_simple?

  • I took a guess that the asset_tracker application would be more polished since it is the primary sample for the nRF9160 DK, and discovered that it never calls poll or nrf_poll or any other version of poll for it's MQTT socket.  The socket reads are triggered from the main application loop as part of the call to nrf_cloud_process, which appears to always try and read data, regardless of whether any is available.  The main loop just calls k_sleep or k_cpu_idle depending on whether the logging feature is enabled.

    So, in my application, I just dropped a call to k_cpu_idle into the main loop and things appear saner.  I'm not sure what events cause k_cpu_idle to wake, but it is waking often enough for my very low data rate testing.  (i.e. maybe an MQTT packet every couple minutes, with EDRX enabled to keep the modem power low)

    I also left the call to poll/nrf_poll in place as well, just in case it was doing some sort of housekeeping on the socket, although the asset_tracker example doesn't do that, so I suspect it isn't necessary.

  • Hello, the bsd_os_timedwait() function is not implemented yet. It does nothing at the moment. That's probably the reason why the poll() function never waits at all.

Related