01. Operational Flow
This article provides an overview of the operation flow of the SPRESENSE.
Hereinafter, "Spresense" is called "device".
*The bold frame in the figure indicates the starting point of the operation mode description.
The device has the following major modes.
Script Execution Mode
In this mode, the operation script is executed in the basic operation of the device.Safe Mode
In this mode, if an exception such as a throw or a syntax error occurs while executing the script, wait for the script to be modified.Firmware Update Mode
This mode updates the device firmware.
It also updates the firmware of the user device with the NEQTO Machine Driver.
The operation flow of each mode is described below.
Script Execution Mode
Normal Booting Operation
Script execution mode is the basic operation of the device.
The device will initialize after booting.
After initialization, connect to the network.
After connecting to the network, access NEQTO Console and authenticate.
When the authentication is completed, download and execute the script.
Booting Operation when unable to connect to a Network
If the device cannot connect to the network when the device starts, retry the network connection.
Note that the script will not be executed in this state.
Check the network settings and signal environment, and restart the device.
Booting Operation when device is not registered to a Node
If the device is started without registering to a node on NEQTO Console, authentication will fail.
Note that the script will not be executed in this state.
Check the node registration and restart the device.
Script Reload Operation
"Script Reload" is the operation to terminate the script once and download and execute the updated script.
Basically, when all the main routines have completed and all resources waiting for callbacks such as timers and nqMQTT objects have been released, the script reload will be performed.
On the other hand, there are two ways to perform a script reload without waiting for resources to be released.
Use trigger command (push notification) from NEQTO Console
Perform "Reload Script" using the trigger command from NEQTO Console.
When the device receives the "Reload Script" instruction from NEQTO Console, it forcibly terminates the script and downloads and executes the updated script.
It can be used to update the script or to intentionally restart the script remotely.Use a throw statement that contains a specific hashtag
By executing the throw statement below, you can start reloading spontaneously from within the script.
It can be used to check if the script is updated regularly or to intentionally restart the script.throw '#nqEXIT';
throw new Error('#nqEXIT');
Booting Operation when Express mode is enabled
In normal booting operation, network connection, certification, and script downloading are required until the scripts are launched. The Express mode is a feature that bypasses these prerequisites and allows scripts to be launched.
After the device is booted, it will first attempt to connect to the network, but it is expected that it may take some time for the network to connect due to factors such as the wireless environment. However, there are times when scripts need to run as quickly as possible, and Express mode can be utilized for this purpose.
When Express mode is enabled, network connection wait timeout processing is enabled.
If the network is connected before the timeout, the normal booting operation continues: certification, script download, and script launch.
If a timeout occurs, certification, script download is bypassed and the previously downloaded script stored in the device is launched. Even after the network connection wait timeout, the network connection process continues, and functions that require communication functions can be used from the time the network connection is established.
Express mode configuration
Express mode is enabled/disabled from the NEQTO Console. Refer to here.
Network connection wait timeout value
The timeout value can be changed using the .setExpressConf() method. The default value is 30
seconds. If 0
is specified, in effect, there is no waiting for a network connection, and the previously downloaded script can be launched immediately.
About System Time
The device's system time is normally synchronized during the certification sequence after network connection, but if bypassed by Express mode, the script will basically launch with no current time set. Until time synchronization is performed, the system time will be the time starting from the default value 1970/1/1 00:00:00
. For more information on time synchronization, refer to here. In addition, the rtc.getInitTimeCorrVal() method can be utilized to convert the timestamp obtained before time synchronization to the present time after time synchronization.
Standby Mode Operation
Since Version 02.00.00: From the script, the following methods can be used to transition the device to the standby mode.
Standby mode reduces standby power the most because the device is in standby mode, near power off.
When a resume condition occurs, the device will start again from Normal Booting Operation. ("Normal Resume")
sleep.setStandby() <Recommended>
1.Waits for normal disconnection of network communication before shutting down the communication module and transitioning to standby mode.
sleep.setStandbySync()
2.Forcibly disconnects network communication, shuts down the communication module, and immediately transitions to standby mode. If there are no constraints on the standby mode transition time, using the sleep.setStandby() method is recommended.
Offline Resume Operation for Standby Mode
The standby mode methods above have an "Offline Resume" option.
When a resume condition occurs, the device will start again, skip the network connection, and immediately execute the stored script.
In "Offline Resume", functions that require a network connection cannot be used.
If the script terminates voluntarily with throw '#nqEXIT', etc., the script restarts with the offline resume maintained. If an exception occurs in the script, the device is automatically reset and restarted in normal resume.
Resume Conditions for Standby Mode
- When the RTC alarm occurs (
Cold Sleep
/Deep Sleep
) - When a level change is detected on the port for which IO port input interrupt is set (
Cold Sleep
only)Interrupt condition Operation Rising edge Resumes when port input is High. Falling edge Resumes when port input is Low. Rising / Falling edge Resumes when the port input status changes.
- (
***
) is the sleep mode of the Spresense used. It can be specified from the standby mode method above.
Safe Mode
Safe Mode Operation
If an exception such as a throw or a syntax error occurs while executing the script, wait for the script to be modified. This state is called safe mode.
Check and correct the script, and perform "Reload Script" using the trigger command from NEQTO Console.
When the device receives the "Reload Script" instruction from NEQTO Console, it will download and execute the updated script.
In addition, the device automatically checks if the script has been updated during safe mode. The check interval increases in the order of 1 minute, 2 minutes, 4 minutes, 8 minutes, 16 minutes, and 30 minutes. And finally it will be every 30 minutes.
Firmware Update Mode
User device firmware update operation using Machine Driver
When the device receives the Machine Driver update instruction from NEQTO Console, it downloads and executes the Machine Driver script.
The Machine Driver script downloads the firmware image file and updates the user device firmware.
When the Machine Driver script processing is completed, the operation script execution returns.
Device firmware update operation
When the device receives the firmware update instruction from NEQTO Console, it downloads the firmware and updates the firmware.
When the firmware update is complete, it will automatically reboot and return to normal operation.
If the device firmware has already been updated, the firmware update process will be skipped.
Caution: Please do not turn off the power while updating the firmware.
About system time synchronization
The device gets the time information from NEQTO Console and automatically synchronizes the time.
The timing of time synchronization is as follows.
Phase | Time update timing |
---|---|
When NEQTO Console authentication is done | When the authentication sequence is executed, such as at device startup |
During operation script execution | Regularly once a day |
When the time correction method of the nqService object is executed | Any timing |