Update 8/24/2022: Looks like this will be in JMRI 5.2 more than likely. That will cover the download and installation of the files. There has also been a modification to the webserver so that you can use the camera throttle and the normal WebThrottle without it.
For the last few years SVL has been running hybrid ops where we have remote operators and in layout room operators. The remote operators get a engineers view of the track using our CabCam project. This allows our remote engineers to participate and run through trains or trains with light switching with the help of a local brakeman. We are accomplishing this using modified JMRI WebThrottle code and some fancy memory variables that will be explained below.
1. Install the WebThrottle JS and CSS files.
Download the webThrottle.css file and the appropriate webThrottle.js file for your install of JMRI. The file labeled webThrottle 426.js is for JMRI versions 4.22-4.26. webThrottle 5+.js is for JMRI 5.0 and up, it works as recently as 5.1.3.
These files will be placed in your JMRI install folder. This is different for various operating systems but you wan to look for /JMRI/web/js and /JMRI/web/css respectively. Place the .js file in the JS folder and rename it webThrottle.js then place the .css file in the CSS folder and rename it webThrottle.css.
On Windows you will want to copy both of these files before you rename them so you can have a backup in the folder. When JMRI gets updated it WILL write over these files with a new version. If you leave a copy in the folder with a different name it can quickly be swapped back in. Linux and MacOS may have the same issue, but I cannot confirm it.
The following setup will be handled in two sections, one for local internal streaming and control, and the next for streaming to remote engineers on the internet. Local streaming is good for testing or if you end up with too many engineers for a room, but not for the layout itself. Internal setup is useful to do before, as much of the setup applies to remote engineers on the internet.
You must also have every engine you want to run with the CabCam added to JMRI’s roster. You can get as fancy or as spartan as you want with this, you can just add NMRA standard CV definitions decoders to your roster, the important bit is the DCC address is in the roster so it shows up in WebThrottle.
2. Internal SetupFirst you are going to need to get the streaming URL for your CabCam which can be obtained from the CabCam setup instructions. Setting the Memory Variables. Open Tools>Tables>Memory Variables.
When this opens click Add… and a window will pop up. In System Name you want to enter IMWTVIDEOURL:XXXX where XXXX is the address of the engine you are wanting to run with the camera. For instance if I had UP 6936 in my roster I would add IMWTVIDEOURL:6936, and if I also wanted to run BNSF 326 I would add IMWTVIDEOURL:326 to the System Name. Don’t enter anything for User Name, hit Create when done. If you have multiple entries to create you can just keep adding DCC addresses without closing that window by just changing the number at the end.
Now you need your CabCam streaming address. If you have a few cameras you can create parking spots for the camera URLS by adding a new variable and naming it IMWTCAMERAURL:# where # is the camera number. Take your streaming URL, it needs to be a IP stream so it needs to end in something like video.mjpeg or stream.h264 etc, so it will look somewhat like this. http://internalcabcamIP:8080/stream/video.mjpeg
Take that address and put it into Value.
If you have not told this to start automatically head to Edit>Preferences>Web Server> and check start automatically. Or you can go to Tools>Servers> Start JMRI Web Server when you want to start it. Now head to your web browser and navigate to the ip and port of your JMRI web server. The URL should look something like http://internalIPofJMRIwebserver:12080/web/webThrottle.html. 12080 is the default port but you can change that in your settings. When you get to the JMRI WebThrottle page click on the engine you assigned a camera too and you should be presented with your throttle and camera.
At this point you can use the throttle internally to your network or setup a VPN on your router to allow friend and family to remotely operate on your layout. The VPN may honestly be the best way for you to do this with friends as it is the most secure way to do this. I won’t go over how to setup a VPN on your router as there are so many different ways to do it. Just Google your router name and VPN and you should find the instructions.
WebThrottle Over the Internet (WOT)
Sometimes there are use cases where you wouldn’t want to setup a VPN and would rather have your remote engineers go to a URL or your DDNS or external IP addresses and use the throttle. This requires more setup on your end and is more unsecure. A good setting for this is if you have less tech savvy remote engineers, or at a club or historical society etc. To start this off you will need to google how to setup port forwarding on your router. I am again going to leave you to handle this as there are so many different routers. Once you are logged into your router you will need to take the IP of your JMRI computer and have the internal port be your JMRI webs servers port, generally 12080 and then set your external port. You can set this to the same port number or you can change the port to something fun like the number of your favorite locomotive, eg 4014 etc. Just make sure to reference the list of port numbers and their uses so you don’t end up using a important port. Ports above 49152 are pretty much fair game.
To connect to your JMRI Webserver from the internet to make sure you did this right you can google “What is my IP” and insert that into this URL http://externalIP:theportyouchose ex http://126.96.36.199:12080 and you should see your Server.
Next you want to forward the port for your camera. You will input the IP of the camera, port 8080 for the internal port, and then chose an external port you want to use. If you have multiple cameras chose sequential ports eg. Port 49501 for camera 1, 49502 for camera 2 etc. You can test this by going to the stream of your camera using the external IP eg http://yourexternalIP:49501/stream/video.mjpeg and you should see the stream. That URL you used to see the external stream is what you will put into the memory variable above instead of the internal URL for the locomotive you want to allow be remote operated.
One cool thing you can do with this is setup a CNAME off your website and have people go to a subdomain of your website to run trains. This would end up with a URL like http://layout.franksawesomebnsflayout.com:6936 . To do this you will need to log into the DNS section of your domain host. Find the custom records bit and add a CNAME and put whatever you want to come before your websites URL, eg layout, in the hostname bit, leave the TTL, and under data you are either going to put your external IP(this changes so you may need to update this from time to time) or input a URL given to you by a dynamic DNS service like NoIP. These can range from free with some nagging to refresh to a paid service. Many routers have a DDNS service built in but you will need to google how to set that up for your router.
Some words of caution.
One thing to note, anyone with the URL can connect and run a train on your layout while JMRI is running. You can either disable the port forwarding on your router when you are not wanting to allow access, or shut down JMRI. I have not looked into a way to put the webserver behind a login and JMRI does not support secure URLs like HTTPS.
There are some features I would like to add is sound, that currently is missing from this project, but UV4L should be able to do it. The WebThrottle code may need a update to support that.
I would also like to roll this all into JMRI releases at some point.