DCC-EX / EX-T3-WiFi

ESP32 based WiFi throttle for DCC++
GNU General Public License v3.0
15 stars 4 forks source link

Throttle not sending commands to CS #105

Closed FECRwy closed 3 months ago

FECRwy commented 3 months ago

Hi, I've recently built one of the T3 throttles. After a couple of early mistakes(not uploading the Filesystem Image and the code), I was able to get my screen displaying the throttle. I wasn't able to connect to the throttle settings by using DCCEX but could when I used the IP address of the throttle on my network. I then setup a couple of locos and a custom function screen. All of this seemed to work correctly. However, when I then tried to enter a loco, by number or name, I get the next screen with no function buttons and no speed or direction information. I have checked a LocoNet viewer and there is no information coming from the T3 throttle. I get information from iPhone and Android throttles but not the T3. My CS sees the T3 and the screen indicates both WiFi and CS connection,

I think it must just be a communication link that I overlooked but I am at a loss. I have checked my wiring and programming several times and not found any errors or mistakes.

Could anyone please offer some suggestions as to what to do next. I can provide more info if you give me some idea of what.

alex-code commented 3 months ago

Are you on the latest CS code? There's some broadcast features used by the throttle.

FECRwy commented 3 months ago

Hi Alex, Yes, I downloaded the latest code as far as I know. I also used the most recent version of PlatformIO and had to obtain a GIT file in order for the software to load onto the throttle. All appeared okay.

alex-code commented 3 months ago

Does the track power button work if you try that? Just trying to see if any commands are sending.

FECRwy commented 3 months ago

No, I've tried other buttons such as the accessory ones, the only buttons that appear to function are the ones in the Loco section. and the Settings section.

alex-code commented 3 months ago

Are both icons at the top showing as connected (WiFi and CS).

FECRwy commented 3 months ago

Yes

FECRwy commented 3 months ago

Alex,

I may have misled you a bit. If I press the accessory button I do get another screen asking for me to input the number however I do not see any traffic on the LocoNet viewer. The throttle does not appear to be transmitting any data after pressing the button.

Rob

Rob Leathley Hampton, New Brunswick


From: Alex @.> Sent: Tuesday, March 19, 2024 4:58:39 PM To: DCC-EX/EX-T3-WiFi @.> Cc: FECRwy @.>; Author @.> Subject: Re: [DCC-EX/EX-T3-WiFi] Throttle not sending commands to CS (Issue #105)

Are both icons at the top showing as connected (WiFi and CS).

— Reply to this email directly, view it on GitHubhttps://github.com/DCC-EX/EX-T3-WiFi/issues/105#issuecomment-2008009422, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BHDX5TTBND7ILZ36Q7QIAATYZCKG7AVCNFSM6AAAAABE6EBXNKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBYGAYDSNBSGI. You are receiving this because you authored the thread.Message ID: @.***>

alex-code commented 3 months ago

I'm not sure what loconet is so can't say if that's having an effect.

One way to check if the throttle is sending data would be to try the basic CS emulator. You'll need to install Python but you can then run cs_emulator.py (included with all the code). This will start a local server and show output in the terminal window to help debug. Just change the CS IP address on the throttle to the one of the computer running the server.

FECRwy commented 3 months ago

First the good news. I was able to successfully install Python and run the emulator. The screens and buttons work as expected and there is information in the Terminal window that appear to be correct to me. One thing, I did notice that the function buttons didn't come up until I turned the encoder. I will look into this on my system to make sure that I haven't missed this before.

I tried using my CS IP and I get the same, no response. I imagine that there is something I still need to do with my configuration but I don't know where to start looking.

LocoNet is a network buss system for Digitrax devices to communicate between each other. Other companies, such as NCE, have similar but LocoNet is by far a more complete system. Anyway, my CS is made up of a MEGA clone with two IoTT 5amp Power Shields and an IoTT Red Hat with a M5Stack Stick running communication software. IoTT is a brainchild of Hans Tanner and comprises a number of IoT devices that can be hooked up to a model railroad. Hans has both a YouTube Channel and a Tindie store. The Red Hat has an interface for LocoNet and his software can show what is happening on the buss, so all commands controlling the layout and locomotives are shown. He has videos outlining making a DCCEX command station with his devices. I am just following along with some of those ideas. As stated before, the CS works fine with both Android and iPhone devices as wireless throttles.

I hope that helps explain more about my system. I'm open to suggestions as to do what next?

alex-code commented 3 months ago

Could you confirm the CS version you're using?

I wonder if this might be because I use the native DCC Ex commands and not wiThrottle so the commands aren't forwarded.

FECRwy commented 3 months ago

BINGO! I believe that you have the answer. The software is WiThrottle compatible but I don't think it is aware of native DCCEX commands. I'll check with Hans to see if there is a solution from his end.

I appreciate your help in solving my problem. I apologize for missing the obvious. You have a nice throttle here. One day I hope to be able to interface it to my layout.

alex-code commented 3 months ago

Having done this throttle I've found the world of DCC is far more varied than I ever thought. I've only ever used a Mega with WiFi shield.

Hopefully it'll be easy to support native commands in IoTT Red Hat.

FECRwy commented 3 months ago

Thanks for all of your help. I'll figure something out now that I know where I made my mistake.

FECRwy commented 3 months ago

Hi Alex, Well it seems that the problem is not so easily dismissed. I have written Hans and he confirms that the WiThrottle server is both WiThrottle and native DCC-EX compatible. I checked this out by running both my iPhone with WiThrottle app and an Android table running Engine Drive in DCC-EX mode. Both worked with the layout no problem. I then tried reprogramming the FireBeetle. I got no error messages. I reset the T3 WiFi settings and the throttle does indicate that it has successfully connected to both the network and the CS server. I still cannot get it to control an engine.

Using the CS emulator, it appears to work fine. Here is a copy of the dialogue: C:\EX-T3-WiFi\EX-T3-WiFi-master\cs_emulator.py:55: SyntaxWarning: invalid escape sequence '\d' r = re.search("<t (?P\d+) (?P\d+) (?P\d+)>", cmd) Socket successfully created socket binded to 2560 socket is listening Got connection from ('192.168.2.84', 63381) << << <t 3000> << <t 3000 126 255>

<l 3000 0 32767 0>

<< <t 3000 1 0>

<l 3000 0 2 0>

<< <1> << <0>

Any suggestions as to what I should look at next?

FECRwy commented 3 months ago

Don't know why the strikeout font above. It is not that way in the dialogue.

alex-code commented 3 months ago

I can't find much documentation on IoTT or code so unable to check myself.

You could try using telnet to connect to IoTT to send some native DCC Ex commands to see if they get through.

FECRwy commented 3 months ago

Here's a link to Hans' IoTT GitHub page: https://github.com/tanner87661/IoTTStick/tree/master You should be able to find what you are looking for as he uses Open-Source.

I did a bit more testing and discovered that if I am running my CS with an Engine Driver throttle app I can enter a Loco and run it and as I do, the results are echoed on the T3 screen. In other words, If I select Loco 3000 on my ED throttle, the T3 will display that Loco and show both the speed and direction as well as the Function buttons. Additionally pressing a Power On button on the ED throttle will show the Power Buttons on the T3 light up too. Unfortunately, I can not seem to acquire a Loco with the T3 throttle and control it. It should be noted that the CS also was connected to a WiThrottle app on my iPhone and was able to run Locos at the same time as the ED throttle app.

It appears that the IoTT DCCEX CS is functioning correctly. It does exactly as it should and works both WiThrottle app and Engine Driver app throttles together. The T3 throttle appears to connect to both the wireless network and the CS correctly. The only issue here is that I must use the IP address of the CS and not "dccex". I can add Locos and create custom function screens via the web page configuration. Unfortunately it just will not communicate to the CS so that it can control a Loco. I'm not sure if the T3 throttle needs to send a DCCEX native command in order for the CS to recognize that it is using native DCCEX commands and this is what my CS is missing or if there is just a missing port number or something preventing the communication. BTW, as to port, I use 2560 as default throughout.

Thanks for your continued help.

alex-code commented 3 months ago

That's an idea, maybe IoTT expects some sort of handshake/negotiation from throttles so it knows to pass commands on.

Will see what I can find.

alex-code commented 3 months ago

Are you able to connect your IoTT to a computer at the same time as it being on the board?

Looking at the code it has serial output which may help debug and see where it gets too. There's a serial monitor built in to the Arduino IDE.

FECRwy commented 3 months ago

Unfortunately the M5 Stick uses the serial communication line to do things. You can't have the Arduino serial monitor on at the same time. At least that is my understanding.

FECRwy commented 3 months ago

This is some feedback I got from Hans. Perhaps this can narrow down our problem source.

The WiThrottle server of the IoTT Stick does support the DCC-EX mode. In fact, it automatically detects it and switches automatically. It can even serve some phones using WiThrottle protocol and others using DCC-EX. You can try that out with EngineDriver.

By default, it is set to Withrottle commands. To switch the connection over to DCC-EX, it requires the init string as sent by the ED app. If I remember right it is a string containing “DCC-EX” and a software version. Check the ED protocol to see what exactly is send right after connecting in DCC EX mode. Your throttle needs to do the same and the Stick should switch to DCC EX mode for that connection.

Please give it a try and let me know.

alex-code commented 3 months ago

I've not got an M5 stick or any of the IoTT modules so can't confirm but think I know why it's not working after looking at the IoTT code.

It looks like IoTT won't process a command until it sees a new line character \n.

You can try this on the power command. If you add _csClient.write("\n"); after line #77 in src/DCCExCS.cpp then compile and upload.

If that does work you can add that new line after each occurrence of _csClient.write(...); until I can update (working on other changes).

FECRwy commented 3 months ago

Well success, sort of. I tried adding the single line and recompiling the code. I got nothing. I then reedited the code by adding the line in front of all the occurrences and recompiled. This time it sort of worked but was very slow to get the CS to respond. Might this be a timing issue? In addition, I was only able to get the Power Switch to work. Trying to control an engine did nothing.

What I found was that it took several presses of the Power buttons to get any response. This did not seem to me to be a question of double tapping a button but rather a lag in the sending and receipt of a command. I also found that the Power buttons did not react as I expected. Pressing ALL OFF or ALL ON didn't turn the power to Main or Prog off or on immediately and required me to press it several times. As I said, it seems like a timing issue.

alex-code commented 3 months ago

You could try changing lines #75-#76 to this.

char buf[10];
sprintf(buf, "<%d%s>\n", state ? 1 : 0, cmd);

So it's sent as one.

There's no delays in the throttle, if a button is pressed it's cmd is sent.

FECRwy commented 3 months ago

That works fine on the Power Buttons. Does exactly as expected with no wait.

No response for the Loco buttons but I suspect you are just trying to use the Power buttons to try to fix this for now.

alex-code commented 3 months ago

Maybe IoTT doesn't buffer cmds so it has to all be in one send.

Will need to increase the buf size by 1 and add a \n to each function between >", e.g. >\n"

void DCCExCS::acquireLoco(uint16_t address) {
  char buf[12];
  sprintf(buf, "<t %d>\n", address);
  _csClient.write(buf);
}

void DCCExCS::releaseLoco(uint16_t address) {
  char buf[12];
  sprintf(buf, "<- %d>\n", address);
  _csClient.write(buf);
}

void DCCExCS::setLocoThrottle(uint16_t address, int8_t speed, uint8_t direction) {
  char buf[20];
  sprintf(buf, "<t %d %d %d>\n", address, speed, direction);
  _csClient.write(buf);
}

void DCCExCS::setLocoFn(uint16_t address, uint8_t fn, bool state) {
  char buf[18];
  sprintf(buf, "<F %d %d %d>\n", address, fn, state);
  _csClient.write(buf);
}
FECRwy commented 3 months ago

Yes, that works. I can acquire a Loco and set the speed and direction. The Function buttons work too.

I tried the Emergency Stop and it didn't work so I added "\n" in _csClient.write("<!>\n"); That seemed to do the trick. Now, what other commands should I edit so that this can be finally solved?

alex-code commented 3 months ago

For the others if they have buf it'll need increasing by 1 then adding \n

So

char buf[11];
sprintf(buf, "<W %d>", address);
 _csClient.write(buf);

becomes

char buf[12];
sprintf(buf, "<W %d>\n", address);
 _csClient.write(buf);

For getLocoAddress() it'll be _csClient.write("<R>\n");

FECRwy commented 3 months ago

Thank you for you work. I made those changes and it seems to work as expected. I do some more running and tests over the weekend. I'll also inform Hans as he was interested as well.

alex-code commented 3 months ago

Thanks for helping test on this too. I'll add these changes so it'll be included in newer versions.