Ethernet Shield Frustrations

TwinDad Jan 26, 2017

  1. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Hi Will

    Can you give me a clue of what you're trying to connect?
     
    Scott Eric Catalano likes this.
  2. Will G

    Will G TrainBoard Member

    19
    13
    2
    Hi Steve,
    My aim is to get some sort of throttle control of DCC++ from my iPhone.

    I've flashed your web socket onto the ESP successfully with my wifi AP details and the ESP connects to the AP fine. The final message on the Arduino IDE serial monitor is "pm open,type:2 0".

    I've been trying to connect to the ESP from Web Throttle but it keeps saying socket closed.

    I'm afraid I'm way out of my depth here but happy to keep experimenting rather than depending on other for help, however any help is very gratefully received.


    Sent from my iPhone using Tapatalk
     
  3. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    OK

    Assuming you have a compatible Web Throttle page running, in the white address box (upper left of page) tap the box to change the default address.
    Note you can hardcode this later.

    The format is something like this ws://192.168.11.8/ws

    Now just change the numerical bits of the address to the IP address of the ESP as it appears on your network, and hit connect.
    The page will instantly confirm if you have a good connection.
     
    Scott Eric Catalano likes this.
  4. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Will,

    I note there is no print of ESP's local IP in that version of the server code. This is just to keep unnecessary serial traffic to a minimum as Base Station gets fed with all serial output.
    If you can't get into your home routers (AP) home page or don't have another method of quickly obtaining that IP, then here's a little mod you can do to the server code.

    In the setup part....

    Add the 3 lines of code indicated, the address will then print in SM at every boot

    Code:
    void setup() {
      initSerial();
      WiFi.mode(WIFI_STA);
      //WiFi.config(ip, gateway, subnet);//Uncomment to initiate a static IP
      WiFi.begin(ssid, password);
      if (WiFi.waitForConnectResult() != WL_CONNECTED) {
        Serial.printf("STA: Failed!\n");
        WiFi.disconnect(false);
        delay(1000);
        WiFi.begin(ssid, password);
      }
      Delay(500);//<====================
      Serial.print("ESP IP address: ");//<========
      Serial.println(WiFi.localIP());//<==========
    
      // Port defaults to 8266
      ArduinoOTA.setPort(8266);.........
    
     
    Scott Eric Catalano likes this.
  5. Will G

    Will G TrainBoard Member

    19
    13
    2
    Hi Steve,
    Many thanks for the help. I've got the IP address and the ESP is connected to my AP, as it prints the IP address and gateway address obtained over DHCP.

    I'm using the trainelectronics.com DCC++ Mobile Controller web throttle, which is what Diego used when you originally posted the code. Entering ws://192.168.1.29/ws (or substituting the port number) yields the message "WebSocket Closed. Please try again." So something is up but I'm struggling to work out what.


    Sent from my iPhone using Tapatalk
     
    Scott Eric Catalano likes this.
  6. Will G

    Will G TrainBoard Member

    19
    13
    2
    I take it back! It has now connected.

    On resetting the Mega running DCC++, I can see the messages coming up in the throttle display. However, commands sent from the web throttle don't appear to be getting through to the Mega (connected to the ESP with Tx-Rx and vv). I've tried turning the track power on and off and the lights in the motor shield don't light (they do if a serial command is sent straight to the Mega).

    Am I right in using Mega pins 0&1 for Rx and Tx (i.e. Serial port 0)?


    Sent from my iPhone using Tapatalk
     
    Scott Eric Catalano likes this.
  7. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    OK,

    Slow down a bit. The page you are using is out of date and not compatible.

    You need this page. Click to enlarge....

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

    However, with it comes with a few caveats! It needs more dependencies to render like the screen shot. On apple devices using Safari, there were issues with certain elements not rendering at all. You could get round that by using Chrome.

    Download here #1275 http://www.trainboard.com/highball/...ource-dcc-station-and-interface.84800/page-64

    If you are running the old page from Dave's site then we'll need to cover all dependencies to make it work locally.
    And for initial testing I recommend you do all this on a PC.

    Let me know about your current set up.
     
    Scott Eric Catalano and sboyer2 like this.
  8. TwinDad

    TwinDad TrainBoard Member

    1,844
    551
    34
    Will, you may want to pick up my WiThrottle code... there's a thread on it in this forum. It will let you connect WiThrottle or Engine Driver apps directly to the DCC++ base station...

    If you'd rather use an app than a web throttle...
     
    Scott Eric Catalano likes this.
  9. Will G

    Will G TrainBoard Member

    19
    13
    2
    Hi Steve,
    Yes, I was running on the old code. I've now got the newer, speedo based, HTML page working and it connects fine.

    Many thanks again for your help! I hope to be able to contribute something on the RFID detection side soon.

    One more dumb question - in which file do I change the cab IDs?


    Sent from my iPhone using Tapatalk
     
    Scott Eric Catalano likes this.
  10. Will G

    Will G TrainBoard Member

    19
    13
    2
    Sorted. Many thanks again for taking the time to help me.

    Will


    Sent from my iPhone using Tapatalk
     
    Scott Eric Catalano likes this.

Share This Page