Skip to main content

Lab 12: WebSockets

Websocket node-type Example
Websocket node-type Example.

In this lab we will show you the VILLASnode WebSockets mockup. The mockup is a simple webpage which receives / sends simulation from / to VILLASnode by using low latency WebSockets.

This technique is useful for live monitoring and user interaction with simulations.

The configuration file

node/etc/labs/lab12.conf
nodes = {
udp_node1 = {
type = "socket"
layer = "udp"

in = {
address = "*:12000"

signals = {
count = 8
type = "float"
}
}

out = {
address = "127.0.0.1:12001"
}
}

web_node1 = {
type = "websocket"

vectorize = 2
series = (
{ label = "Random walk", unit = "V" },
{ label = "Sine", unit = "A" },
{ label = "Rect", unit = "Var" },
{ label = "Ramp", unit = "°C" }
)
}
}

paths = (
{
in = [ "udp_node1" ]
out = [ "web_node1" ]

hooks = (
# We do not want to overload the WebBrowsers
{ type = "decimate", ratio = 2 }
)
},
{
in = [ "web_node1" ]
out = [ "udp_node1" ]

# Web -> UDP does not require decimation
}
)

Start node and signal generator

villas signal -v 4 -r 120 mixed | villas pipe -x lab3.conf udp_node1 &
villas node lab12.conf

Web Mockup