FOTA Authentication error - nRF9160

Hello

I am developing an application based on the nRF9160, it uses Coap protocol to connect to nRFCloud to transfer the data. Also I have implemented the FOTA which always worked with no problems but since last week I get an error, only when there is a pending fota on the nrf cloud for the device. Otherwise the device is able to connect and send data to nrf cloud without any problems. I get the following error: err> nrf_cloud_coap_transport: Device not authenticated; reconnection required.

For the device provision process I use the device_credentials_installer.py script from the nRFCloud utils on github . I have generated the CA certificate and private key using the script create_ca_cert.py.
I have never experienced a problem related with the provision and authentication of the device. I also, repeat the device provision using new generated certificates but did not solve the problem.

The fota in my application is based on the nrf_cloud_multi_service sample and the fota_support.c and fota_support.coap.c files.

The logs from my application when I there is a pending fota are the following:

The prj.conf file:

#General config
CONFIG_EVENTS=y
CONFIG_FPU=y
CONFIG_RESET_ON_FATAL_ERROR=y

#LOGGING
CONFIG_LOG=y
CONFIG_LOG_INFO_COLOR_GREEN=y
CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP=n
#CONFIG_LOG_BACKEND_UART_ASYNC=y
CONFIG_LOG_BACKEND_UART_AUTOSTART=y

#SHELL - can not be used with device power management
CONFIG_SHELL=n
CONFIG_SHELL_STACK_SIZE=4096

CONFIG_UART_ASYNC_API=y             #The Asynchronous API allows to read and write data in the background using DMA without interrupting the MCU at all.
CONFIG_UART_INTERRUPT_DRIVEN=y

CONFIG_UART_1_INTERRUPT_DRIVEN=n
CONFIG_UART_1_ASYNC=y
CONFIG_UART_0_INTERRUPT_DRIVEN=y

#MAIN THREAD
CONFIG_MAIN_LOG_LEVEL_INF=y
CONFIG_MAIN_STACK_SIZE=8192

CONFIG_LSM6DSV16X=n
CONFIG_LSM6DSV16X_ENABLE_TEMP=n
CONFIG_LSM6DSV16X_SENSORHUB=n 
CONFIG_LSM6DSV16X_TRIGGER_OWN_THREAD=n

#SENSORS DRIVER
CONFIG_SENSOR=y
CONFIG_SENSOR_LOG_LEVEL_ERR=y

#WATCHDOG
CONFIG_WATCHDOG_APPLICATION=y
CONFIG_WATCHDOG_APPLICATION_TIMEOUT_SEC=600
CONFIG_WATCHDOG_LOG_LEVEL_ERR=y

#POWER MANAGEMENT
CONFIG_PM_DEVICE=y
CONFIG_POWEROFF=y
CONFIG_PM_DEVICE_RUNTIME=y

# Configuration required by Application Event Manager
CONFIG_APP_EVENT_MANAGER=y
CONFIG_APP_EVENT_MANAGER_LOG_LEVEL_ERR=y
CONFIG_APP_EVENT_MANAGER_POSTINIT_HOOK=y

CONFIG_HEAP_MEM_POOL_SIZE=47250
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
CONFIG_REBOOT=y


# Network
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_IPV6=y
CONFIG_NET_IPV4=y
CONFIG_NET_TX_STACK_SIZE=4096
CONFIG_NET_RX_STACK_SIZE=4096



# nRF Cloud
CONFIG_NRF_CLOUD_MQTT=n
CONFIG_NRF_CLOUD_COAP=y                             # nRF Cloud COAP
CONFIG_NRF_CLOUD_COAP_LOG_LEVEL_DBG=y               # nRF Cloud COAP LOG LEVEL
CONFIG_NRF_CLOUD_ALERT=y                            # nRF Cloud Alert System
CONFIG_NRF_CLOUD_LOG_DIRECT=y
CONFIG_NRF_CLOUD_LOG_OUTPUT_LEVEL=3
CONFIG_NRF_CLOUD_LOG_LOG_LEVEL_ERR=y
CONFIG_NRF_CLOUD_CLIENT_ID_SRC_IMEI=y
CONFIG_NRF_CLOUD_CLIENT_ID_PREFIX="ED220-"
CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS=y               # Send device status on initial connection
CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS_CONN_INF=y      # Include connection information with device status
CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS_NETWORK=y       # Include network status information with device status
CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS_SIM=y           # Include SIM card information with device status
CONFIG_NRF_CLOUD_SEND_SERVICE_INFO_FOTA=y           # Add supported FOTA types to the "serviceInfo" section

CONFIG_NRF_CLOUD_ALERT_LOG_LEVEL_WRN=y

CONFIG_LOG_MODE_DEFERRED=y
CONFIG_LOG_BUFFER_SIZE=4096
CONFIG_NRF_CLOUD_LOG_DIRECT=y
CONFIG_NRF_CLOUD_LOG_OUTPUT_LEVEL=3
CONFIG_NRF_CLOUD_LOG_BACKEND=y

CONFIG_CJSON_LIB=y


CONFIG_POSIX_API=y


# CoAP Client
CONFIG_COAP_CLIENT_BLOCK_SIZE=1024
CONFIG_COAP_CLIENT_STACK_SIZE=6144
CONFIG_COAP_CLIENT_THREAD_PRIORITY=0
CONFIG_COAP_EXTENDED_OPTIONS_LEN=y
CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=40

# nRF modem library
CONFIG_NRF_MODEM_LIB=y
CONFIG_NRF_MODEM_LIB_ON_FAULT_APPLICATION_SPECIFIC=y
CONFIG_MODEM_BATTERY=y
CONFIG_MODEM_INFO=y

# Modem
CONFIG_MODEM_KEY_MGMT=y
CONFIG_MODEM_JWT=y
CONFIG_MODEM_INFO=y
CONFIG_MODEM_INFO_ADD_NETWORK=y
CONFIG_MODEM_INFO_ADD_DEVICE=y
CONFIG_MODEM_INFO_ADD_DATE_TIME=n
CONFIG_MODEM_INFO_ADD_SIM=y
CONFIG_MODEM_INFO_ADD_SIM_ICCID=y
CONFIG_MODEM_INFO_ADD_SIM_IMSI=y


# AT Host library - Used to send AT commands directy from an UART terminal and to allow
#		    integration with nRF Connect for Desktop LTE Link monitor application.
CONFIG_AT_MONITOR=y
# Heap and stacks
CONFIG_AT_MONITOR_HEAP_SIZE=1024
CONFIG_AT_HOST_LIBRARY=y
CONFIG_AT_HOST_LOG_LEVEL_ERR=y
CONFIG_AT_MONITOR_LOG_LEVEL_INF=y


# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_NBIOT_GPS=y
CONFIG_LTE_LINK_CONTROL_LOG_LEVEL_INF=y

## Power saving timers.
# Enable optional power savings mode for carrier roaming; this is compatible
# with nRF Cloud CoAP because communications are always initiated by the device. It is not compatible with MQTT.
CONFIG_LTE_PROPRIETARY_PSM_REQ=y
CONFIG_LTE_PSM_REQ=y
# Periodic TAU - ### 320 hours PSM.
CONFIG_LTE_PSM_REQ_RPTAU="11000001"
### 20 seconds active time.
CONFIG_LTE_PSM_REQ_RAT="00001010"  # for cosmote the smaller active time is 30 sec, even in this case

CONFIG_PDN=y
CONFIG_PDN_LOG_LEVEL_INF=y
CONFIG_PDN_DEFAULTS_OVERRIDE=y
CONFIG_PDN_DEFAULT_APN="iot" 



#DATE AND TIME
CONFIG_DATE_TIME=y
CONFIG_DATE_TIME_AUTO_UPDATE=y
# Auto update time every 24 hours
CONFIG_DATE_TIME_UPDATE_INTERVAL_SECONDS=86400
CONFIG_DATE_TIME_LOG_LEVEL_ERR=y


CONFIG_I2C=y

# Flash - Used by FOTA and PGPS - Using only this with zephyr,pm-device-runtime-auto; - on device tree we have a low power consumtion on the flash device
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=n

# MCUBOOT - Needed by FOTA
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_IMG_MANAGER=y
CONFIG_MCUBOOT_IMG_MANAGER=y
CONFIG_SECURE_BOOT=y
CONFIG_BUILD_S1_VARIANT=y

# Download Client - used by FOTA and PGPS
CONFIG_DOWNLOAD_CLIENT=y
CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE_1024=y
CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
CONFIG_DOWNLOAD_CLIENT_BUF_SIZE=2300
CONFIG_DOWNLOAD_CLIENT_MAX_HOSTNAME_SIZE=128
CONFIG_DOWNLOAD_CLIENT_LOG_LEVEL_INF=y

CONFIG_FOTA_DOWNLOAD=y
CONFIG_FOTA_DOWNLOAD_PROGRESS_EVT=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y
CONFIG_DFU_TARGET=y

# Disable MQTT-specific services; equivalent CoAP versions are used instead.
CONFIG_NRF_CLOUD_FOTA=n
CONFIG_NRF_CLOUD_FOTA_POLL=y

# Settings - used by nRF Cloud library and PGPS
CONFIG_SETTINGS=y
CONFIG_SETTINGS_FCB=y
CONFIG_FCB=y


#FOTA SUPPORT
CONFIG_FOTA_SUPPORT_COAP_LOG_LEVEL_INF=y
CONFIG_FOTA_DOWNLOAD_LOG_LEVEL_INF=y

#MODEM MODULE
CONFIG_MODEM_MODULE_LOG_LEVEL_INF=y


#MESSAGE QUEUE MODULE
CONFIG_MESSAGE_QUEUE_MODULE_LOG_LEVEL_WRN=y
CONFIG_MESSAGE_QUEUE_COAP_SEND_CONFIRMABLE=y

#LOCATION MODULE
CONFIG_LOCATION_MODULE_LOG_LEVEL_WRN=y


#Enable for thread stack information
CONFIG_DEBUG_THREAD_INFO=y
#CONFIG_INIT_STACKS=n

#LOCATION
CONFIG_LOCATION=y
CONFIG_LOCATION_METHOD_CELLULAR=y
CONFIG_LOCATION_METHOD_GNSS=y
CONFIG_LOCATION_REQUEST_DEFAULT_TIMEOUT=300000
CONFIG_LOCATION_DATA_DETAILS=y
CONFIG_LOCATION_SERVICE_NRF_CLOUD=y
CONFIG_LOCATION_LOG_LEVEL_INF=y
CONFIG_LOCATION_REQUEST_DEFAULT_GNSS_ACCURACY_HIGH=y
#CONFIG_LOCATION_SERVICE_NRF_CLOUD_GNSS_POS_SEND=y      --try this- What is this?

#NRFCLOUD LOCATION
CONFIG_NRF_CLOUD_AGNSS=y
CONFIG_NRF_CLOUD_PGPS=y
CONFIG_NRF_CLOUD_PGPS_REPLACEMENT_THRESHOLD=4
CONFIG_NRF_CLOUD_PGPS_REQUEST_UPON_INIT=y

  • SDK: nRFCloud SDK v2.7.0
  • Modem firmware: mfw_nrf9160_1.3.7

As you can see from the LOGS the device is authorized but when there is a fota pending it says that the device is not authenticated. Also, in case there is not pending fota the device is able to get the shadow register and send data to nrfcloud using Coap protocol, without any problems. Why such an error might occur?

Thank you in advance 

Parents
  • Hi Avgerinos,

    Thanks for reporting this issue. I have a couple of suggestions that might help you narrow down the cause:

    1. Have you tested with the nrf_cloud_multi_service sample to reproduce the issue? I encourage you to try it with both NCS v2.7.0 and the latest NCS v2.9.0. This approach will help determine if the problem is related to firmware changes or originates from your custom code.

    2. Please note that there is a known issue that may affect NCS v2.7.0 as well. You might want to try the recommended workaround for that issue.
      CIA-1400: nRF Cloud FOTA and P-GPS downloads over CoAP might fail to resume

      v2.9.0.nrf54h20.rc1v2.9.0v2.8.0

      nRF Cloud FOTA and P-GPS downloads over CoAP might fail to resume at the correct file offset if the download is interrupted.

      Workaround: Disable the CONFIG_NRF_CLOUD_COAP_DOWNLOADS Kconfig option to use HTTP for downloads instead.

    Let me know if these steps help or if you need further assistance.

    Best regards,

    Charlie

  • Hello Charlie

    I used the workaround suggestion as follows:
    CONFIG_NRF_CLOUD_COAP_DOWNLOADS=n
    but did not solve the problem. I had the same exact error.


    Also I enable it just in case 
    CONFIG_NRF_CLOUD_COAP_DOWNLOADS=y
    and also set 
    CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=192 because it was required and again the same error.

    The other test I did was that, I build my application using the nRFConnect SDK v2.8.0 and tested it using both the above options (CONFIG_NRF_CLOUD_COAP_DOWNLOADS=n and another test with CONFIG_NRF_CLOUD_COAP_DOWNLOADS=y)
    but again I had the same exact error.

    Finally I used an older back up of my application that was build on SDK 2.6.1 and was tested using FOTA, but this time I had again the same exact error. That backed up code was working without any issues at the time it was backed up.

    Overall looks like when the download is using http and also coap, there is the same error.

    On your second comment you mention an known issue but I was not able to find it using the link. Could you please let me know where I can find this known issue, in case it might give me insights in order to figure this out.

    I have not tested the nrf_cloud_multi_service sample yet, as you suggested but I will give it a try and let you know.

    Is there anything else that might cause this issue?

    Thank you for your help!

Reply
  • Hello Charlie

    I used the workaround suggestion as follows:
    CONFIG_NRF_CLOUD_COAP_DOWNLOADS=n
    but did not solve the problem. I had the same exact error.


    Also I enable it just in case 
    CONFIG_NRF_CLOUD_COAP_DOWNLOADS=y
    and also set 
    CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=192 because it was required and again the same error.

    The other test I did was that, I build my application using the nRFConnect SDK v2.8.0 and tested it using both the above options (CONFIG_NRF_CLOUD_COAP_DOWNLOADS=n and another test with CONFIG_NRF_CLOUD_COAP_DOWNLOADS=y)
    but again I had the same exact error.

    Finally I used an older back up of my application that was build on SDK 2.6.1 and was tested using FOTA, but this time I had again the same exact error. That backed up code was working without any issues at the time it was backed up.

    Overall looks like when the download is using http and also coap, there is the same error.

    On your second comment you mention an known issue but I was not able to find it using the link. Could you please let me know where I can find this known issue, in case it might give me insights in order to figure this out.

    I have not tested the nrf_cloud_multi_service sample yet, as you suggested but I will give it a try and let you know.

    Is there anything else that might cause this issue?

    Thank you for your help!

Children
  • Hi Avgerinos,

    Thanks for sharing your testing results.

    According to your series of tests, one potential issue could be changes on the nRF Cloud side or a combination of changes in both nRF Cloud and the firmware APIs.

    Looking forward to seeing if you can reproduce this issue using the nRF Cloud multi-service sample. That would help determine whether the problem is related to your custom implementation or a broader compatibility issue.

    Best regards,

    Charlie

  • Hello Charlie

    I have tested the nrf_cloud_multi_service sample sample as you suggested with the following results:

    I performed two tests using two different SIM cards the one is IPV4 and the other one IPV6. In both cased it could not connect successfully.

    Following you can find the screenshots from the LOGS of both tests.

    Does this help to figure out what is going on?

    Btw, I tested again my code and I have exactly the same results as in my first post.

    Thank you!

  • Hi Avgerinos,

    Apologies for the delayed response.

    Our nRF Cloud development team is currently investigating the issue you've reported. 

    We will provide you with updates as soon as we have more information.

    Best regards,

    Charlie

  • Hello Charlie

    Thank you for the support!

    Just an update, today I tried the same FOTA and it worked. I tried it also using another device of mine that there were no firmware change, just in case.

    As you can see in the following Logs of the device, the FOTA was successful.

    Moreover, I also tried the nrf_cloud_multi_service sample, just to see what will happed and I had the same results as in my previous post. The sample was not able to connect to nrfCloud.

    Im not sure what is going on....?

    Thank you

Related