1

Update: Examples from library are working if DHCP is enabled!

Using this library I try to connect with static IP but it always say DNS failed. Ethernet module is blinking that means is good connection also static ip is correct..

Question: What is hisip and how can this module connect to internet with static IP`?

Connections :

VCC -   3.3V
GND -    GND
SCK - Pin 52
SO  - Pin 50
SI  - Pin 51
CS  - Pin 53 # Selectable with the ether.begin() function

Code:

// This demo does web requests via DNS lookup, using a fixed gateway.
// 2010-11-27 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <EtherCard.h>

#define REQUEST_RATE 5000 // milliseconds

// ethernet interface mac address
static byte mymac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };
// ethernet interface ip address
static byte myip[] = { XXX, XXX, 216, 199 };
static byte gwip[] = { XXX, XXX, 216, 126 };
static byte dnsip[] = { 8, 8, 8, 8 };
// remote website name
const char website[] PROGMEM = "google.com";

byte Ethernet::buffer[300];   // a very small tcp/ip buffer is enough here
static long timer;

// called when the client request is complete
static void my_result_cb (byte status, word off, word len) {
  Serial.print("<<< reply ");
  Serial.print(millis() - timer);
  Serial.println(" ms");
  Serial.println((const char*) Ethernet::buffer + off);
}

void setup () {
  Serial.begin(57600);
  Serial.println("\n[getViaDNS]");

  if (ether.begin(sizeof Ethernet::buffer, mymac, 53) == 0)
    Serial.println( "Failed to access Ethernet controller");

  ether.staticSetup(myip, gwip);

  if (!ether.dnsLookup(website))
  Serial.println("DNS failed");
  ether.printIp("Hisip: ", ether.hisip);
  ether.printIp("Myip: ", ether.myip);
  ether.printIp("Gateway: ", ether.gwip);
  ether.printIp("DNS: ", ether.dnsip);

  timer = - REQUEST_RATE; // start timing out right away
}

void loop () {
  ether.packetLoop(ether.packetReceive());

  if (millis() > timer + REQUEST_RATE) {
    timer = millis();
    Serial.println("\n>>> REQ");
    ether.browseUrl(PSTR("/foo/"), "bar", website, my_result_cb);
  }
}

Output:

[getViaDNS]
DNS failed
Hisip: 0.0.0.0
Myip: XXX.XXX.XXX.199
Gateway: XXX.XXX.216.126
DNS: 8.8.8.8

>>> REQ

>>> REQ
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.