Welcome to the forum   
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post in this topic Go to first unread post in this topic
Offline nygma  
#1 Posted : 05 March 2019 15:38:34(UTC)
nygma

Hungary   
Joined: 15/04/2015(UTC)
Posts: 64
Location: Budapest, Budapest
Hi Everyone,

I have a Marklin Gauge 1 layout in the garden and some of my points are difficult to get to (tree in the way). I only have 6, so it is not a huge layout, but a problem nevertheless. I am trying to use as little computers on my layout as possible, so I thought I will build my own switch board to control my points. But I figured I should still use accessory decoders and servos to control the points.

I connected and ESP32 microcontroller to my CS2 and I started listening on the CAN bus. Once I figured out what messages control the points, I started sending the same messages out. Now I can control my points via my ESP.

So the next step if to build a second ESP32 with buttons for my bespoke switch board. Have the to ESP32 communicate with each other via Wifi and the first ESP relays the messages to CAN bus.

I am not sure if anyone has done this before. Of course this would not be limited to accessory decoders, but it is much easier to understand the messages of those than locomotives.

If don't have a code ready yet, but you can see how it is working here:
thanks 10 users liked this useful post by nygma
Offline dennisb  
#2 Posted : 06 March 2019 10:41:12(UTC)
dennisb

Sweden   
Joined: 21/09/2015(UTC)
Posts: 217
Location: Kronoberg
This is very interesting! I think this has a really good potential for, like in your case, remote switch boards! Looking forward to see further updates on this!


Offline DaleSchultz  
#3 Posted : 06 March 2019 18:52:56(UTC)
DaleSchultz

United States   
Joined: 10/02/2006(UTC)
Posts: 3,997
excellent!
Dale
Intellibox + own software, K-Track
My current layout: https://cabin-layout.mixmox.com
Arrival and Departure signs: https://remotesign.mixmox.com
Offline nygma  
#4 Posted : 02 January 2021 19:19:17(UTC)
nygma

Hungary   
Joined: 15/04/2015(UTC)
Posts: 64
Location: Budapest, Budapest
Anyone who is following this topic:
after a very long pause I dug up this project and made some progress. The external point control works fine already, I can send point motor messages from a website and it is accepted by the control box, or CS2.

But as a next stage of the project, I wanted to turn my MS2 to a truly wireless controller. The idea is what the MS2 is connected to a microcontroller over CAN, which communicates with the second microcontroller over Wifi which puts the original CAN messages back to the CAN bus connected to the Control Box.
And it looks like it is working one way but the not the other. Maybe the control box is confused as where these messages originate form.
Anyway, for longer explanation check the video:
thanks 2 users liked this useful post by nygma
Offline ajoreis  
#5 Posted : 16 December 2021 14:36:40(UTC)
ajoreis

Germany   
Joined: 27/01/2013(UTC)
Posts: 3
Location: Dortmund
Hi there,
I have a similar project, I send messages directly to my CS2 via WLAN and an ESP and am looking for a solution how I can control locomotives with a throttle.
Could this also be done with your solution?
Could you adapt your sketch so that it sends it directly to the CS2?
Do you have some instructions for the hardware and the sketch, can I buy that?
Here is an example of my solution.


Quote:
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char* ssid = "xxxxxxxx";
const char* password = "yyyyyyy";

char * HostName = "192.168.67.141"; // Zieladdr
const uint16_t HostPort = 15731; // Zielport
const uint16_t LocalPort = 15730;

WiFiUDP udp;


bool sendMessage(const byte * data)
{
if(udp.beginPacket(HostName,HostPort))
{
Serial.println("beginPacket ok");
}else
{
Serial.println("beginPacket err");
}

udp.write(data, 13);
Serial.println(" Bytes writen");

if(udp.endPacket())
{
Serial.println("endPacket ok");
}else
{
Serial.println("endPacket err");
}
}

void setup(void)
{
Serial.begin(115200);
Serial.println("");
Serial.println("setup begin");


if (WiFi.mode(WIFI_STA))
{
Serial.println("to AP ok");
} else {
Serial.println("to AP err");
}

while (! WiFi.begin(SSID, PASSWORD))
{
Serial.print(".") ;
yield();
}
Serial.println("WiFi begin ok");

if(WiFi.waitForConnectResult() != WL_CONNECTED)
{
Serial.printf("Could not connect to %s\n", SSID);
while(1) delay(500); // Brutaler Halt
}


while (! udp.begin(LocalPort) )
{
Serial.print("+") ;
yield();
}
Serial.println("UDP ok");
Serial.print("setup end\r\n");
}

void loop(void)
{
static unsigned long timestamp;
byte can1[13] = {0x00, 0x23, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00}; // Besetzt Sende CAN message Adresse 1 an
byte can2[13] = {0x00, 0x23, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00}; // Besetzt Sende CAN message Adresse 1 aus

//byte can1[13] = {0x00, 0x16, 0x03, 0x00, 0x06, 0x00, 0x00, 0x38, 0x00, 0x01, 0x01, 0x00, 0x00}; // Weichen Befehl Sende CAN message
//byte can2[13] = {0x00, 0x16, 0x03, 0x00, 0x06, 0x00, 0x00, 0x38, 0x00, 0x00, 0x01, 0x00, 0x00}; // Weichen Befehl Sende CAN message

byte can3[13] = {0x00, 0x16, 0x03, 0x00, 0x06, 0x00, 0x00, 0x38, 0x01, 0x01, 0x01, 0x00, 0x00}; // Weichen Befehl Sende CAN message
byte can4[13] = {0x00, 0x16, 0x03, 0x00, 0x06, 0x00, 0x00, 0x38, 0x01, 0x00, 0x01, 0x00, 0x00}; // Weichen Befehl Sende CAN message


if(millis() - timestamp > 10)
{
sendMessage(can1);
timestamp = millis();
delay(10000);
sendMessage(can2);
timestamp = millis();
delay(10000);
sendMessage(can3);
timestamp = millis();
delay(10000);
sendMessage(can4);
timestamp = millis();
delay(10000);
}
}

Thank you for a short answer

Olaf
Offline nygma  
#6 Posted : 16 December 2021 15:18:20(UTC)
nygma

Hungary   
Joined: 15/04/2015(UTC)
Posts: 64
Location: Budapest, Budapest
OK, I thought I made an update on this project, but I did not. So I need some time to get all this documented. Because I will want to make the sketches available, in fact one of them is already in Github:
https://github.com/nygma2004/marklin_can_wifi

And I also have a PCB for a controller and also for base station as well. But I have not released the designs yet. But I will do.

I also made this update video on the boards:


So please allow me some time and I will release all the files and upload them to Github with the PCB boards as well.

I am pretty sure this can be made to a throttle as well. I just need to spend more time understanding how to loco control signals are sent, and I guess there could be some differences between DCC, motorola and Mfx. But in your code it looks like you already send loco commands over UDP so you got that figured out. On my layout I am using MS2, so this is why I am sending the signals directly to the control box via CAN.
Offline kiwiAlan  
#7 Posted : 16 December 2021 15:37:17(UTC)
kiwiAlan

United Kingdom   
Joined: 23/07/2014(UTC)
Posts: 7,395
Location: ENGLAND, Didcot
Originally Posted by: nygma Go to Quoted Post

I am pretty sure this can be made to a throttle as well. I just need to spend more time understanding how to loco control signals are sent, and I guess there could be some differences between DCC, motorola and Mfx. But in your code it looks like you already send loco commands over UDP so you got that figured out. On my layout I am using MS2, so this is why I am sending the signals directly to the control box via CAN.


Sounds like you need to reference the CS2 protocol manual that is available from Marklin.

I did a google translate of it and put it in a zip file.
CS2 CAN Protocol 2-0 Translated_files.zip (356kb) downloaded 155 time(s).

Perhaps both these links could be put in Bigdaddys list

Offline nygma  
#8 Posted : 16 December 2021 19:55:34(UTC)
nygma

Hungary   
Joined: 15/04/2015(UTC)
Posts: 64
Location: Budapest, Budapest
I think I have that, just I guess controlling a loco is lot more involved that controlling simple accessories. I need to dive into this again, I parked this project almost a year ago.
Offline ajoreis  
#9 Posted : 21 January 2023 14:03:25(UTC)
ajoreis

Germany   
Joined: 27/01/2013(UTC)
Posts: 3
Location: Dortmund
Hello Nygma,

I took up this topic again and I have a question regarding Märklin CAN-Wifi Gateway sketch v1.0 from your github, I would like to connect two gateways with each other, unfortunately this does not seem to work.
The gateways do not send any messages to each other, but if I connect them to the CS2 and trigger an action via WEB, this is also sent to the CAN bus. Unfortunately, if I connect an ESP module to the CS2 and set up the second ESP module and only carry out an action via WEB browser, the CS2 does not notice it.

I took the same port for the WIFIServer TCPserver(8040) on both ESPs, so that the two ESPs could talk via port 8040. Or does something else have to be done here with the WifiClient?

I also had to adjust the sketch a bit because I didn't get all Liberies (display).
Maybe I have an error in the sketch there too.

If you already have a small solution there that would help me further, that would be great.

Many thanks for any information or help.

Olaf
thanks 1 user liked this useful post by ajoreis
Offline nygma  
#10 Posted : 21 January 2023 22:06:29(UTC)
nygma

Hungary   
Joined: 15/04/2015(UTC)
Posts: 64
Location: Budapest, Budapest
Originally Posted by: ajoreis Go to Quoted Post
Hello Nygma,

I took up this topic again and I have a question regarding Märklin CAN-Wifi Gateway sketch v1.0 from your github, I would like to connect two gateways with each other, unfortunately this does not seem to work.


Hi Olaf, I got your email as well, but I did not reply yet. To be honest it is almost 2 years since I last working on this project and I need to find some time to go back and understand again what I have done. But in theory I don't think why it would not work. Assuming the entire Can->Wifi->Can communication can be as fast as the Can only communication. But I think the amount of traffic on the Can bus is not that huge.

So I will try to find the time and go back to your question in the future. Feel free to send me a chaser email.

Csongor

Offline ajoreis  
#11 Posted : 25 January 2023 19:05:21(UTC)
ajoreis

Germany   
Joined: 27/01/2013(UTC)
Posts: 3
Location: Dortmund
Hello Csongor,

Many thanks for your answer, I wasn't sure if mine had arrived (still exist). Everything is fine and don't stress and take your time.

Best regards ThumpUp

Olaf
Users browsing this topic
OceanSpiders 2.0
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

| Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.591 seconds.