Hello everyone, I can't figure out the seemingly simple situation arduino + ENC28j60 in client mode for parsing the site. I connect everything according to the instructions and a simple sketch from the example does not work for me
#include <Ethernet.h> //library for ethernet functions
#include <SPI.h>
#include <Client.h> //library for client functions
byte mac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte ip[] = { 192,168,1,25}; //The Arduino device IP address
byte subnet[] = { 255,255,255,0};
byte gateway[] = { 192,168,1,1};
IPAddress server { 64, 233, 187, 99 }; // Google
EthernetClient client;
bool connected = false;
void setup(void) {
Serial.begin(9600);
Serial.println("Initializing Ethernet.");
delay(1000);
//Ethernet.begin(mac, ip , gateway , subnet); //tried this, no working
Ethernet.begin(mac);
}
void loop(void) {
if(!connected) {
Serial.println("Not connected");
if (client.connect(server, 80)) {
connected = true;
Serial.println("Connected");
client.println("GET /search?q=arduino HTTP/1.0");
delay(1000);
}
else{
Serial.println("Cannot connect to Server");
}
}
else {
delay(1000);
while (client.connected() && client.available()) {
char c = client.read();
Serial.print(c);
}
Serial.println();
client.stop();
connected = false;
}
}
The first thought is to check if my bundle works at all, I checked it on this sketch:
#include <EtherCard.h>
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
void setup () {
Serial.begin(57600);
Serial.println(F("n[testDHCP]"));
Serial.print("MAC: ");
for (byte i = 0; i < 6; ++i) {
Serial.print(mymac[i], HEX);
if (i < 5)
Serial.print(':');
}
Serial.println();
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println(F("Failed to access Ethernet controller"));
Serial.println(F("Setting up DHCP"));
if (!ether.dhcpSetup())
Serial.println(F("DHCP failed"));
ether.printIp("My IP: ", ether.myip);
ether.printIp("Netmask: ", ether.netmask);
ether.printIp("GW IP: ", ether.gwip);
ether.printIp("DNS IP: ", ether.dnsip);
}
void loop () {}
on it I get the following.
n[testDHCP]
MAC: 74:69:69:2D:30:31
Setting up DHCP
My IP: 192.168.1.25
Netmask: 255.255.255.0
GW IP: 192.168.1.1
DNS IP: 192.168.1.1
I also ran a sketch of a local server - I can connect to arduino, but I can not connect arduino to a server on the global Internet, apparently I do not understand something