Introducing DCC++ ---a complete open-source DCC station and interface

Gregg Aug 25, 2015

  1. esfeld

    esfeld TrainBoard Member

    443
    382
    17
    Steve
    Reset router, and even though ESPs do not show up in Device List (yet I can ping) an older ESP stack connects immediately so I doubt that it is a router problem... same set up and Wang Tong stack still will not connect ( WS closed) ..... I've tried with toggle 1&2 up and down .......guess I'll have to just play around and see if I can figure it out. Thanks
    Steve F
     
    Scott Eric Catalano likes this.
  2. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Steve,

    So everything connects to the router.
    It's just the Websocket layer that won't play ball. Websocket is just another layer of the TCP protocol, which we run over our established connection.
    There should be no errors is the Address definition or that will return the same error. Must be ws://***.***.***.***/ws
    The switches on the shield have nothing to do with the WiFi. As part of the stack, 1 and 2 should be in the on position and that just connects the RX TX serial
    lines to the Arduino, which we need for it all to work. Switches 3 and 4 do the flash mode pin config, and are off for normal operation.
    Try running the web page on a PC in Chrome the debug features can sometimes help in the console view.

    Edit; Just for comparison when I hit connect the Websocket should be there almost instantaneously if there is a delay then I've usually got the address wrong somewhere.
    Older versions of server code had a port number in the address, the newer code will not work with that.
     
    Last edited: Jul 20, 2016
    sboyer2 and Scott Eric Catalano like this.
  3. Curn

    Curn TrainBoard Member

    752
    500
    32
    My WiFi shields came in last week. Earlier posts seemed like UK Steve was still working on the server code, but the last few posts make it seem like the server code is available for tinkering.. Did I miss a link to a repository?

    Matt
     
  4. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Hi Matt,

    First an apology to Steve F and others including yourself. I really should fully test things before I post about them.
    Reference post #1397 programming your Wang Tongze shields.
    Sorry guys as some of you are finding out, it doesn't work like that.
    However the theory is correct, so I've found a quick hack for anyone who doesn't have an FTDI Usb to Serial converter to hand and needs to get their shield programmed.
    Please note: The ESP RX TX is not 5V tolerant and this method circumvents the on board TTL level shifting circuits (which were causing the problem using the other method for some reason).
    Use this method at your own risk !!!

    In the photo below you can get away with just 3 jumper leads and of course your USB connection.
    Power the shield from the Uno using +5v to +5v and ground as you see below.
    Plug the TX RX pins of the debug port into the Uno exactly as shown.
    Finally jumper the Uno Reset to GND.
    Set the shield DIP switches to 1 and 2 OFF, 3 and 4 ON.
    It's now in flash mode.
    I've tested with the Arduino IDE and a few flash tools using a .bin file. It does work.
    When assembled as part of your stack switches 1 and 2 need to be on, with 3 and 4 turned off.

    Server code available here http://www.trainboard.com/highball/...ource-dcc-station-and-interface.84800/page-66
    Post #1317. Change the file extension to .ino

    20160721_130640.jpg
     
    Last edited: Jul 21, 2016
    Scott Eric Catalano likes this.
  5. esfeld

    esfeld TrainBoard Member

    443
    382
    17
    Steve
    Unfortunately after extensive testing I must, at this point, assume that my Wang Tong board is defective. I can load the ESP8266 sketch and verify it’s presence on the network and successfully ping the IP but can not get DCC Server to connect. My other home made ESP boards on the same stack connect as designed so I know that the UNOs are functioning yet the Wang Tong continues to issue an immediate disconnect. As usual, thank you for your assistance.
    Steve F
     
    Scott Eric Catalano likes this.
  6. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Steve,

    Please try this version of the server code. It's a slimmed down version with no Spiffs support, but has an additional raw TCP connection availability.
    Do the usual with the extension and your network config.
    Once flashed to wang tongze try connecting a TCP app to it on port 23. (Putty or similar, even a TCP cellphone app works great.)
    Send some commands to base station, <s> is a good start.
    See above for a flash hack.
     

    Attached Files:

    Last edited: Jul 21, 2016
    Scott Eric Catalano likes this.
  7. esfeld

    esfeld TrainBoard Member

    443
    382
    17
    Steve
    I have been able to load the ESP sketch by using the 5 pin "debug" port connected to an FTDI/USB through a simple 4 wire breadboard connection as depicted
    FTDI.JPG
     
    Scott Eric Catalano likes this.
  8. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Great Stuff,

    Same route in, seems to be the 'best' way in.
    Hope you have time for testing #1406 just above your post.

    Steve.
     
    Scott Eric Catalano likes this.
  9. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Steve F,

    If you manage to get a good connection over TCP. We can move on to further tests with Gregg's DCC++ Controller app or JMRI using the same link.
    If that works out then we go back to Websockets and start looking for errors in the firmware or perhaps a broken library file.

    Steve.

    Edit: I've just remembered that you add a small modification to your sketch effectively to fix the device IP. Could you post an example of how this is done. It's possible some conflicts are occurring depending how the final configuration presents to the network.
     
    Last edited: Jul 21, 2016
    Scott Eric Catalano likes this.
  10. esfeld

    esfeld TrainBoard Member

    443
    382
    17
    Steve
    Loaded the #1406 sketch .... doesn't seem to be working as pressing the reset button I get no blue light response from the ESP which I always got in the old sketch. Since I added my static IP code to it I will go back and insure that I didn't corrupt anything.
    Steve F
     
    Scott Eric Catalano likes this.
  11. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Ha Ha,

    Cross post on the same subject, and we're probably closing in on the problem.
    I know the sketch is good, as it's the same one I've been testing today. Websocket and TCP working fine.
     
    Last edited: Jul 21, 2016
    Scott Eric Catalano likes this.
  12. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Screenshots with that same firmware,

    Screenshot_2016-07-21-15-46-50.png Screenshot_2016-07-21-15-48-52.png

    My cellphone here, has both a Websocket and TCP simultaneously
     
    Last edited: Jul 21, 2016
    Scott Eric Catalano and sboyer2 like this.
  13. esfeld

    esfeld TrainBoard Member

    443
    382
    17
    Can't get your new code to accept my static IP code ...... it compiles and uploads but I get no response from an IP scan ......... I inserted the code as follows ...... could you check it out? It works in the old code but I'm not sure I have it in the right place in your new code.

    void setup() {
    // Update these with values suitable for your network.
    IPAddress ip(10,0,0,11); //Node static IP
    IPAddress gateway(10,0,0,200);
    IPAddress subnet(255,255,255,0);

    initSerial();
    SPIFFS.begin();
    WiFi.mode(WIFI_STA);
    WiFi.config(ip, gateway, subnet);
    WiFi.begin(ssid, password);
    if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.printf("STA: Failed!\n");
    WiFi.disconnect(false);
    delay(1000);
    WiFi.begin(ssid, password);
    }
    //ArduinoOTA.begin();
     
    Last edited: Jul 21, 2016
    Scott Eric Catalano likes this.
  14. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Hi Steve,

    I done some digging.

    https://github.com/esp8266/Arduino/issues/128

    Apparently ESP needs .config() AFTER .begin()
    Contrary to the Arduino documentation.
    Not tried it myself, sure you can give it a go.

    S.

    See also, last comment on the link by thorathome
    I would also move the declarations outside of setup()
    move them up to just under #include's and #define's.
     
    Last edited: Jul 21, 2016
    Scott Eric Catalano likes this.
  15. esfeld

    esfeld TrainBoard Member

    443
    382
    17
    Steve
    Thanks, tried Config() after Begin() and 57600 .. no help. I'll keep playing. What is frustrating is that I have it working as I originally coded it in your old sketch.
    Steve F
    Edit: Serial Monitor reports:
    scandone
    state:0->2 b0
    state:2 -> (0)
    state:3 -> (10)
    add 0
    aid 9
    connected with zoom, channel 6
    ip:10.0.0.11,mask:255.255.255.0,gw:10.0.0.200
    cnt
    ets Jan 8 2013, rst cause:4, boot mode:(1,6)
    wdt reset
    ........................................
    looks like it is correct but not sure about "wdt reset"
     
    Last edited: Jul 21, 2016
    Scott Eric Catalano likes this.
  16. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Watchdog timer reset.

    Can be hard to find a cause, but usually something is wrong in the code. Bad loops and other odd things causing sram memory crashes are stuff I've encountered before.
    Can you not for the sake of testing a working setup and your numerous devices, run the code without the modification.
    A little inconvenience I know, but if everything then works reliably, we've narrowed down the cause.
    That will give me some time to implement the additional code in some tests and hopefully lead to a working solution for you.

    Regards

    Steve.
     
    sboyer2 and Scott Eric Catalano like this.
  17. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Static Client IP on ESP8266 Update.

    Steve F and All following this Wifi issue

    Good morning, I've had a little time to check a few things and overall the outlook is good.

    As your home router is at the heart of this system it may be best if you do not try circumventing the DHCP feature unless the firmware can reliably handle
    such a senario. You'll need to explore the firmware GUI to see what the best options are. The ESP is a client to the network, and conflicts can occur as you are currently experiencing.

    My home router runs the DD-WRT firmware which is very comprehensive and highly configurable.
    Nothing breaks when I configure the ESP to define it's own IP address, meaning the ESP firmware is quite stable on my network.

    However, here are some observations.
    My router does not report the address that the ESP has assigned to itself. It reports the address that it's DHCP server has assigned.
    I can only think that it works because the router does some kind of hidden redirection when another device requests a route to
    the 'new' IP address.

    Most routers will allow a static IP client configurations to be entered via the GUI, you'll need the full MAC address of each client device. I can't advise on how you might achieve this,
    so you'll have to break out the manual or study the GUI pages on your PC.
    And for sure it is probably best that static IP's are set up on the Router (Host) rather than the ESP (Client).
    This is not an issue for me, as DD-WRT effectively does all that by default with DHCP.

    Basic Server code attached
    I've run this today and it's working fine on my router, it may not work on yours !
    The Static address is reported correctly in the serial debug.
    Websocket and TCP requests connect instantly. Note only 1 TCP at a time.
     

    Attached Files:

    Last edited: Jul 22, 2016
    sboyer2 and Scott Eric Catalano like this.
  18. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Here are my observations:
    When a router is in DHCP mode as well as any client computer or device, the router assigns an IP address to the connecting client from an IP range that the user specifies in the routers DHCP table. Some routers in my experience (Netgear, Linksys) you can assign an IP Address to a specific device using the DHCP reserved IP address range which acts like a Static IP address and this is based on the clients MAC address or assigned name. This is done without changing the wired/wireless adapter settings on the client device as this is done via the router only. Now regarding Static IP addresses internally which you have to set both the client wired/wireless adapter and the router to static ip address mode. You have to assign a specific IP address, Subnet, Gateway, and DNS to the client device and you have to set the router to Static IP address mode and range.
    As you can see there are many options/settings that have to be set internally to make things work.
     
    sboyer2 and UK Steve like this.
  19. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    And one more thing,

    Ultimately it's the MAC address that is the destination, so don't assign the same IP address to several different device MAC's, the router is logging each change for future
    reference and even 2 devices with the same IP is gonna cause you trouble !
    Only use addresses that have not been used before, even if some device is long gone from your network it's history will still be in a table somewhere,
    a factory reset or a table entry deleting option would be the best option to free up old assignments that you might want to reuse.
     
    Last edited: Jul 22, 2016
    sboyer2 likes this.
  20. esfeld

    esfeld TrainBoard Member

    443
    382
    17
    Steve, Eric, ALL

    I have had no trouble setting a static IP in UK Steve's original sketch using the code I previously posted and it works as it should on my home made ESP shields.

    Steve, I have tried the new sketch as is, devoid of my static IP code, uploading using the same set up to the Wang Tongze shield and am getting “wdt reset” errors as before … I have tried inserting wdt_disable() to no avail. Due to its low profile I was hoping to get it to work, but will have to continue to use my home made ESP shields with their static IP configuration until I can solve the WT shield problems. At this point I think it may be an amperage issue (as the ESP has a high current requirement) since you have tested the code sufficiently or perhaps some anomaly in the WT shield itself as I have no problem loading to my ESP shields.

    EDIT: Tried your (non FTDI setup) as pictured above ....... still get wdt reset on upload. Can you tell that I'm getting desperate? :)
     
    Last edited: Jul 22, 2016
    sboyer2 and Scott Eric Catalano like this.

Share This Page