Initializing FOTA from app/general FOTA questions

Hi!

I'm trying to implement FOTA in our project. My application will sleep for days between each connection, so I'm turning off the modem and everything between.

I'm successfully connecting to nRF Cloud when I'm getting new A-GPS data or when doing cell measurements. These connections to the cloud lasts for less than a minute at a time, as I disconnect when I'm done sending my sensor data.

I'm trying to deploy a FOTA from nRFCloud. The job status is "queued", and isn't applied. Part of my configuration and the shadow is below. 

# MCUBOOT - Needed by FOTA
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_IMG_MANAGER=y
CONFIG_MCUBOOT_IMG_MANAGER=y
CONFIG_STREAM_FLASH_ERASE=y

# Download Client - used by FOTA 
CONFIG_NRF_CLOUD_FOTA=y
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

# Flash - Used by FOTA 
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

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

hadow":{3 items
"reported":{5 items
"connection":{...}4 items
"pairing":{...}2 items
"nrfcloud_mqtt_topic_prefix":"prod/XXX-XXX-XXX/"
"config":{...}7 items
"device":{2 items
"serviceInfo":{2 items
"ui":[]0 items
"fota_v2":[2 items
0:"MODEM"
1:"APP"

Before disconnecting the cloud, I always check if a FOTA is active by testing "if (nrf_cloud_fota_is_active()) " (defined in nrf_cloud_fota.c).
When connecting to the cloud, the library prints "nrf_cloud_fota: Saved job: , type: 3, validate: 0, bl: 0x0", called by "fota_settings_set()". I do not understand what this info means.

My questions are, can you see any reason or come with any tips as to why the FOTA isn't happening?  Is there any way of actively initiating/check for a FOTA from the application side?

Thank you all for all and any help!

Kind regards,

Torje

Parents Reply
  • Hello Håkon,

    And thank you for responding. I can confirm these properties under "device information". I am doing it as it says in the linked guide.

    When restarting the device I can get the FOTA, but not under normal operations. I believe I am connected to the cloud for a too short interval so it "doesn't have the time". First connection is somewhat longer. I don't want to extend my duration of connection due to power saving, as there won't be a FOTA 99/100 times. 

    Do you have any suggestions to how I can solve or work around this? Would you agree that a too short cloud connected period could be the reason the FOTA isn't executing?

    Thank you again!

Children
  • Hi!

    Thanks for clarifying the behavior!

    Given that the process works upon reset, ie. a full re-connect, it indicates that this function is not called/checked on normal operation:

    https://github.com/nrfconnect/sdk-nrf/blob/v2.1.0/subsys/net/lib/nrf_cloud/include/nrf_cloud_fota.h#L161

    (this function again interacts with these topics: https://docs.nrfcloud.com/Reference/Interacting/MQTT/#fota-topics)

     

    Could you try to call this function to see if the FOTA is picked up during normal operation?

     

    Kind regards,

    Håkon

  • Thanks again, Håkon.

    I am now calling the function several seconds before disconnecting. I doesn't seem to do anything though. I feel like I'm missing something to actually commence the FOTA, but this is all "black box" handled by modem and libraries. nrf_cloud_fota_is_active() still returns false, seven seconds after calling the function you suggested. Do I need to update the shadow every time I connect to the cloud? Not I'm only doing it once, upon the first connection. Other cloud communications works fine, I get both cell and agps-data immediately after requesting it.

    Thank you again for all and any help!

  • As Håkon noted, nrf_cloud_fota_update_check() makes the request to nRF Cloud for pending FOTA jobs.  It publishes to the /jobs/req topic and if there is a pending job, the cloud will respond on the the jobs/rcv topic.  nrf_cloud_fota_is_active() checks to see if the device is actively working on a FOTA job.
    You could try waiting up to 30s after calling nrf_cloud_fota_update_check() to see if the cloud responds with the pending FOTA job.  Also, check to make sure the modem has not entered into any power saving mode.

    "When restarting the device I can get the FOTA, but not under normal operations. I believe I am connected to the cloud for a too short interval so it "doesn't have the time". First connection is somewhat longer."

    If you are using the nrf_cloud MQTT library, the check for FOTA jobs is performed automatically during the connection process.  If your device is disconnecting from MQTT and the carrier and then reconnecting each time, there should not be any difference in operation in the nrf_cloud library compared to a device restart.  Could you provide more details on your application's behavior?
    Are you using the full nrf_cloud MQTT library (CONFIG_NRF_CLOUD_MQTT=y) or only FOTA (CONFIG_NRF_CLOUD_FOTA)?

    Also, since it sounds like your device is rarely connected to the network, you could consider using REST instead of MQTT.

  • Hello Justin,

    And thank you as well for replying. Today, I sat up two Thingys with the same code and issued separate FOTA jobs to them. One happened, the other one did not.
    I have enabled both the mentioned libraries. I also send my data to a third party broker, thus having connection both with nRFCloud, and with a third party. These connections seem to not interfere with each other. My current routine disconnects from nRFCloud before connecting to the other broker, but I have not experienced any issues being connected to both. Could this be cause of any trouble?

    My cloud connect routine is nrf_cloud_init() (with handler param) and nrf_cloud_connect(). My disconnect routine is nrf_cloud_disconnect() and nrf_cloud_uninit() (all from nrf_cloud.c). I am now also calling nrf_cloud_fota_update_check() in between. 

    I am trying to make my system work with both short- and long intervals. Disconnecting in longer intervals, staying connected for shorter. The interval may be changed during runtime. It gets GPS positioning at this interval, with aGPS-support and fallback to cell location if needed. It always gets aGPS or cell data when requested, establishing cloud connection if needed. 

    Thank you for the REST suggestion, I might consider this in a future version. 

  • My current routine disconnects from nRFCloud before connecting to the other broker, but I have not experienced any issues being connected to both. Could this be cause of any trouble?
    - No, that should be fine.

    You shouldn't need to un-init and re-init  the nrf_cloud library each time, unless you want to recover the memory.  Disconnecting and reconnecting should be sufficient.
    Also, you shouldn't need to call nrf_cloud_fota_update_check(), as the nrf_cloud library calls it automatically upon connection.

    For testing purposes, I would allow up to 30s after connection to the cloud to see if a scheduled FOTA job arrives.  Also for testing, try disabling power saving modes in the modem (PSM and eDRX).

Related