DCC++ Ethernet - Specifying Static IP

joelalbi Apr 29, 2019

  1. joelalbi

    joelalbi New Member

    4
    0
    1
    Hello Everyone,

    I discovered DCC++ yesterday and thanks to Amazon have now got a Mega, Ethernet Shield and Motor Shield and as far as i can tell so far everything is plugged together and doing what it should.

    One thing i cant figure out it how to disable DHCP for the Ethernet and set a static IP.

    I have a feeling i've missed something really obvious and would appreciate a pointer.

    Thanks in advance,

    Joel.
     
  2. esfeld

    esfeld TrainBoard Member

    442
    382
    17
    Joel ... you neglected to state what Base Station code you are using with the Mega. Here is a code sample that should help you .. obviously the first 7 lines are what you will need to insert into whatever code you are using:
    // begin static IP code
    const char *ssid = "YourSSID";
    const char *pass = "YourPassword";

    // 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);

    void setup()
    {
    WiFi.begin(ssid, pass);
    WiFi.config(ip, gateway, subnet);

    //Wifi connection
    while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    }
    Serial.println("");
    Serial.print("WiFi connected, using IP address: ");
    Serial.println(WiFi.localIP());
    }

    void loop()
    {
    }
    // end static IP code
     
  3. joelalbi

    joelalbi New Member

    4
    0
    1
    Apologies, i downloaded the code from https://sites.google.com/site/dccppsite/ and went for the official release 1.2.1

    It doesn't look like its been updated for a while - is that the best source?

    I'm not actually using a Wifi shied, just the standard Ethernet one with the W5100 controller.

    Thanks,

    Joel.
     
  4. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    You can configure it in the Config.h file of the Arduino BaseStation code, you will need to set the COMM_INTERFACE to the right value depending on the Ethernet shield and library you will be using.
     
  5. Jimbo20

    Jimbo20 TrainBoard Member

    274
    178
    11
    Alternatively, if you can log in to your router settings, you may be able allocate a fixed IP address in the dhcp server settings.
     
    Onizukachan likes this.
  6. joelalbi

    joelalbi New Member

    4
    0
    1
    Hi Jimbo20

    I think you might have the easiest solution here as i can see in config.h where to define the MAC so ill just set up a DHCP reservation rule in the router as you suggest.

    I am a bit surprised that there isn't a setting in here to define the IP although I'm sure someone with more programming knowledge than me could figure it out!

    Thanks,

    Joel.
     
  7. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    I'm guessing you missed this: https://github.com/DccPlusPlus/BaseStation/blob/master/DCCpp_Uno/Config.h#L36-L41

    Uncomment line 41 and set it to the IP you want to use. It will then use that IP address every time and not require you to alter anything on your AP.
     
  8. Pieter

    Pieter TrainBoard Member

    152
    46
    10
    If you follow Atani's advise and uncomment and supply your own IP, DCC++ will automaticly ignor DCHP. Otherwise it will use the DHCP setting on your router.
     
  9. joelalbi

    joelalbi New Member

    4
    0
    1
    That is great - it turns out the code on Github is newer/different to the one on the Google site for the DCC++ project.

    I will download the the one off Github and give it a go.

    Thanks again,

    Joel.
     
  10. Onizukachan

    Onizukachan TrainBoard Supporter

    752
    1,198
    24
    Thos is exactly why I upgraded my router last year, I got tired of having to program every device with a static up address. That’s 20+ devices to be programmed by hand.
    My new router supports assigning up based on MAC address, so my servers (yes plural, two for video, 1 for books, and 3 different instances of JMRI and wi throttle) can be set and stay where they need to be, even when there is a power outage and everything comes back on out of order!
     
    Atani likes this.

Share This Page