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

nRF9160 MQTT + TLS + PSM

Hi,

I have build a application based on the mqtt-simple-sample and successfully integrated TLS.

Now I wanted to measure the floor current in PSM. I did wait some minutes after my application aborted the

mqtt-session and measured a floor current of 980 uAs, what seems way to high in my opinion. In comparison, I measured

a current of 50 uAs with an empty application in PSM and a floor current of 100 uAs in my application without the use of TLS.

Is it normal, that the current consumption is so much higher through the use of TLS or did I missed something in the configs

or the application flow?

My prj.conf files:

#SPM config

CONFIG_IS_SPM=y
CONFIG_GPIO=n

CONFIG_SERIAL=n
CONFIG_UART_CONSOLE=n




#MQTT config

# General config
CONFIG_TEST_RANDOM_GENERATOR=y

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

# BSD library
CONFIG_BSD_LIBRARY=y

# AT Host
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=n

# MQTT
CONFIG_BSD_LIBRARY_TRACE_ENABLED=n
CONFIG_POWER_OPTIMIZATION=y
CONFIG_SERIAL=n
CONFIG_UART_CONSOLE=n
CONFIG_PROVISION_CERTIFICATES=y
CONFIG_GPIO=n
CONFIG_LOG=n
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_NEWLIB_LIBC=n
CONFIG_MQTT_LIB=y
CONFIG_MQTT_LIB_TLS=y
CONFIG_MQTT_KEEPALIVE=300
CONFIG_LTE_LEGACY_PCO_MODE=y
CONFIG_LTE_NETWORK_MODE_NBIOT=y
CONFIG_LTE_PSM_REQ=y
CONFIG_LTE_PSM_REQ_RPTAU="10101010"
CONFIG_LTE_PSM_REQ_RAT="00100001"

# Application
#CONFIG_MQTT_PUB_TOPIC="/my/publish/topic"
#CONFIG_MQTT_SUB_TOPIC="/my/subscribe/topic"
#CONFIG_MQTT_CLIENT_ID="my-client-id"
#CONFIG_MQTT_BROKER_HOSTNAME="test.mosquitto.org"
#CONFIG_MQTT_BROKER_PORT=8883

# Main thread
CONFIG_MAIN_THREAD_PRIORITY=7
CONFIG_MAIN_STACK_SIZE=4096

CONFIG_HEAP_MEM_POOL_SIZE=1024

# Disable native network stack to save some memory
CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=n
CONFIG_NET_UDP=n
CONFIG_NET_TCP=n

And the main:

void main(void) {

	volatile int err;
    u32_t turner = 0;
    volatile static int init_cnt = 0;

    provision_certificate();
    k_timer_init(&my_timer, my_expiry_function, NULL);
    buttons_leds_init();
	modem_configure();
	err = lte_lc_psm_req(true);
    if(err != 0) {
        dk_set_leds_state(0x00, DK_LED1_MSK);
    } else {
        dk_set_leds_state(DK_LED1_MSK, 0x00);
    }
	client_init(&client);

	while (1) {
	
        if(btn_flag > 0) {
            k_timer_start(&my_timer, K_SECONDS(TIMER_INTERVAL_SEC), K_SECONDS(TIMER_INTERVAL_SEC));
            timer_flag = 0;
            err = mqtt_connect(&client);
            if (err != 0) {
                dk_set_leds_state(0x00, DK_LED2_MSK);
            } else {
                dk_set_leds_state(DK_LED2_MSK, 0x00);
            }
            fds_init(&client);
			btn_flag = 0;
        }
            
        if(timer_flag == 0) {
            if(msg_flag == 1) {
				timer_cnt = 0;
            }
            err = poll(&fds, 1, K_SECONDS(CONFIG_MQTT_KEEPALIVE));
            err = mqtt_live(&client);
            if ((fds.revents & POLLIN) == POLLIN) {
                if(init_cnt < 2) {
					err = mqtt_input(&client);
					if (err != 0) {
						break;
					}
					init_cnt++;
                } 
                if(init_cnt == 2) {
                    button_handler(turner, 0x1);
                    init_cnt++;
                }
                if(msg_flag == 1) {
                    err = mqtt_input(&client);
					if (err != 0) {
						break;
					}
                }
            }
            if ((fds.revents & POLLERR) == POLLERR) {
				printk("POLLERR\n");
            }
            if ((fds.revents & POLLNVAL) == POLLNVAL) {
                printk("POLLNVAL\n");
            }
        } else if(timer_flag == 1) {
            err = mqtt_abort(&client);
            if(err != 0) {
                //
            } else {
                k_timer_stop(&my_timer);
                dk_set_leds_state(0x00, DK_LED1_MSK);
                k_sleep(1000);
                init_cnt = 0;
                timer_cnt = 0;
                timer_flag = 2;
                dk_set_leds_state(DK_ALL_LEDS_MSK, 0x00);
            }
        }
            
        k_sleep(1000);

	}
}

Thanks in advance and best regards.

Parents Reply Children
No Data
Related