Go Down

Topic: Compiler error when trying to use a static IP on ethernet shield (Read 867 times) previous topic - next topic


Hi, long time lurker, first time poster here.

I just got my first ethernet shield and am not quite sure what I am doing wrong, some help would be much appreciated.

I have an Arduino UNO and an ethernet shield with the WIZnet W5100 chip on it.

The first thing I did was take the default Webclient example, load it on the Uno, and it worked great, I was able to see the data in the serial monitor. I did change the address for google as the default one was not working for me.

The network this is going to be on does not have DHCP or DNS, so my next step was to change the default webclient example to use a static IP.

I followed reference at http://arduino.cc/en/Reference/EthernetBegin

My code:
Code: [Select]

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0x90, 0xA2, 0xDA, 0x0D, 0x45, 0x2B };
byte ip[] = {  10, 20, 0, 211 };
byte dns[] = {  10, 20, 0, 200 };
byte gateway[] = {  10, 20, 0, 1 };
byte subnet[] = {  255, 255, 255, 0 };
IPAddress server(173,194,33,33); // google.com

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
// Open serial communications and wait for port to open:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  // start the Ethernet connection:
    Ethernet.begin(mac, ip, dns, gateway, subnet);
  // give the Ethernet shield a second to initialize:

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.0");
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");

void loop()
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();

  // if the server's disconnected, stop the client:
  if (!client.connected()) {

    // do nothing forevermore:

The error I get when compiling is:
webclient_demo_google_com_staticIP:23: error: 'byte dns []' redeclared as different kind of symbol
C:\Arduino\arduino-1.0.3\libraries\Ethernet/Dhcp.h:64: error: previous declaration of '<anonymous enum> dns'

If I am understanding correctly, DNS is being referenced in DHCP.h? I don't want to use DHCP.h, I am not sure what to do.

Thanks for the help.


This is the problem. dns is already declared in the ethernet library.
Code: [Select]
byte dns[] = {  10, 20, 0, 200 };
// change to something like this
byte dnServer[] = {  10, 20, 0, 200 };

// start the Ethernet connection:
Ethernet.begin(mac, ip, dnServer, gateway, subnet);


Just change the name! What a simple fix. Thanks for the help.

Go Up