ENC28j60 Ethernet controller as web client

Hi !

This hardware configuration is working as web server perfectly.

I am trying to use ENC28j60 Ethernet controller as web client.

I have got the folowing error:

I try to run a code web client but I can not get the ip of server.

What can be the problem ? Does anyone has this problem ? It is the dns server ? It can not translate the name ot ip. Here is the code.

// This demo does web requests to a fixed IP address, 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,0x33 };

static byte myip = { 192,168,0,190 };

static byte gwip = { 192,168,0,1 };

static byte hisip = { 216,58,209,206 };//

const char website PROGMEM = “www.google.com”;

byte Ethernet::buffer[300];

static long timer;

void setup () {

Serial.begin(57600);

Serial.println(“\n[getStaticIP]”);

if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)

Serial.println( “Failed to access Ethernet controller”);

ether.staticSetup(myip, gwip);

if(ether.dnsLookup (website, false)){

Serial.println( “dnsLookup ok”);

}else{

Serial.println( “dnsLookup faild”);

}

while (ether.clientWaitingGw())

ether.packetLoop(ether.packetReceive());

Serial.println(“Gateway found”);

ether.printIp("My IP: ", ether.myip);

ether.printIp("Netmask: ", ether.netmask);

ether.printIp("GW IP: ", ether.gwip);

ether.printIp("DNS IP: ", ether.dnsip);

ether.printIp("SRV: ", ether.hisip);

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(“/”), “bar”, website, my_result_cb);

ether.browseUrl(PSTR(“/index.html”), “”, website, my_result_cb);

}

}

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

}

The serial log is :

→ dnsLookup

DNS Lookup failed

My IP: 192.168.0.190

Netmask: 0.0.0.0

GW IP: 192.168.0.1

DNS IP: 8.8.8.8

SRV: 0.0.0.0

I think the (sub)netmask is wrong. For a 192.168.(0).? address it must be 255.255.255.0. But I’m not sure where your device gets this from, as it isn’t a defined constant used as input for a function. (in network configuration it is a required item to identify which IP adress’ are local, and which are the rest of the world/interwebs.) Before you do DNS lookups to the internet you need to get the communication with the gateway to function properly on the local network, and this requires a proper subnet setting for your local network. Finding ‘Google’ or ‘the internet’ is a worry for later. Start with pinging to and from pc’s or devices on your local network first. But I don’t know how that is done with this code library. And usually NAT-routers/your home gateway have a setting that makes them unresponsive to ping requests. You may have to find that and enable it in it’s configuration. But your Windows PC should happily respond to ping requests if you have filesharing enabled.

Sorry, I cannot help further but to provide suggestions to investigate further.

Thanks for the answer. The subnet mask is ok. If I use ahother code where this hardware is working as web server, I can ping 192.168.0.190 from my pc. So the 192.168.0.1 gateway is ok. that is my subnet. An I can connet to the arduoino from my pc with crome. But if I wat to use as web client to get some data from web I can not get the connection, (the dns do not relove my name “google.com”). I have traing to write insted of name “www.google.com” in the ether.hisip = the goggle ip addres but still not working. Is anyone use this as web clinet ?

Well, there is a variant of the Ethercard class memberfunction staticSetup which also allows to enter the netmask. See if that makes a difference.

bool EtherCard::staticSetup (const uint8_t* my_ip,
	                             const uint8_t* gw_ip,
	                             const uint8_t* dns_ip,
	                             const uint8_t* mask)

copied from:

https://github.com/jcw/ethercard

https://github.com/jcw/ethercard/blob/m … erCard.cpp

Thank you wery much ! its working !!!

The problem it was the mask .

ether.staticSetup(myip, gwip, dnsip, mask);

Br Robert.

So which subnetmask was the one that worked?

I enteted 255.255.255.255

Ok, that should work also. It just thinks it is in it’s own ‘single IP’ subnet, even though it shares the adress space of your router subnet. Just make sure it’s IP is not inside the DHCP range in your router. Or make a reservation for it.