WebGui

javadoc

Warning: This is not quite up to date.

 

The WebGUI is a mini webserver and websocket server.  Most people are familiar with what a web server can do.  Web servers take requests and server content.  Typically, they do not allow allow full duplex communication over a long period of time.  Websocket do allow this behavior.  One large benefit of this, is web pages can start behaving like complex applications.  "Refreshing" a page to get new information is no longer required.

Those are the 2 protocols the WebGUI offers, it also has 2 interfaces.

The "Web Interface" and the REST API.

The Web Interface uses websockets to provide a HTML5 interface to MyRobotLab.  This is the direction we would like to take the GUI.  The current state however is very new and there are many bugs.

The REST API does not use websockets, but it is an exteremely powerful interface.  The reason its so powerful is that it offers a graphical display of every single function a running instance of MyRobotLab has to offer.  And any one of these methods can be invoked through this interface.

[[WebGUI.py]]

The script above should start the WebGUI and auto launch a browser to the appropriate address.  It will bring up the initial home page.

From here you can go to either the "Web Interface" or the "REST API".
The Web Interface is "pre-beta" and missing alot of information. It's is designed to be closely integrated with each specific Service.

REST API

REST - stands for REpresentational State Transfer, and API stands for Application Programming Interface.
Simply, its a way to make MRL do what you want just by sending it a set of URLs.  You may explore what it can do by clicking on the REST API link. This might show you the following view.

This will show what Services are currently running.  In this instance, I'm running a Python, GUIService, Runtime and WebGUI.  You may click on service and it will expand a set of methods which can be invoked from another URL.

Each and every method a Service can do will be listed.  I opened the runtime service, the Runtime service is capable of starting other services.  Here you can see I am about to start a new Arduino service names "arduino".  Sometimes, the question mark (?) is linked to helpful documentation which explains the service.  Often the elves have not bothered to write down any helpful documentation :(

Each text box represents a parameter which the method will want.  In the case of Runtime.start, the start method requires 2 parameters.  A "name", and a Service Type.  The button is very simple, it just concatenates the parameters and creates a new URL.  (The button really is not needed, just the URL)

So, in this example I press the button and http://127.0.0.1:7777/services/runtime/start/arduino/Arduino is sent to the webgui.  And runtime.start is called with the 2 parameters.

And then .....

We get a new Arduino service named arduino ! 

And this can continue. Now if you look at the Arduino, you can "connect" and supply a parameter. 
For example 

http://127.0.0.1:7777/services/arduino/connect/COM15 

will connect the Arduino to an Arduino on COM port 15.

<<TODO - Arduino>>

<<TODO - Runtime>>

<<TODO - Clock>> others? Shoutbox

 


#file : service/WebGui.py edit raw
WebGui = Runtime.create("WebGui","WebGui")

WebGui.hide('cli')
sleep(1)
WebGui.show('cli')
sleep(1)
WebGui.set('cli', 400, 400, 999)

# if you don't want the browser to 
# autostart to homepage
#
# WebGui.autoStartBrowser(false)

# set a different port number to listen to
# default is 8888
# WebGui.setPort(7777)

# on startup the WebGui will look for a "resources"
# directory (may change in the future)
# static html files can be placed here and accessed through
# the WebGui service

# starts the websocket server
# and attempts to autostart browser
WebGui.startService();

Examples:


#file : service/WebGui.py edit raw
WebGui = Runtime.create("WebGui","WebGui")

WebGui.hide('cli')
sleep(1)
WebGui.show('cli')
sleep(1)
WebGui.set('cli', 400, 400, 999)

# if you don't want the browser to 
# autostart to homepage
#
# WebGui.autoStartBrowser(false)

# set a different port number to listen to
# default is 8888
# WebGui.setPort(7777)

# on startup the WebGui will look for a "resources"
# directory (may change in the future)
# static html files can be placed here and accessed through
# the WebGui service

# starts the websocket server
# and attempts to autostart browser
WebGui.startService();