Yet Another Robot Platform
YARP ports process HTTP requests with a default interface suitable for viewing their status, receiving bottle-compatible messages, and writing bottle-compatible streams. This is not a general purpose web-server, or something you'd expose to the general public on the internet. HTTP service comes is implemented by the http carrier; for other carriers, see Configuring YARP Connections.
To form the URL for a yarp port /PORT, we need to know the IP address of the machine it lives on, and the (socket) port number it listens to. One way to get this information is with yarp name query -
yarp name query /PORT
For example, let's look at the YARP name server's port, by default called /root (or whatever "yarp namespace" reports). For me, that is reported to be here:
registration name /root ip 192.168.1.3 port 10000 type tcp
Then the URL we need to reach this port is:
Visiting that address in a browser, I see something like this:
yarp port /root (All ports) (connections) (help) (read) This is /root at tcp://192.168.1.3:10000 There are no outgoing connections There is an input connection from web to /root using http
This is the index page for that port, and it reports information analogous to that given by yarp ping. You can view this page for any YARP port.
You can send data to a port by appending w?data=... to its base URL. For example:
For my case, that will send a bottle containing the string "list" to the name server, which will respond with a list of all ports.
Or, if I could send a vector of three floating point numbers 10.0, 30.0, and 40.0 to a port called /adder by finding its address and port number, then visiting:
The format of the data parameter is regular Bottle text format (the "+" symbol is URL encoding for the space character).
Viewing data sent by a port is done by visiting:
This will sit and wait for messages and render them as Bottle text format. For example, doing:
yarpdev --device test_motor --name /motor
Gives a vector stream at port /motor/state:o. Finding its URL and then visiting "http://.../r" gives:
yarp port /motor/state:o (All ports) (connections) (help) (read) Reading data from port... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Buffering behavior varies from browser to browser - YARP does its best to flush data in a timely fashion but you may have to try different browsers or browser settings to get good results.
Image streams can be viewed in the browser if the mjpeg carrier has been enabled.
For example, doing:
yarpdev --device test_grabber --name /grabber --framerate 5
We can now view the /grabber port image output at the following URL:
and see the image in any browser that understands MJPEG streams (firefox and chrome for sure).
We can also visit:
as before, but that will give images in text format, which is slow and not very helpful...
For the record, the mjpeg carrier currently intercepts any URLs of the form "http://.../?ac". Other URLs are handled by the default http carrier.
If you do succumb to the temptation to make a mini-webserver, YARP >= 2.3.15 will help you a little. Requests that don't match the patterns above are passed on to the port in bottle-compatible format; you may simply reply to them to generate a custom webpage. See the example web/web_test.cpp. Be aware that this is a new feature of YARP that is not yet nailed down, so you may need to change your code when using the next version of YARP.