User's Manual DG100 IoT Gateway
Web user interface
https://macchina.io/docs/00200-MacchinaJSProgramming.html
For a functionl description and description of programming interface of Decode bundles
installed on DG100 please use specific bundle programming reference document which could
be obtained from Decode support. For two standard DG100 Decode bundles ModPoll and
MqttClient functional description and programming reference are given in following chapters.
5.6.1 Writing JavaScript programs
JavaScript program can be typed in Playground editor or can be pasted to web editor from
another page or document. Note that when working with the Playground app, it's a good idea
to have a nearby console window with macchina.io's log output open to see script output or
error messages. You can also open the "Console" app in a separate browser window.
The best way to start programming in Playground is to write simple "Hello World!" script that
outputs the [Information] message "Hello, World!" to web Console window. Following script is
version which additionally outputs the [Error] message "No Error!" to show possibility to
output different types of messages in different colors using logger function.
//
// Playground Hello World Script
//
// This script will print Hello World! message in Console window
// in white color and No Error! message in red color
//
var
message =
"Hello World!"
;
logger.information(message);
logger.error(
'No Error!'
);
Clicking on Run icon script is saved and started. After several seconds, console output should
print following messages:
2020-10-22 12:35:57.7 [Information] osp.bundle.io.macchina.webui.playground.sandbox: Hello World!
2020-10-22 12:35:57.7 [Error] osp.bundle.io.macchina.webui.playground.sandbox: No Error!
Already started bundle can be Restarted or Stopped by clicking to respective icon.
DG100 is based on OSP (Open Service Platform) and Service Registry enabling user to write
JavaScript applications that use a services provided by other bundles. A JavaScript program
can discover a certain service by using a simple query language to query the Service Registry
for a service with certain properties. Since bundles can appear and disappear in an
www.decode.rs
31/31