Skip to the content.

Main Module

The Main module serves as the central control unit of the Asset Tracker Template application. It implements a hierarchical state machine that coordinates the activities of all other modules through zbus messages. This module handles the application’s business logic, including cloud connectivity, data sampling, firmware updates, configuration updates, and user interactions.

Messages

The main module does not implement messages available to other modules. Instead, it processes messages from other modules to control the application’s behavior. It subscribes to messages on the following zbus channels:

The Main module uses the following zbus channels, both for subscribing to incoming data and publishing outbound requests or status updates:

Configurations

The Main module can be configured using the following Kconfig options:

State Diagram

The Main module implements a hierarchical state machine with the following states:

stateDiagram-v2
    [*] --> STATE_RUNNING

    state STATE_RUNNING {
        [*] --> STATE_IDLE

        STATE_IDLE --> STATE_TRIGGERING : CLOUD_CONNECTED_READY_TO_SEND
        STATE_TRIGGERING --> STATE_IDLE : CLOUD_DISCONNECTED/CLOUD_CONNECTED_PAUSED

        state STATE_TRIGGERING {
            [*] --> STATE_SAMPLE_DATA
            STATE_WAIT_FOR_TRIGGER --> STATE_SAMPLE_DATA : timer_trigger/button_press

            STATE_SAMPLE_DATA --> STATE_WAIT_FOR_TRIGGER : LOCATION_SEARCH_DONE
        }
    }

    STATE_RUNNING --> STATE_FOTA : FOTA_DOWNLOADING_UPDATE

    state STATE_FOTA {
        [*] --> STATE_FOTA_DOWNLOADING

        STATE_FOTA_DOWNLOADING --> STATE_FOTA_WAITING_FOR_NETWORK_DISCONNECT : FOTA_SUCCESS_REBOOT_NEEDED
        STATE_FOTA_DOWNLOADING --> STATE_FOTA_WAITING_FOR_NETWORK_DISCONNECT_TO_APPLY_IMAGE : FOTA_IMAGE_APPLY_NEEDED

        STATE_FOTA_WAITING_FOR_NETWORK_DISCONNECT --> STATE_FOTA_REBOOTING : NETWORK_DISCONNECTED

        STATE_FOTA_WAITING_FOR_NETWORK_DISCONNECT_TO_APPLY_IMAGE --> STATE_FOTA_APPLYING_IMAGE : NETWORK_DISCONNECTED
        STATE_FOTA_APPLYING_IMAGE --> STATE_FOTA_REBOOTING : FOTA_SUCCESS_REBOOT_NEEDED

        STATE_FOTA_REBOOTING --> [*] : sys_reboot()
    }

    STATE_FOTA --> STATE_RUNNING : FOTA_DOWNLOAD_CANCELED/TIMED_OUT/FAILED