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

NRF9160 poll()

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 my poll() function. 

I searched almost everywhere and did not found anything. 

Thank you. 

Parents Reply
  • Try scheduling the uart message to main context.

    The "uart_callback" (you might have named it differently) will inherit the interrupt, and a socket based call doesn't work when called from interrupt functions.

     

    The simplest way to schedule to main is to set a global boolean flag, like this pseudo code:

    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 < 0) {
            /*handle errror*/
        }
      }
    }

     

    Kind regards,

    Håkon

Children
Related