console

The console object provides access to the systems’s debugging console.

console.log(message)

Outputs a debug message to the console

console.info(message)

Outputs an informational message to the console

console.warn(message)

Outputs a warning message to the console

console.error(message)

Outputs an error message to the console

 

Worker

Worker(path)

Creates a new worker instance that runs in the background independently of other scripts.

worker.postMessage(message)

Send a message to the worker instance.

message:

The object to deliver to the worker; this will be in the data field in the event delivered to the worker’s global onmessage handler. This may be any value or JavaScript object handled by the structured clone algorithm.

worker.terminate()

Terminate a web worker, and free its resources.

worker.onmessage = function(event) {}

The onmessage handler is called on a Worker object when the worker’s parent receives a message from its worker (i.e. when the worker sends a message using global.postMessage()).

The message itself is available in the message event’s data attribute

Example:

server.jss:

worker.jss:

Open

Serial

Serial()

Creates a new serial instance

serial.open(device, options)

Opens the specified device.

device:

Device driver path such as “/dev/ttyAMA0” or “/dev/ttyUSB0” etc.

options:

  • baudrate (number) – Baud rate such as 9600 or 115200 etc.
  • databits (number) – Number of data bits. Possible values: 5, 6, 7, 8
  • parity (string) – Enable parity checking. Possible values: “odd”, “even”, “none”
  • stopbits (number) – Number of stop bits. Possible values: 0, 1, 2
  • xonxoff (boolean) – Enable software flow control.
  • rtscts (boolean) – Enable hardware (RTS/CTS) flow control.

serial.close()

Close device immediately.

serial.send(data)

Enqueues data to be transmitted.

data:

Data to be transmitted..

serial.flush()

Flushes both data received but not handled (by onmessage handler), and data sent (by send method) but not transmitted.

serial.onmessage = function(event) {}

onmessage handler is called whenever any data are available.

event.data:

Data received.

serial.onerror = function(event) {}

onerror handler is called whenever there is any error.

event:

The error object representing the cause of error.

Possible error types:

  • RangeError when parameter are out of range, e.g. baud rate, data bits.
  • Error when the error is generated by the underlying operating system

serial.onsuccess = function(event) {}

onsuccess handler is called whenever the requested operation finishes successfully. (such as: open, flush, close)

Server

Implements the web application server functionalaties. (e.g.: handles http request, handles websocket connections, handles remote method invocations, user management, etc.)

server.onconnect(client) 

onconnecte method is called when there is a new client request to connect.

A new client request can either be:

  • accepted by returning true
  • rejected by returning false (In this case the client will get HTTP-404 Forbidden)

server.onopen(client)

onopen method is called when the new client is connected. After that, the client can invoke remote methods defined in the server instance or the server can notify the client. (client.notify)

Do not forget to call base method (super.onopen(client))

server.RM_[method name](request, …)

Method names starting with “RM_” are remote methods, thus can be called by the clients.

A remote method invocation can be either be resolved or rejected asynchronously by calling:

  • request.resolve(value)
  • request.reject(value)

Or a request can either be resolved or rejected synchronously by:

  • returning any value except undefined
  • throwing an exception
If a remote method returns undefined and never calls request.resolve or request.reject then the invocation will never be responded.

Example:

server.jss:

Open

Pin

A class to control the GPIO pins.

Pin(device, pin)

Creates a new pin instance.

device:

Device driver or sysfs interface path. (For example: On Raspberry PI: “/sys/class/gpio”, on stm32: “GPIOD”)

pin:

Pin number

pin.value

Synchronously sets/gets the value of the pin instance. 

Possible values: 

  • 0 for low
  • 1 for high

pin.direction

Synchronously sets/gets the direction of the pin instance. 

Possible values: 

  • 0 for output
  • 1 for input

pin.onchange

Synchronously sets/gets the onchange method of the pin instance.  This event handler is called on both rising and falling edges.

 

 

PWM

A class to control the GPIO pins.

PWM(device, pin)

Creates a new pin instance.

device:

Device driver or sysfs interface path. (For example: On Raspberry PI: “/sys/class/pwm/pwmchip0”, on stm32: “PWM”)

pin:

Pin number

pwm.period

PWM period in nanoseconds.

pwm.duty_cycle

PWM pulse width in nanoseconds.

 

0