<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>NRF9160 poll()</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/58611/nrf9160-poll</link><description>Hello guys, 
 I`m pretty new in socket programing, I have a question , is there any way to trigger an event for a file descriptor that is used in poll() function ? 
 For example: when a timer expires I want to trigger an event that will be catched by</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 03 Mar 2020 14:18:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/58611/nrf9160-poll" /><item><title>RE: NRF9160 poll()</title><link>https://devzone.nordicsemi.com/thread/237802?ContentTypeID=1</link><pubDate>Tue, 03 Mar 2020 14:18:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15ffd6cf-e636-4b96-9729-630d77690248</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>[quote user="Adev"]Thank you very much ![/quote]
&lt;p&gt;&amp;nbsp;You&amp;#39;re welcome &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m glad to hear that it worked!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 poll()</title><link>https://devzone.nordicsemi.com/thread/237801?ContentTypeID=1</link><pubDate>Tue, 03 Mar 2020 14:18:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ec8cfd4-2ffe-4acc-81ce-5311eb5aedfe</guid><dc:creator>Adev</dc:creator><description>&lt;p&gt;Thank you very much ! It works.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 poll()</title><link>https://devzone.nordicsemi.com/thread/237740?ContentTypeID=1</link><pubDate>Tue, 03 Mar 2020 12:51:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7b56068-442a-4c55-93a1-a2c69328808e</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Then you can start a system work queue from the interrupt context:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.zephyrproject.org/1.9.0/kernel/threads/workqueues.html#system-workqueue"&gt;https://docs.zephyrproject.org/1.9.0/kernel/threads/workqueues.html#system-workqueue&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 poll()</title><link>https://devzone.nordicsemi.com/thread/237720?ContentTypeID=1</link><pubDate>Tue, 03 Mar 2020 12:26:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8853501-66cb-4b46-a6fb-7889b0bae9e5</guid><dc:creator>Adev</dc:creator><description>&lt;p&gt;Yes that`s the first thing I tried, that worked but in main also I have the poll function with an timeout of 60 seconds, so I will have to wait for 60 seconds ( in worst case) every time I want to publish something :( .&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 poll()</title><link>https://devzone.nordicsemi.com/thread/237717?ContentTypeID=1</link><pubDate>Tue, 03 Mar 2020 12:24:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df6e55c8-1478-4b2c-bf44-617a0fc1858e</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Try scheduling the uart message to main context.&lt;/p&gt;
&lt;p&gt;The &amp;quot;uart_callback&amp;quot; (you might have named it differently) will inherit the interrupt, and a socket based call doesn&amp;#39;t work when called from interrupt functions.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The simplest way to schedule to main is to set a global boolean flag, like this pseudo code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;volatile bool uart_command_received;
u8_t my_uart_buffer[SOME_SIZE];

void uart_cb(..)
{
   /* if uart string received */
   uart_command_received = true;
   /* Copy to global buffer */
   memcpy(my_uart_buffer, buf, received_size);
}

int main(void)
{
....
  while (1)
    if (uart_command_received == true) {
      uart_command_received = false;
      u32_t ret = mqtt_publish(..);
      if (ret &amp;lt; 0) {
        /*handle errror*/
    }
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 poll()</title><link>https://devzone.nordicsemi.com/thread/237709?ContentTypeID=1</link><pubDate>Tue, 03 Mar 2020 12:05:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c7613a1-09e3-4c30-aa46-115640d913bc</guid><dc:creator>Adev</dc:creator><description>&lt;p&gt;Hello, I was working on this example, the operation I want to do is to recieve an message over serial and send it with mqtt_publish, the problem is that after I catch the message from serial in uart interruption,&amp;nbsp;I call mqtt_publish and it get stucked there because whe are in ist and poll does not recieve socket events, the only solution I see is to declare another socket for serial messaging but I can`t figure how to trigger an event for this socket.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 poll()</title><link>https://devzone.nordicsemi.com/thread/237705?ContentTypeID=1</link><pubDate>Tue, 03 Mar 2020 11:50:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:799296b8-dcb9-4c62-8f12-5e2676026583</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A good place to start when you&amp;#39;re new to socket based APIs is to check the manuals in linux, by entering &amp;quot;&lt;a href="http://man7.org/linux/man-pages/man2/poll.2.html"&gt;man poll&lt;/a&gt;&amp;quot;, or just googling &amp;quot;man &amp;lt;some socket operation&amp;gt;&amp;quot;.&lt;/p&gt;
&lt;p&gt;poll returned events cannot be a specific timer, but you can give poll() an input timeout, as done here in mqtt_simple:&amp;nbsp;&lt;a href="https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/samples/nrf9160/mqtt_simple/src/main.c#L407"&gt;https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/samples/nrf9160/mqtt_simple/src/main.c#L407&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>