Command execution is only allowed for an authorized session. The command API will
output "Unauthorized" and a Login button as necessary. The login state is also
available in the global variable loggedin. To send the user to the
login page and return to the current page after login, call login():
To execute a command automatically on page load, simply add the monitor class
to an output element, set data-updcmd to the command to be executed and
data-updcnt to 1:
Fetching boot status…
Output elements typically are samp or pre, as commands
normally output formatted plain text, but any element can be used. samp
by default compresses white space and has no visible area, while pre
is visible and preserves all spacing.
updcnt will count down to zero and stop, or run indefinitely if started
below zero. The execution interval can be given in data-updint (in seconds).
You can set the data attributes any time using jQuery, all monitors are checked and
updated by the framework once per second.
To automatically trigger a monitor update on OVMS events, additionally set the
data-events attribute to a regular expression matching the event(s) of
interest. This example monitor lists the active network channels and automatically
updates on all server connection events:
Try: Open new window Stop V2 server Start V2 server Send fake event
A bootstrap button has the base class btn. Add the command to execute
as attribute data-cmd and optionally the output element as
data-target and you're done.
Add class samp-inline or wrap in a ul.list-inline to place
the output element on the same line with the button. Prefix the target with a "+" to
append to it:
External 12V power
By combination of a button and a monitor, you can let the button start a repeated
execution of a command: set data-watchcnt on the button to the number of
repetitions (default 0) and data-watchint to the interval in seconds
(default 2).
Note: to stop a monitor, set data-updcnt to 0:
To execute Javascript code directly (i.e. without calling script eval),
simply exchange the data-cmd / data-updcmd attribute by
data-js / data-updjs. Example: