You are not logged in.

rcmodeler

Schrankenwärter

(21)

  • "rcmodeler" started this thread

Posts: 35

Location: Sweden

  • Send private message

1

Friday, November 1st 2019, 1:51pm

Control model railroad with Wifi and Mqtt

What is that?
Well, Wifi communicates without wiring and Mqtt is the way things talk to each other.
It is a smart, flexible and cheap way of controlling almost everything on a model railway.
Most known in the popular home automation systems but it can of course be used anywhere.
It can be connected to internet, but it can also be used in a closed, local network.
A wireless router is needed to provide wifi and if there isn't any wifi where the railroad is,
or if it not a smart idea to interfere with the rest of the family's web activities,
a separate router doesn't cost much.

There is a lot of Youtube videos on how to use this on a model railroad and I just want to show
how I do to make things work the way we want to.

I don't have any model railroad myself but my brother is building a new layout with Lenz track
and Lenz DCC turnout motors, and I have been given the task to get everything running.
As we don't live in the same town, I am building the electric parts in my home and visit him
once a week for testing and mounting.

The room he is building his layout in is about 7 x 3,5 meters, with a track in to another room where there is a small yard and a workshop.
There will be four separate trackplans and we will not sit and drive, we will walk around with wireless remotecontrols.
There will not be any automated driving, everything is done manually but with wireless remote control.
This is the way we want to do it.

We use the existing wifi in the house, with a range extender in the room where the railroad is.
The base in Mqtt is something called a "broker", everything goes thru that broker.
The "broker" is a computer program and for that we need some kind of computer where this can be installed.
It is possible to use a standard PC, but that is not a good idea. It can be used for testing.
We use a Raspberry Pi 3+ with built in wifi. It cost about €40 (+ €20 for power adapter if you don't have one) and
that is the most expensive part in this system. A small SD-card is also needed.



There is many installation guides on how to install the operating system on the Raspberry, so I wont go in to that,
but it is quite easy to follow the instructions on Raspberrys website, Raspberry Pi .
Make sure to make the right wifi-connections.

Then we need an Mqtt-broker, that is the only program (apart from the operating system) that we need to install.
We use a program called Mosquitto, it's free and it is probably the most popular, but there is other choises.
After installing Mosquitto that part is done and we don't have to touch that anymore.

As I have a couple of 3D-printers I printed out a small case, there is many to choose from on Thingiverse.



Then there is just one important thing we have to do, the Raspberry must have a static/fixed adress (ip-number) in the router.
So we are logging in to the router and in the LAN-settings we choose DHCP and assign a static adress.
How this is done can vary in different routers but this must be done.
It is also a good idea to write this IP-adress down, because it will be needed later.

And it is ready to run.


To be continued…..

6 registered users thanked already.

Users who thanked for this post:

barilla73 (01.11.2019), AliSpur0 (01.11.2019), werkzeugmacher (02.11.2019), Altenauer (02.11.2019), derfranze (06.11.2019), Udom (10.11.2019)

rcmodeler

Schrankenwärter

(21)

  • "rcmodeler" started this thread

Posts: 35

Location: Sweden

  • Send private message

2

Monday, November 4th 2019, 5:02pm

Got some interesting information from a member at another forum.
He said it is possible to use the Raspberry Pi for creating a local network, then you don't need another router.
I have not tested that method but I might do it later. Raspberry Pi and Linux is new to me.

Well, then there is two ways of fixing the wifi stuff :)

Zoltan

Hilfsbremser

(12)

Posts: 24

Location: Wien

  • Send private message

3

Monday, November 4th 2019, 6:09pm

I use an ESP (vemos d1 mini) and a H-Bridge, simulating a Z21, for full DCC control and steering via Roco Z21 App. The whole costs under 5 € and is 2,5 *2,5 * 3 cm. You can even build it into a loco with accus, and can thus be full independent of the rail voltage.

BR Zoltan
Schaut bei meiner "echten" Dampflok 52.4984 vorbei!
Und hier ist mein YouTube Kanal mit meinen (Bahn)filmen :)

rcmodeler

Schrankenwärter

(21)

  • "rcmodeler" started this thread

Posts: 35

Location: Sweden

  • Send private message

4

Friday, November 8th 2019, 10:10pm

Interesting thing, Zoltan. Can you tell us more about that?

Anyway, we are using DCC++ to get the DCC-signals out on the track. It's a cheap and clever
open source project based on Arduino. I put some links here if you feel like diving in to it.
DCC++ on trainboard
DCC++ on Youtube

We use an Arduino Uno as BaseStation Master to create DCC-signals.


On top of that we put an Arduino Motorcontroller to get the power to the rail.


And on top of that is a prototype board with a step down regulator and a Wemos D1 mini for handling Wifi and Mqtt.


The step down regulator takes the input voltage (16V DC) from the power source and feeds all electronic
on this stack with 5V. Thus we just need one power source.


The Wemos D1 mini subscribes to all Mqtt topic/messages related to DCC (that is Track power, Cab (Throttle and F-functions) and Turnouts)
translate and send them via serial command (TX) to the Arduino Uno/BaseStation Master (RX), which creates and sends out DCC signals to the rail via the Motorcontroller.

This is probably not for anyone to understand, but if you have been playing around with Arduino
then this is really something to look into. Take me, for exampel, I have never worked with It and programming.
It is just a hobby.

To be continued....

5 registered users thanked already.

Users who thanked for this post:

barilla73 (08.11.2019), jbs (09.11.2019), KBS 249 (09.11.2019), Zoltan (09.11.2019), Udom (10.11.2019)

Zoltan

Hilfsbremser

(12)

Posts: 24

Location: Wien

  • Send private message

5

Saturday, November 9th 2019, 9:11am

Thanks for the links.
I am not really deeply interested, for I do not have an own track but only a single lco to drive as a guest somewhere.
But who knows.
For my "thing" see this forum where it goes all abu that.

BR Zoltan
Schaut bei meiner "echten" Dampflok 52.4984 vorbei!
Und hier ist mein YouTube Kanal mit meinen (Bahn)filmen :)