2019-03-12

Mobile phone layout control app

I have always liked the idea of being able to control my layout from anywhere in the room. As technology has changed over the years I have implemented this capability in various forms.

First there was a PDA version (2005) that worked very well, but the hardware became redundant.
I then redid it using HTTP so it could be controlled from any browser. This works pretty well but I never got around to making the images update without doing a full screen refresh. I also added the capability to control things by voice, but that is not conducive to cab control.

Now that I have found ESP8266 and Blynk technology I have implemented a third system that runs on Android or iOS which I present here.

There are 6 tabs in the app and the most interesting tab is of course:

Cab control tab



The cab control allows one to pick any train that is on the layout (from an alphabetic list of the trains). Once a train has been selected, its current status is displayed on the screen. This comprises:
  • Train name, and address of first locomotive in the train. (Umbau in the example)
  • The track view at its current location (no camera required!)
  • If any signals are present, the current signal aspect is shown
  • The speed limit for the track section (10 means 100Km/h)
  • The current, and desired speed of the train, in text form as well as with visual scales
  • A direction toggle button, showing current direction
  • An emergency stop botton
  • A manual control toggle button.
  • Up to eight function buttons corresponding to f0 through f7 of the first loco in the train, labeled with their functions, and indicating their status.
  • A layout power toggle button (green oval) that allows layout-wide track power to be switched on or off

As the train progresses around the layout, the track images, signals, speed limit, speeds and functions are all updated in real time!

Speed slider control
This lets the user set (or override) the desired speed for the train. The train will adjust its speed to attain that speed, be it faster or slower than the desired speed. When the train is running in automatic mode, the desired speed is being continually adjusted by the layout software. If the Manual control button has been turned on though, the computer will not alter the desired speed but do all the acceleration and deceleration work to bring the train speed to the desired speed. This creates a mode in which the user needs to pay attention to the speed limits and signals and regulate the train speed accordingly. (Future feature: when the train passes a distant signal, the operator must acknowledge it or an emergency brake will be applied.)

Function buttons
Functions that are switched on, are indicated with a blue background.

In this example, the signal has turned green. Smoke, sounds and acceleration functions have been turned on, manual control is in effect, and the desired speed has been set to 42km/h

It is fun to monitor the progress of a train around the layout using the screen.

The cab control can also handle the case where the selected train is removed form the layout, and perhaps placed in another location. The removal and placement is done in the main layout software and the cab control is kept informed of the events. Say the train 'Umbau' is removed:

The cab would display:
Once placed on a track again the new information is displayed (in this case, the adjacent track with a higher speed limit):

Power tab

The power tab shows the main power modes of the Intellibox; stop, on, and halt. If I shake the phone fast, it will switch the layout to stop mode!

This tab also allows me to toggle an important layout-wide setting that allows the software to ignore sensor alerts in places where a train is not expected to be, and is not reserved for human controlled shunting.
Network connectivity with the Layout software (Betriebswerk), wi-fi signal strength and a firmware update button (OTA), round out this tab.

K83+S88 tab

This screen is useful for troubleshooting problems around the layout. Any electromagnetic accessory device address can be selected, and the current state and description of the red and green modes of that address are displayed on buttons. Pressing the buttons will set that address to the selected color.
In this example, address 56 has been selected. The k83 is currently set to red - which is used to set signal 70 to Aspect Hp00. If the green button is pressed, it will set address 56 to green which will set signal 70 to Hp0Sh1. (Note this is not how signals are controlled, this functionality is for testing.)
On the lower part of this tab we can select an s88 port to monitor. When a port is selected, a  description of what it monitors is displayed. When the s88 goes 'high' (on) the green light will be illuminated.

Stations tab

This screen lets one pick a station, then, pick a track in that station, and then select a destination to which the train on the selected track can be dispatched.

In this example, the Station called 'Wilsnack Hbf.' has been selected. Only the tracks within that station can then be selected, and track 5 containing a train called 'Umbau' has been chosen. Destinations that are appropriate for that train from that track are then presented in the third pull down list, and I have elected to send it to my hidden station called 'Schatten'.

Once a train has been selected, a small button appears that allows that train to be selected in the cab tab, another button sends the command to dispatch the train on the route to the destination.
The recycle button will refresh the tracks in the station as new trains may have arrived or others departed since the station was selected.

Events tab

The events tab allows one to select from the events that have been defined for the layout, from an alphabetic list. This can be sound effects, accessories such as switching on  a welder, chimney smoke, or starting sunset or sunrise sequences, etc.


Log tab

The last tab allows one to display the last 25 lines of the system log

Architecture

  • The user interface on the phone is created using Blynk.
  • The programming code that drives the display and fetching of data over wi-fi runs on a small ESP8266 processor
  • The code uses the RemoteSign command set to request and receive data from my Betriebswerk layout software.
  • The layout software connects automatically to the Cab device over a persistent TCPIP connection, and the device informs the layout software that it has cab control capabilities.

Data flows
When the layout software connects, and finds out that the device has cab capabilities, it sends the following information:
  • Power status
  • 'Ignore unexpected trains' status
  • List of trains on the layout
  • List of stations
  • List of events
  • Betriebswerk version 
When a train is selected, the cab registers its interest in that train. That precipitates the following information to be sent to the device:
  • URL of the track image
  • URL of signal image
  • Speed limit for current track
  • Current, and desired speed
  • Current direction
  • List of functions
  • List of function states
The data is then repeated whenever there is any change.

When a station is selected, the device requests a list of tracks for that station. Betriebswerk responds with a list of tracks and if a train is present, the name of the train.

When a station track is selected, the device requests a list of destinations for that track and train present. Betriebswerk responds with a list of destinations.

When the layout software disconnects from the device, all data lists are emptied out, images are blanked out, and function buttons are hidden, etc.

I could have more than one cab device running at a time. Each is simply defined as a RemoteSign and handled independently.

Availability

This app would not be any use to you unless you are running your layout using Bw.