nRF9161-DK SMS sample. message not receiving to controller on time

Hello all smart people.

Currently I am working with SMS sample and I want to toggle LED with pwm after receiving message, but I can not get sms on the "live" only after restart I see that message is received on terminal.

What did I wrong or how to get sms on controller live time?

Thank you, fizz drink on me

/*
 * Copyright (c) 2021 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */
 
#include <stdio.h>
#include <zephyr/kernel.h>
#include <string.h>
#include <modem/sms.h>
#include <modem/nrf_modem_lib.h>
#include <modem/lte_lc.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/pwm.h>
 
static struct k_work sms_workk;
 
static const struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
 
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   2500
 
/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)
 
/*
 * A build error on this line means your board is unsupported.
 * See the sample documentation for information on how to fix this.
 */
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
 
 
static void sms_callback(struct sms_data *const data, void *context)
{
    if (data == NULL) {
        printk("%s with NULL data\n", __func__);
        return;
    }
 
    if (data->type == SMS_TYPE_DELIVER) {
        gpio_pin_toggle_dt(&led);//
        /* When SMS message is received, print information */
        struct sms_deliver_header *header = &data->header.deliver;
 
        printk("\nSMS received:\n");
        printk("\tTime:   %02d-%02d-%02d %02d:%02d:%02d\n",
            header->time.year,
            header->time.month,
            header->time.day,
            header->time.hour,
            header->time.minute,
            header->time.second);
 
        printk("\tText:   '%s'\n", data->payload);
        printk("\tLength: %d\n", data->payload_len);
 
        if (header->app_port.present) {
            printk("\tApplication port addressing scheme: dest_port=%d, src_port=%d\n",
                header->app_port.dest_port,
                header->app_port.src_port);
        }
        if (header->concatenated.present) {
            printk("\tConcatenated short message: ref_number=%d, msg %d/%d\n",
                header->concatenated.ref_number,
                header->concatenated.seq_number,
                header->concatenated.total_msgs);
        }
    } else if (data->type == SMS_TYPE_STATUS_REPORT) {
        printk("SMS status report received\n");
    } else {
        printk("SMS protocol message with unknown type received\n");
    }
}
 
int main(void)
{
    int handle = 0;
    int ret = 0;
    uint32_t period = 1000000U;
    uint32_t pulse_width = period/100*100;
    uint32_t dummy =0;
 
    printk("\nSMS sample starting\n");
 
    ret = nrf_modem_lib_init();
    if (ret) {
        printk("Modem library initialization failed, error: %d\n", ret);
        return 0;
    }
 
    ret = lte_lc_connect();
    if (ret) {
        printk("Lte_lc failed to initialize and connect, err %d", ret);
        return 0;
    }
 
    handle = sms_register_listener(sms_callback, NULL);
    if (handle) {
        printk("sms_register_listener returned err: %d\n", handle);
        return 0;
    }
 
    printk("SMS sample is ready for receiving messages\n");
 
    /* Sending is done to the phone number specified in the configuration,
     * or if it's left empty, an information text is printed.
     */
    if (strcmp(CONFIG_SMS_SEND_PHONE_NUMBER, "")) {
        printk("Sending SMS: number=%s, text=\"SMS sample: testing\"\n",
            CONFIG_SMS_SEND_PHONE_NUMBER);
        ret = sms_send_text(CONFIG_SMS_SEND_PHONE_NUMBER, "SMS sample: testing");
        if (ret) {
            printk("Sending SMS failed with error: %d\n", ret);
        }
    } else {
        printk("\nSMS sending is skipped but receiving will still work.\n"
            "If you wish to send SMS, please configure CONFIG_SMS_SEND_PHONE_NUMBER\n");
    }
 
    if (!gpio_is_ready_dt(&led)) {
        return 0;
    }
 
    ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
    if (ret < 0) {
        return 0;
    }
 
    /* if (!pwm_is_ready_dt(&pwm_led0)) {
        printk("Error: PWM device %s is not ready\n",
               pwm_led0.dev->name);
        return 0;
    }  
 
    ret = pwm_set_dt(&pwm_led0, period, pulse_width);
    if (ret) {
        printk("Error %d: failed to set pulse width\n", ret);
        return 0;
    } */
 
    for(;;)
    {      
        //ret = pwm_set_pulse_dt(&pwm_led0, pulse_width);
        k_msleep(SLEEP_TIME_MS);
        dummy++;
    }
 
    /* In our application, we should unregister SMS in some conditions with:
     *   sms_unregister_listener(handle);
     * However, this sample will continue to be registered for
     * received SMS messages and they can be seen in serial port log.
     */
    return 0;
}

Parents
  • Hi,

    It's possible that the modem has gone into a power saving mode (such as PSM), where it has turned the radio off for a while.

    Can you enable some more logging, so that we can check if that is the case?

    CONFIG_LTE_LINK_CONTROL_LOG_LEVEL_DBG=y

    Best regards,

    Didrik

  • where should I place that? :D I do not find this parameter

  • SMS sample starting
    [00:00:00.673,370] <dbg> lte_lc: lte_lc_system_mode_set: System mode set to 7, preference 3
    [00:00:00.673,431] <dbg> lte_lc: lte_lc_psm_param_set: RPTAU set to 00000011
    [00:00:00.673,492] <dbg> lte_lc: lte_lc_psm_param_set: RAT set to 00100001
    [00:00:00.673,553] <dbg> lte_lc: on_modem_init: PSM configs set from string: tau=00000011, rat=00100001
    [00:00:00.673,614] <dbg> lte_lc: lte_lc_psm_req: enable=0, tau=00000011, rat=00100001
    [00:00:00.734,497] <dbg> lte_lc: lte_lc_on_modem_cfun: CFUN monitor callback: 0x17969
    [00:00:02.149,139] <dbg> lte_lc: at_handler_cereg: +CEREG notification: +CEREG: 2,"1FA4","02C53D11",7
    [00:00:02.149,383] <dbg> lte_lc: parse_cereg: Network registration status: 2
    [00:00:02.149,414] <dbg> lte_lc: parse_cereg: LTE mode: 7
    [00:00:02.216,064] <dbg> lte_lc: at_handler_cscon: +CSCON notification
    [00:00:03.115,539] <dbg> lte_lc: at_handler_cereg: +CEREG notification: +CEREG: 1,"1FA4","02C53D11",7,,,"11100000","11100000"
    [00:00:03.115,814] <dbg> lte_lc: parse_cereg: Network registration status: 1
    [00:00:03.115,875] <dbg> lte_lc: parse_cereg: LTE mode: 7
    SMS sample is ready for receiving messages
    Sending SMS: number=NUMBER123, text="SMS sample: testing"
    SMS status report received
    [00:00:09.109,649] <dbg> lte_lc: at_handler_cscon: +CSCON notification

    Sorry I am not familiar with those commands 

Reply
  • SMS sample starting
    [00:00:00.673,370] <dbg> lte_lc: lte_lc_system_mode_set: System mode set to 7, preference 3
    [00:00:00.673,431] <dbg> lte_lc: lte_lc_psm_param_set: RPTAU set to 00000011
    [00:00:00.673,492] <dbg> lte_lc: lte_lc_psm_param_set: RAT set to 00100001
    [00:00:00.673,553] <dbg> lte_lc: on_modem_init: PSM configs set from string: tau=00000011, rat=00100001
    [00:00:00.673,614] <dbg> lte_lc: lte_lc_psm_req: enable=0, tau=00000011, rat=00100001
    [00:00:00.734,497] <dbg> lte_lc: lte_lc_on_modem_cfun: CFUN monitor callback: 0x17969
    [00:00:02.149,139] <dbg> lte_lc: at_handler_cereg: +CEREG notification: +CEREG: 2,"1FA4","02C53D11",7
    [00:00:02.149,383] <dbg> lte_lc: parse_cereg: Network registration status: 2
    [00:00:02.149,414] <dbg> lte_lc: parse_cereg: LTE mode: 7
    [00:00:02.216,064] <dbg> lte_lc: at_handler_cscon: +CSCON notification
    [00:00:03.115,539] <dbg> lte_lc: at_handler_cereg: +CEREG notification: +CEREG: 1,"1FA4","02C53D11",7,,,"11100000","11100000"
    [00:00:03.115,814] <dbg> lte_lc: parse_cereg: Network registration status: 1
    [00:00:03.115,875] <dbg> lte_lc: parse_cereg: LTE mode: 7
    SMS sample is ready for receiving messages
    Sending SMS: number=NUMBER123, text="SMS sample: testing"
    SMS status report received
    [00:00:09.109,649] <dbg> lte_lc: at_handler_cscon: +CSCON notification

    Sorry I am not familiar with those commands 

Children
Related