nrf9160 - lwm2m_Client (queue mode)

Good day

I am currently trying to a create a lwm2m client to use with my custom board.  When I have queue mode enabled and the device is sleeping, i use the lwm2m_send function and get a very high power consumption.  I have found  that the program hangs before getting this on the logging:

 [00:19:30.532,806] <inf> net_lwm2m_engine: Connected, sock id 0

I have also attributed this to:

zsock_connect(client_ctx->sock_fd&client_ctx->remote_addraddr_len
when the client attempts to re-establish a connection   (lwm2m_engine_connection_resume), this function takes a while to complete it causes the high power consumption.  For a better understanding, I will post the power consumption while using and not using queue mode:
I have noticed that in queue mode,  a registration update is triggered.  However, the high power consumption occurs during the above mentioned process.  Is there a way that I can avoid as queue mode is essential for my project as I would like to send requests from the server while the device is sleeping.
Thank you in advance
Kind regards,
Hassan
Parents Reply Children
  • Hi Michal

    I have a nrf9160DK and im using it as a JLink programmer.  I can use it for RTT logging fine but when I try to do the same thing to get a modem trace, I don't receive anything through the trace.

    My prj file looks like this:

    # General config
    CONFIG_NEWLIB_LIBC=y
    CONFIG_ASSERT=y
    CONFIG_REBOOT=y
    
    # Network
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=n
    CONFIG_NET_IPV6=n
    CONFIG_NET_IPV4=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_OFFLOAD=y
    
    # NBIOT Usage
    CONFIG_LTE_NETWORK_MODE_NBIOT=y
    CONFIG_PDN=y
    CONFIG_PDN_DEFAULTS_OVERRIDE=y
    CONFIG_PDN_DEFAULT_APN="nbiot.vodacom.za"
    CONFIG_LTE_NETWORK_MODE_NBIOT=y
    
    # Sensors
    CONFIG_I2C=y
    CONFIG_SPI=y
    CONFIG_SENSOR=y
    
    # LwM2M and IPSO
    CONFIG_LWM2M=y
    CONFIG_LWM2M_COAP_BLOCK_SIZE=512
    CONFIG_LWM2M_COAP_MAX_MSG_SIZE=1280
    CONFIG_LWM2M_ENGINE_MAX_OBSERVER=20
    
    CONFIG_LWM2M_ENGINE_MAX_MESSAGES=20
    CONFIG_LWM2M_ENGINE_MAX_PENDING=20
    CONFIG_LWM2M_ENGINE_MAX_REPLIES=20
    
    CONFIG_LWM2M_DNS_SUPPORT=y
    CONFIG_LWM2M_RW_JSON_SUPPORT=n
    CONFIG_LWM2M_SERVER_DEFAULT_PMIN=1
    CONFIG_LWM2M_SERVER_DEFAULT_PMAX=300
    CONFIG_LWM2M_CLIENT_UTILS=y
    CONFIG_LWM2M_CLIENT_UTILS_LOCATION_OBJ_SUPPORT=n
    CONFIG_LWM2M_IPSO_SUPPORT=y
    
    # DTLS settings
    CONFIG_LWM2M_DTLS_SUPPORT=y
    
    # nRF9160 helper libraries
    CONFIG_MODEM_KEY_MGMT=y
    
    # Default app to debug logging
    CONFIG_LOG=y
    CONFIG_APP_LOG_LEVEL_DBG=y
    
    # Support HEX style PSK values (double the size + NULL char)
    CONFIG_LWM2M_SECURITY_KEY_SIZE=33
    
    # extend CoAP retry timing to 4 seconds for LTE/LTE-M
    CONFIG_COAP_INIT_ACK_TIMEOUT_MS=4000
    
    # Enable CoAP extended option length
    CONFIG_COAP_EXTENDED_OPTIONS_LEN=y
    CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=40
    
    # Enable settings storage
    CONFIG_SETTINGS=y
    CONFIG_FCB=y
    CONFIG_SETTINGS_FCB=y
    CONFIG_FLASH_MAP=y
    CONFIG_STREAM_FLASH=y
    
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_NETWORK_MODE_LTE_M_GPS=n
    
    # Modem library
    CONFIG_NRF_MODEM_LIB=y
    
    # Modem info
    CONFIG_MODEM_INFO=y
    CONFIG_MODEM_INFO_ADD_DATE_TIME=n
    
    # Enable shell
    CONFIG_LWM2M_SHELL=y
    
    # Heap and stacks
    CONFIG_HEAP_MEM_POOL_SIZE=16384
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_LWM2M_ENGINE_STACK_SIZE=3072
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
    
    # Allow FOTA downloads using download-client
    CONFIG_DOWNLOAD_CLIENT=y
    CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
    CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE_1024=y
    CONFIG_FOTA_DOWNLOAD=y
    
    # Application version
    CONFIG_MCUBOOT_IMAGE_VERSION="1.0.0"
    
    # Set LwM2M Server IP address here
    CONFIG_LWM2M_CLIENT_UTILS_SERVER="coaps://leshan.eclipseprojects.io:5684"
    
    # Application Event Manager
    CONFIG_APP_EVENT_MANAGER=y
    
    # Date-Time library
    CONFIG_DATE_TIME=y
    CONFIG_DATE_TIME_UPDATE_INTERVAL_SECONDS=86400
    
    # Enable LwM2M Queue Mode
    CONFIG_LWM2M_QUEUE_MODE_ENABLED=y
    
    # Enable TLS session caching to prevent doing a full TLS handshake for every send.
    CONFIG_LWM2M_TLS_SESSION_CACHING=y
    
    # Socket close is skipped at RX off idle state which optimize power consumption
    # Socket close call will enable RCC connection for send Alert message to server
    # Alert is now send right before opening a new connection.
    CONFIG_LWM2M_RD_CLIENT_SUSPEND_SOCKET_AT_IDLE=y
    
    # Sets the duration that the lwm2m engine will be polling for data after transmission before
    # the socket is closed.
    # Adjust so that we can detach from network in 30 seconds
    CONFIG_LWM2M_QUEUE_MODE_UPTIME=30
    
    # Set lifetime of 12 hours
    CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=43200
    
    # Do registration update after 5400 seconds (90 minutes)
    CONFIG_LWM2M_SECONDS_TO_UPDATE_EARLY=37800
    
    # Configure PSM mode`
    # Request periodic TAU of 3600 seconds (60 minutes)
    CONFIG_LTE_PSM_REQ_RPTAU="00000110"
    
    # Set Requested Active Time (RAT) to 30 seconds. Preferably a little bit longer than the
    # configured LWM2M_QUEUE_MODE_UPTIME. Due to NAT/firewall UDP connections are usually
    # closed within 30-60 seconds so there is in general no point in setting a longer
    # Queue mode uptime / LTE PSM active time.
    CONFIG_LTE_PSM_REQ_RAT="00001111"
    
    # Request eDRX mode
    CONFIG_LTE_EDRX_REQ=y
    
    # Request eDRX cycle length of 10.24 seconds for LTE-M
    CONFIG_LTE_EDRX_REQ_VALUE_LTE_M="0001"
    
    # Request eDRX cycle length of 20.48 seconds for NB-IoT
    CONFIG_LTE_EDRX_REQ_VALUE_NBIOT="0001"
    
    # Request Paging time window of 1.28 seconds for LTE-M
    CONFIG_LTE_PTW_VALUE_LTE_M="0000"
    
    # Request Paging time window of 2.56 seconds for NB-IoT
    CONFIG_LTE_PTW_VALUE_NBIOT="0000"
    
    # Get notification before Tracking Area Update (TAU). Notification triggers registration
    # update and TAU will be sent with the update which decreases power consumption.
    CONFIG_LTE_LC_TAU_PRE_WARNING_NOTIFICATIONS=y
    
    
    
    
    # Sensors
    CONFIG_I2C=y
    CONFIG_SPI=n
    CONFIG_SENSOR=n
    
    #Enable/Disable RTT or UART Logging
    CONFIG_CONSOLE=y
    CONFIG_LOG=y
    CONFIG_APP_LOG_LEVEL_DBG=y
    
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_RTT_CONSOLE=y
    CONFIG_UART_CONSOLE=n
    
    
    # Set LwM2M Server IP address here
    
    
    
    
    
    
    
    
    # Configure lwm2m version
    CONFIG_LWM2M_VERSION_1_1=y
    CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1=y
    
    CONFIG_JSON_LIBRARY=y
    CONFIG_BASE64=y
    CONFIG_LWM2M_RW_SENML_JSON_SUPPORT=y
    
    # w1 sensor interface configuration
    CONFIG_SENSOR=y
    CONFIG_W1=y
    
    # Enabling RTC
    CONFIG_COUNTER=y
    CONFIG_PCF85063A=y
    
    # Battery measurement
    CONFIG_ADC=y
    
    # Power saving
    CONFIG_PM_DEVICE=y
    
    # Configure internal flash
    
    
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_MPU_ALLOW_FLASH_WRITE=y
    CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y
    
    
    
    CONFIG_LTE_NETWORK_USE_FALLBACK=n
    CONFIG_LTE_NETWORK_TIMEOUT=120
    
    
    
    CONFIG_WATCHDOG=y
    
    CONFIG_NRF_MODEM_LIB_TRACE=y
    
    CONFIG_NRF_MODEM_LIB_TRACE_BACKEND_RTT=y

  • Hello,

    Sorry for the delays, I was on a sick leave last week unfortunately.

    What if you turn off the logging via RTT? I think it may be interfering with the modem trace.

    Best regards,

    Michal

  • HI Michal

    This is the first thing I tried two weeks ago. Any other suggestions?

  • Hello,

    Please check if you doing it according to this guide:

    Requirement: NCS v1.9.x or newer

    1. Go into prj.conf and add these two lines:
    CONFIG_NRF_MODEM_LIB_TRACE_ENABLED=y
    CONFIG_NRF_MODEM_LIB_TRACE_MEDIUM_RTT=y

     

    You might also need to disable other RTT logging channels:
    CONFIG_LOG_BACKEND_RTT=n
    CONFIG_RTT_CONSOLE=n

     

    2. Compile and flash the project.

     

    3. Open JLinkRTTViewer, select device "nRF9160_xxaa"

     

    4. When successfully connected, go to "Logging" -> "Start Data Logging", and select a path to save the file.

     

    5. See that the .log file grows in size. When finished tracing, stop data logging and rename the .log file to .bin

    6. Open the recorded .bin file in the Trace Collector V2 (Cellular Monitor should also work I think)

    Best regards,

    Michal

Related