new alternative train firmware using MQTT

Forum about the OS-Railway project available on Thingiverse. Here you can ask questions, look at building pictures, share ideas, pictures and STL's.
aligator
Posts: 4
Joined: Sat Jul 25, 2020 8:25 am

new alternative train firmware using MQTT

Postby aligator » Sat Jul 25, 2020 8:58 am

hi

I just started a new firmware for the trains which uses MQTT for communication. https://github.com/aligator/OSRailwayTrain

For all who don't know what MQTT is:
It is a simple Protocol to send messages to iot devices. It works very well with the ESP-8266.
Every client can listen to specific topics and then receives the messages automatically.

Advantages:
- MQTT is widely used for iot and therefore there are many tools/apps to communicate with it.
- It is also very lightweight and efficient on the client side.
- The protocol needs only a low band-with.

Disadvantage:
- MQTT needs a server (broker). But this is no problem if you already use it for other iot projects.
And also if not, it's easily set one up using a raspi (using Mosquitto, https://github.com/eclipse/mosquitto, https://randomnerdtutorials.com/how-to- ... pberry-pi/). There is even an implementation for the esp-8266 (https://github.com/martin-ger/esp_mqtt) but I haven't tested how it performs...

Because I had problems using the official firmware (it behaved very strangely on my esp...) I decided to write my own.
Currently my solution is only based on MQTT so there is no webinterface. But it can already be used using any mqtt app. I use https://play.google.com/store/apps/deta ... x.mqttdash for testing currently.

It is built using the Platformio platform (basically a better library management and IDE support than plain Arduino, still uses the Arduino framework).

I already have some ideas how to improve the firmware. For example I would like to write a OSRailway controling software using a web-ui (I will very likely write this webserver in Golang.)

Finally it is possible (and I think very easy) to also write a firmware for the remote control which is compatible with my train firmware.

I am open to suggestions and help :-)

admin
Site Admin
Posts: 409
Joined: Thu Jan 11, 2018 7:46 pm

Re: new alternative train firmware using MQTT

Postby admin » Fri Jul 31, 2020 10:44 am

Hi!

Thanks for your contribution! I have dreamt of a unified open source software development for this project for a long time. I will go through this when I get home, I'm out traveling today but when we have something started that is worth publishing I will add links to all the thingiverse pages. I will get back on this hopefully now during the weekend!

aligator
Posts: 4
Joined: Sat Jul 25, 2020 8:25 am

Re: new alternative train firmware using MQTT

Postby aligator » Tue Aug 04, 2020 5:35 pm

Ok,
I have to finish my train first, but then I could start working on a remote control firmware as the next step. I haven't looked into the existing remote control firmware yet, but I think it should be easy possible. I could also implement something like auto-discovery using mqtt, like posting the train name on activation of the train in a special mqtt-channel which the remote listens to.

Feel free to post your ideas about this project.

admin
Site Admin
Posts: 409
Joined: Thu Jan 11, 2018 7:46 pm

Re: new alternative train firmware using MQTT

Postby admin » Thu Aug 06, 2020 10:09 pm

Hi, ok, please post some pictures or video when you have it up'n'running. :) I'm currently waiting for TTGO boards with ESP32 that I ordered. Those seems to be very nice and could be very suitable at least as remote control platform to simplify construction and add performance.

aligator
Posts: 4
Joined: Sat Jul 25, 2020 8:25 am

Re: new alternative train firmware using MQTT

Postby aligator » Sun Aug 09, 2020 3:12 pm

Hi,

I will have to order one of these board's too :D Looks interesting.

And I already started an initial version of a Control software which is basically a little webserver which connects to a mqtt-broker and also serves a simple web-ui.
The idea is to put it together with a mosquitto-broker onto a Raspery Pi.
https://github.com/aligator/OSRailwayControl

And here are two videos with the ui in action. (my train is partly finished by now, still waiting for the weight, because the train is to light...)
https://cloud.j-code.de/s/EZrCtgYASkeqJkc

I also extended the train firmware by an autodiscovery so that it gets automatically displayed in the ui when it get's active. You can see that in one of the vids.

admin
Site Admin
Posts: 409
Joined: Thu Jan 11, 2018 7:46 pm

Re: new alternative train firmware using MQTT

Postby admin » Mon Aug 10, 2020 9:58 pm

haha! I've never seen an entire train track drift! :D What motor did you use?

Would be nice if you could publish a make on Thingiverse of the locomotive, then add in the make-description a description of your software project and links. I think that would be much appreciated! :)

aligator
Posts: 4
Joined: Sat Jul 25, 2020 8:25 am

Re: new alternative train firmware using MQTT

Postby aligator » Thu Aug 13, 2020 11:52 am

I use this one https://www.conrad.de/de/p/igarashi-n-2 ... 44520.html

Yeah, I will publish it, when the train is finished :D

I got a step further to it, but there are still some problems to solve:
  • the leds are missing and have to be delivered
  • I am not fully satisfied by my wiring, (currently it is done using jumper wires) I am thinking about soldering a circuit board.
  • the akku I have is a bit too big, maybe I just make the roof in the middle a bit higher...
  • the tires get loose after driving some time. Do you think it would be possible to screw them somehow to the axle? (I use carbon axles) Did you have such problems?
On the software side I also have some progress:
  • I added some basic styling to OSRailwayControl, also I added controls for the lights.
    Image
  • I started another repo for the OSRailwayRemote as my TTGO T-Display arrived yesterday (through amazon not aliexpress). I already got the wifi, mqtt and display working.
My current idea for the remote control is to first display a list of all trains (just like in OSRailway Control) and then using buttons to navigate through them and select one.
Do you already have an idea how you would like to design the remote control?

Kohwalter
Posts: 4
Joined: Wed Dec 09, 2020 1:17 pm

Re: new alternative train firmware using MQTT

Postby Kohwalter » Wed Dec 09, 2020 2:21 pm

What you guys think of a different solution: a central control (can be the remote that stays in your hand) is a device that creates a new wifi network? Then each train connects to this network and you can send commands to and from the trains. I'm thinking on a interface of a small display to present info, some push buttons, maybe some leds and a rotary encoder to adjust the train speed and navigate on the menu, like the Prusa 3D printer.

If the idea is a good one I can start to working on it. I printed some tracks and the base of the freighter car (the chassi and the bogies) but I don't have a locomotive yet. The main problem is to find a suitable motor to drive it. I live in Brazil and some stuff and availability of parts are not the same as in Europe or USA.

Anyway I hope I can contribute with this great project!

admin
Site Admin
Posts: 409
Joined: Thu Jan 11, 2018 7:46 pm

Re: new alternative train firmware using MQTT

Postby admin » Wed Dec 09, 2020 7:52 pm

Hi!

That is exactly what I'm thinking about right now. I'm working on a new version of the remote control, and for that I´ll use a new board that I got recommended and which seems to be extremely nice (cheap and powerful and with TFT integrated!).
It is the TTGO with ESP32: https://www.tinytronics.nl/shop/en/plat ... ft-display
ttgo.JPG
ttgo.JPG (18.72 KiB) Viewed 2214 times
I have not purchased mine from this vendor but they can be found in many places, but this is among the beset prices I've seen so far.

I was thinking just like you say to have a server in the remote control and have the trains connect to it. I haven't started modeling the housing or made any schematic yet, I have just managed a "hellow world" at this point, but it seems to be a nice little board and incredible value for the money. (and can be used with Arduino IDE as well! )

By the way, did you try my old handheld remote? https://www.thingiverse.com/thing:3252986

Kohwalter
Posts: 4
Joined: Wed Dec 09, 2020 1:17 pm

Re: new alternative train firmware using MQTT

Postby Kohwalter » Thu Dec 10, 2020 12:49 am

This board is a finding! You can just plug a LiPo battery, charge it via USB and already has the display. I found one seller that has just unity to sell here in Brazil (there is another one but twice the price). I won't buy it for now because I have no locomotive yet.

I think that if you create an access point with the ESP32 you can connect the trains to this network and send two bytes via TCP (or even via UDP): one for the desired speed and another with 8 digital states (one for the direction of the train and other 7 more, like lights). I made a test today using two Wemos D1 mini and it is working. Now it's just a matter of create the hardware. I need to comment the code and share it on github.

I'm terrible at design so I based on your old control design, yes. I implemented a "inertia" on the train control so it changes the speed from the current speed to the desired speed at a constant rate, like a constant acceleration.

I don't know what is the most important requirements that you have to the system. What is necessary? What is recommended?


Who is online

Users browsing this forum: No registered users and 3 guests