A Toit application is made of:
a toit file containing the code that will be executed.
a YAML file containing the app specification that describes when and how often the application must run.
To benefit from the modularity of Toit, we recommend writing and deploying separate apps for the different sensors. This ensures that a failure to access one sensor does not prevent the other apps from collecting data generated by the other sensors for example. It is also easier and safer to update apps independently from each other.
The specification file
This section describes the content of an app specification file.
# Description of an app specification file using YAML syntax. name: <App name> entrypoint: <toit file entrypoint> triggers: on_boot: <bool> on_install: <bool> on_interval: "<duration>" cron: - "*/5 7 * * *" - "0 */2 * * *" on_pubsub_topic: - "<type>:<name>" gpios: - pin: <pin> pubsub: subscriptions: - "<type>:<name>"
The app name. This name is the primary human identifier of an app.
The Toit file where the
mainfunction of the program is located. The entrypoint can be the name of the Toit file, such as
hello.toit, if it is saved in the same folder as its configuration file, or a relative path to the Toit file including the Toit file, such as
The events triggering the execution of the application. Programs can query which trigger started them by using the job library.
Without any trigger, the application is always running. In case the application terminates, it is immediately restarted.
Runs the application every time the device boots. This includes reboots, or when the device wakes up from a scheduled deep sleep.
Runs the application when it is installed.
Runs the application every
duration. If the application is already running when the trigger fires the event is ignored and the program is not run again.
The input is an interval of time in either hours, minutes, or seconds such as:
Is a list of crons, each defining a schedule on when the application should start. In the example above, the application will be triggered every 5 minutes of the 7th hour, as well as every 2 hours on minute 00. Note that the time on devices is in UTC. Timezones are not supported.
If the application is already running when the trigger fires, the event is ignored.
Runs the application when a message from the defined pubsub topic
<type>:<name>is received on the device. The
on_pubsub_topiccan only trigger on topics that the device is subscribed to (see below for subscribing to a topic).
Runs the application when any of the specified GPIO pins are high. This GPIOs trigger is level-triggered, so it'll continue running the application while the GPIO pin is high. This will also wake up the device from deep-sleep to run the app and go back to deep sleep.
The PubSub subscriptions.