<?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>Sending SMS is blocking program execution in nRF9160</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55608/sending-sms-is-blocking-program-execution-in-nrf9160</link><description>Hi, 
 I&amp;#39;m using commands below to send SMS message in my application. SMS sending is working fine, but some reason during the AT+CMGS command program execution 
 Is blocked e.g. all the LEDs are stopped. CNMI mode is set to 3 so I just wondering is the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 16 Dec 2019 14:08:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55608/sending-sms-is-blocking-program-execution-in-nrf9160" /><item><title>RE: Sending SMS is blocking program execution in nRF9160</title><link>https://devzone.nordicsemi.com/thread/225681?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2019 14:08:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1add7cc0-af72-47a1-8741-5fcc0dcea24f</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;If you are not putting the modem in flight mode, or in offline mode, then there&amp;#39;s no need to send the AT+CFUN command. If you are; then you need to wait for the link to be established again.&lt;/p&gt;
&lt;p&gt;Q1: How is the device stuck? Do you get a fault or an assert? What is the log output?&lt;/p&gt;
&lt;p&gt;Q2: Have you tried the exact same in at_client, to see how it behaves there?&lt;/p&gt;
&lt;p&gt;Q3: Have you tried sending a static SMS, to see if the firmware hangs in the snprintf handling?&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: Sending SMS is blocking program execution in nRF9160</title><link>https://devzone.nordicsemi.com/thread/225629?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2019 12:37:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3dd85cb0-96c6-45d9-936f-e34cb872f781</guid><dc:creator>Juha</dc:creator><description>&lt;p&gt;Hi H&amp;aring;kon,&lt;/p&gt;
&lt;p&gt;Here is my main loop code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void main(void)
{
        
    
    #if defined(CONFIG_USE_UI_MODULE)
            ui_init(ui_evt_handler);
    #endif

    /*Put simulated data to GPS buffer,
      when the postion is found it will be replaced with real location data*/
    gps_cloud_data.data.buf = default_gps_data;
    gps_cloud_data.data.len = strlen(default_gps_data);
    gps_cloud_data.tag += 1;

    if (gps_cloud_data.tag == 0) {
        gps_cloud_data.tag = 0x1;
    }

    work_init();
    bp3901_nvs_init();
    bp3901_uart_init();
    modem_configure(); 

    while (true) {
        k_sleep(K_MSEC(5));
        //k_cpu_idle();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Modem configure function:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void modem_configure(void)
{
#if defined(CONFIG_BSD_LIBRARY)
    if (IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT)) {
        /* Do nothing, modem is already turned on
         * and connected.
         */
    } else {
        int err;

        printk(&amp;quot;Connecting to LTE network. &amp;quot;);
        printk(&amp;quot;This may take several minutes.\n&amp;quot;);
        ui_led_set_pattern(UI_LTE_CONNECTING);

        err = lte_lc_init_and_connect();
        if (err) {
                printk(&amp;quot;LTE link could not be established.\n&amp;quot;);
                error_handler(ERROR_LTE_LC, err);
        }

        printk(&amp;quot;Connected to LTE network\n&amp;quot;);
        lte_connected = true;
        ui_led_set_pattern(UI_LTE_CONNECTED);
        sensors_start();
    }
#endif
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best Regards&lt;/p&gt;
&lt;p&gt;Juha&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending SMS is blocking program execution in nRF9160</title><link>https://devzone.nordicsemi.com/thread/225625?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2019 12:31:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:499b440e-d7a8-413c-8379-0bf76985b006</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Juha,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you starting from a powered down state? If yes, then you should let the modem be able to successfully connect to the network before continuing with the rest of the sequence.&lt;/p&gt;
&lt;p&gt;See an example of this in the&amp;nbsp;mqtt_simple:&amp;nbsp;&lt;a href="https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/samples/nrf9160/mqtt_simple/src/main.c#L357"&gt;https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/samples/nrf9160/mqtt_simple/src/main.c#L357&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: Sending SMS is blocking program execution in nRF9160</title><link>https://devzone.nordicsemi.com/thread/225616?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2019 12:13:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:865a9b19-f2aa-4fbc-bb95-3c598e00764b</guid><dc:creator>Juha</dc:creator><description>&lt;p&gt;Hi H&amp;aring;kon,&lt;/p&gt;
&lt;p&gt;Yes, SMS sending is working. In the main program I will get trigger from my sensor driver and then I submit the SMS work to handle SMS sending.&lt;/p&gt;
&lt;p&gt;My trigger handler:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void trigger_handler(struct device *dev, struct sensor_trigger *trigger)
{
      ARG_UNUSED(dev);
      switch ((int)trigger-&amp;gt;type) {
      case SENSOR_BP3901_NOTIFICATION:
            ui_led_set_state(1, 1);
            if(gps_control_is_active()) {
                gps_control_disable();
            }
            
            k_delayed_work_submit(&amp;amp;sms_work, 250);
            break;
      case SENSOR_BP3901_DRDY_READY:
            if(gps_control_is_active()) {
                gps_control_disable();
            }
            k_delayed_work_submit(&amp;amp;data_work, K_NO_WAIT);
            break;
      default:
            printk(&amp;quot;Unknown trigger event %d\r\n&amp;quot;, trigger-&amp;gt;type);
            break;
      }      
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Work handler function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void BP3901_sms_fn(struct k_work *work) {

    int ret;
    char sms_msg[PDU_MAX_LEN];

    networtk_time_str = get_network_time();
    gps_cloud_data.tag = sys_rand32_get();

    ret = create_sms_indication_message(sms_msg, PDU_MAX_LEN);
    if(ret != 0) {
        printk(&amp;quot;SMS encode err=%d\n&amp;quot;, ret);
        return;
    }

    sms_send(sms_msg);

    if(!gps_control_is_active()) {
        gps_control_enable();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;SMS sending function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static int sms_send(const char *msg)
{
    int err;
    enum at_cmd_state state;
    static char at_resp[128];
    
    err = at_cmd_write(AT_CFUN, at_resp, AT_MAX_CMD_LEN, &amp;amp;state);
    if (err &amp;lt; 0) {
        printk(&amp;quot;Could not send AT command to modem: %s %d\n\r&amp;quot;, AT_CFUN, err);
    }

    err = at_cmd_write(AT_CNUM, at_resp, AT_MAX_CMD_LEN, &amp;amp;state);
    if (err &amp;lt; 0) {
        printk(&amp;quot;Could not send AT command to modem: %s %d\n\r&amp;quot;, AT_CNUM, err);                
    }

    err = at_cmd_write(AT_CEREG, at_resp, AT_MAX_CMD_LEN, &amp;amp;state);
    if (err &amp;lt; 0) {
        printk(&amp;quot;Could not send AT command to modem: %s %d\n\r&amp;quot;, AT_CEREG, err);                
    }
  
    err = at_cmd_write(AT_CNMI, at_resp, AT_MAX_CMD_LEN, &amp;amp;state);
    if (err &amp;lt; 0) {
        printk(&amp;quot;Could not send AT command to modem: %s %d\n\r&amp;quot;, AT_CNMI, err);        
    }

    /*err = at_cmd_write_with_callback(msg,
                                     sms_cmd_handler_fn,
				     &amp;amp;state);
    if (err &amp;lt; 0) {
        printk(&amp;quot;Could not send AT command to modem: %s %d\n\r&amp;quot;, &amp;quot;AT+CMGS&amp;quot;, err);
    }   
                                  */

    err = at_cmd_write(msg, at_resp, AT_MAX_CMD_LEN, &amp;amp;state);
    if (err &amp;lt; 0) {
        printk(&amp;quot;Could not send AT command to modem: %s %d\n\r&amp;quot;, &amp;quot;AT+CMGS&amp;quot;, err);
    }

    return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Part of creating the AT+CMGS&amp;nbsp; message:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;char sms_message_str[PDU_MAX_LEN];

n = sprintf(&amp;amp;sms_message_str[0],&amp;quot;%s&amp;quot;, &amp;quot;AT+CMGS=&amp;quot;);    
n += sprintf(&amp;amp;sms_message_str[n],&amp;quot;%d%s&amp;quot;, (pdu_len - (pdu[0]+1)) ,&amp;quot;\r&amp;quot;);    
for(int i = 0; i &amp;lt; pdu_len; i++)
     n +=sprintf(&amp;amp;sms_message_str[n], &amp;quot;%.2x&amp;quot;, pdu[i]);    
n += sprintf(&amp;amp;sms_message_str[n],&amp;quot;%s&amp;quot;, &amp;quot;\x1A&amp;quot;);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best Regards&lt;/p&gt;
&lt;p&gt;Juha&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending SMS is blocking program execution in nRF9160</title><link>https://devzone.nordicsemi.com/thread/225612?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2019 11:55:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f04342a2-fbb5-4adc-9073-9b50c698d927</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;&amp;nbsp;&lt;/p&gt;
[quote user=""]CNMI mode is set to 3 so I just wondering is the modem waiting some Ack from the network? How to send SMS without blocking the program execution?[/quote]
&lt;p&gt;If I understand correct, you are able to send SMS, but the AT command +CMGS hangs after sending one SMS.&lt;/p&gt;
&lt;p&gt;How are you implementing this in firmware?&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>