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

How to to set a keep alive value of MQTT while eDRX is enabled in nRF9160?

I want to set a keep alive value of MQTT while eDRX is enabled, but it doesn't work well. Any advice?

Environment
- hardware: nRF9160 DK 0.8.2
- firmware: 0.7.0-29.alpha
- nrf ver: 0.4.0
- LTE-M
- eDRX enable
- mqtt_simple works fine with mosquitto MQTT broker
- project based on mqtt_simple
- antenna power is fine
- eDRX service is available here

Fullscreen
1
2
3
AT+CEDRXS?
OK
AT+CEDRXS=1,4,"1000"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I added MQTT_KEEPALIVE param to Kconfig and CONF_MQTT_KEEPALIVE param to pro.conf
I've tested several conditions
[condition]
- CONFIG_LTE_EDRX_REQ_VALUE="0110" in prj.conf // 327.68 sec interval
CONF_MQTT_KEEPALIVE=300 in prj.conf
[result]
eDRX doesn't work properly. When I send a message to a MQTT broker, the DK receives it right after that. There should be a delay due to the eDRX.

[condition]
CONFIG_LTE_EDRX_REQ_VALUE="0110" in prj.conf // 327.68 sec interval
CONF_MQTT_KEEPALIVE=400 in prj.conf
[result]
The DK does not receive any message after 360sec followed by disconnection.

This is the whole project.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<Kconfig>
menu "MQTT simple sample"
config MQTT_PUB_TOPIC
string "MQTT publish topic"
default "my/publish/topic"
config MQTT_SUB_TOPIC
string "MQTT subscribe topic"
default "my/subscribe/topic"
config MQTT_CLIENT_ID
string "MQTT Client ID"
default "my-client-id"
config MQTT_BROKER_HOSTNAME
string "MQTT broker hostname"
default "iot.eclipse.org"
config MQTT_BROKER_PORT
int "MQTT broker port"
default 1883
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<prj.conf>
# 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_NETWORK_MODE_LTE_M=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
# CONFIG_LTE_EDRX_REQ_ACTT_TYPE="4"
CONFIG_LTE_EDRX_REQ=y
CONFIG_LTE_EDRX_REQ_VALUE="0110"
# 0100 81.92sec
# 0101 163.84sec
# 0110 327.68sec
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<main.c>
#include <zephyr.h>
#include <stdio.h>
#include <uart.h>
#include <string.h>
#include <net/mqtt.h>
#include <net/socket.h>
#include <lte_lc.h>
#define MQTT_USERNAME "username"
#define MQTT_PASSWORD "password"
.
.
.
/**@brief Initialize the MQTT client structure
*/
static void client_init(struct mqtt_client *client)
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This is a test condition.
Ideally, I want to set a longer keepalive value, like 1200(sec) to decrease power consumption.
- keep alive of MQTT: 1200 sec
- eDRX interval value: 655 sec

I have been struggling with this issue more than two weeks, but I don't really get the eDRX behavior. Any advice?