My talk from #emfcamp 2022 in which I cover how to connect a model railway to the national rail network using JMRI.org and kits from MERG.org.uk, along with some custom code I've published at https://github.com/modelrailwaysascode/pywithrottle
2. @proffalken | github.com/modelrailwaysascode | github.com/proffalken
What’s the dream?
A completely autonomous model railway, utilising the
Network Rail Open Data feeds to move trains around
the layout in real-time.
“
”
5. @proffalken | github.com/modelrailwaysascode | github.com/proffalken
Network Rail data feeds and the Open Rail Data community
●
https://wiki.openraildata.com/
●
Amazing source of information on the various data formats that Network Rail make available via their
API’s
●
https://datafeeds.networkrail.co.uk/ ← Sign up here to get access to the data!
●
Be careful, data comes in multiple formats, and not all formats contain all the data…
7. @proffalken | github.com/modelrailwaysascode | github.com/proffalken
JMRI – The brains of the operation!
●
Java-based
●
Multiple applications depending on what you want to do
●
It uses Jython!
●
Jython is really old…
●
It supports MQTT!
●
MQTT requires yet more “stuff” to be setup
●
It has a TCP-based API called WiThrottle for control via mobile devices!
●
The WiThrottle API is… unique
8. @proffalken | github.com/modelrailwaysascode | github.com/proffalken
WiThrottle – RL2][RGS 41}|{41}|{L][Test Loco}|{1234}|{L
●
It uses [
[ and ]
] to differentiate between locomotives
●
It uses {
{ and }
} to show the values for settings
●
The settings are always in the same order…
●
… but never as key=value
key=value pairs
●
Commands use three characters in a row to delimit: <;>
<;>
●
All feedback is sent as new lines, but you don’t know when it’s finished sending feedback
9. @proffalken | github.com/modelrailwaysascode | github.com/proffalken
WiThrottle – Setting a function
M0AS3<;>F110
M0 = Throttle ID
A = Send an “action” to a locomotive
S = Make sure we’re using DCC “short” mode
3 = The DCC channel we need to target
<;> = That weird choice of delimiter
F = Set a Function
1 = Either 0 (Off) or 1 (On)
10 = The function to act against (from 00 to 99)
10. @proffalken | github.com/modelrailwaysascode | github.com/proffalken
WiThrottle – Moving the loco
M0AS3<;>V50
M0 = Throttle ID
A = Send an “action” to a locomotive
S = Make sure we’re using DCC “short” mode
3 = The DCC channel we need to target
<;> = That weird choice of delimiter
V = Set the speed (v == Velocity?)
50 = A value between 0 and 126
11. @proffalken | github.com/modelrailwaysascode | github.com/proffalken
WiThrottle – Switching Direction
M0AS3<;>R0
M0 = Throttle ID
A = Send an “action” to a locomotive
S = Make sure we’re using DCC “short” mode
3 = The DCC channel we need to target
<;> = That weird choice of delimiter
R = Set the direction
0 = Either 0 (Reverse) or 1 (Forward)
16. @proffalken | github.com/modelrailwaysascode | github.com/proffalken
What next?
●
Build a proper layout rather than the test track
– Find a suitable location (St. Ives Branch line?)
– Model it
– Work out the TIPLOC/STANOX codes for each section
– Write the integration based on PyWiThrottle
●
Continue to update PyWiThrottle to add more functionality (Contributors welcome!)
●
Create more fun distractions timewasters projects under the “Model Railways as Code” banner