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

How to receive SMS message in standby mode in nRF9160?

I want to wake up nRF9160 by SMS.

What I want to do:

The nRF9160 usually sleeps to reduce power consumption, and only when it receives SMS it wakes up and send some data by UDP or so.

I succeeded in implementing MQTT(+TLS), but have no experience to implement SMS function.

Any advice?

Parents Reply Children
  • This is draft code of what I want to do.

    /*
     * Copyright (c) 2018 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
     */
    
    #include <zephyr.h>
    #include <net/socket.h>
    #include <stdio.h>
    #include <uart.h>
    #include <string.h>
    
    /**@brief Recoverable BSD library error. */
    void bsd_recoverable_error_handler(uint32_t err)
    {
    	printk("bsdlib recoverable error: %u\n", err);
    }
    
    /**@brief Irrecoverable BSD library error. */
    void bsd_irrecoverable_error_handler(uint32_t err)
    {
    	printk("bsdlib irrecoverable error: %u\n", err);
    
    	__ASSERT_NO_MSG(false);
    }
    
    int blocking_recv(int fd, u8_t *buf, u32_t size, u32_t flags)
    {
    	int err;
    
    	do {
    		err = recv(fd, buf, size, flags);
    	} while (err < 0 && errno == EAGAIN);
    
    	return err;
    }
    
    int blocking_send(int fd, u8_t *buf, u32_t size, u32_t flags)
    {
    	int err;
    
    	do {
    		err = send(fd, buf, size, flags);
    	} while (err < 0 && errno == EAGAIN);
    
    	return err;
    }
    
    int blocking_connect(int fd, struct sockaddr *local_addr, socklen_t len)
    {
    	int err;
    
    	do {
    		err = connect(fd, local_addr, len);
    	} while (err < 0 && errno == EAGAIN);
    
    	return err;
    }
    
    void setup_sms()
    {
        char recv_buf[256 + 1];
        const char *at_commands[] = {<AT Commands that enables modem and SMS notification>};
    	int at_socket_fd = socket(AF_LTE, 0, NPROTO_AT);
    
    	printk("Starting simple AT socket application\n\r");
    
    	if (at_socket_fd < 0) {
    		printk("Socket err: %d, errno: %d\r\n", at_socket_fd, errno);
    	}
    	for (int i = 0; i < ARRAY_SIZE(at_commands); i++) {
            printk("%s\n", at_commands[i]);
    		int bytes_written = send(at_socket_fd, at_commands[i], strlen(at_commands[i]), 0);
    		if (bytes_written > 0) {
    			int r_bytes = blocking_recv(at_socket_fd, recv_buf, sizeof(recv_buf), MSG_DONTWAIT);
    			if (r_bytes > 0) {
    				printk("%s\n", recv_buf);
    			}
    		}
    	}
    	printk("Closing socket\n\r");
    	(void)close(at_socket_fd);
    }
    
    void main(void)
    {
    	printk("The SMS receiving sample started\n");
    	char sms_messsage[30];
        setup_sms();
    
        while(1){
            while(<no SMS message? = true>){
                <check if modem is on and SMS notification is on in some interval>;
                if(<modem is off of SMS notification is off>){
                    setup_sms();
                }
            }
            
            // if SMS received
            <store sms message to sms_messsage>;
            printk("SMS message is %s\n", sms_message);
        };
    
    }
    

  • The sample you link to is for sending sms. For receiving sms, you need to poll the AT socket. Try to use at_client, and see if you are able to get a sms successfully received. Note that you need a SIM card which has a phone number in order to send/receive sms.

     

    Kind regards,

    Håkon

  • Hi, Hakon.

    I can't receive SMS in eDRX. 

    When I set 82 sec interval, I hope nRF9160 check if it receives SMS in that interval, but it doesn't work.

    Does this mean SMS can't be received when you use eDRX?

  • Hi,

     

    Are you able to receive SMS successfully in other operating modes?

    Is it just eDRX that is the problem?

     

    Kind regards,

    Håkon

  • Yea, I can receive SMS in normal mode without PSM or eDRX.
    I use at_client program and hologram SIM. The SIM allows you to send SMS.

Related