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
  • I've already checked the link below, but I don't really get what each line means.
    devzone.nordicsemi.com/.../sending-sms-using-at_client-example

    This is my understanding.

    ----------------
    AT+CFUN=1
    => Turn on the modem. The modem can receive SMS at any time.

    AT+CPIN="1234"
    => Set Pin number, which is a password of SIM.

    AT+CNMI=3,2,0,1
    => Configure the process of receving SMS.
    ----------------

    After this setting, MCU can go to sleep to wait until SMS is received. When SMS is received, MCU wakes up.

    Is this correct? I'm not familiar with SMS function. Sorry for poor skill.

  • 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);
        };
    
    }
    

Reply
  • 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);
        };
    
    }
    

Children
No Data
Related