I'm trying to connect my Arduino to the internet, but my Ethernet connection config code fails when I try to verify it, and I'm not sure why.
I'm using an Ethernet shield and have installed the Ethernet library v.2.0.0.
This is the running code:
WANStatus initialiseWAN() {
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
WANStatus res;
Serial.println("[INFO]: Initialising WAN");
// Try to initialise Ethernet connecion
if (Ethernet.begin(mac) == 0) {
res.error = true;
res.retry = true;
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
res.message = "Ethernet shield was not found";
Serial.print("[ERROR]: "); Serial.println(res.message);
return res;
}
// If all component are present try assigning a static IP address
IPAddress ip(192, 168, 0, 177);
IPAddress myDns(192, 168, 0, 1);
Ethernet.begin(mac, ip, myDns)
Serial.print("[INFO]: Assigned static IP: "); Serial.println(Ethernet.localIP());
if (Ethernet.linkStatus() == LinkOFF) {
res.message = "Ethernet cable is not connected";
Serial.print("[ERROR]: "); Serial.println(res.message);
return res;
}
if (Ethernet.linkStatus() == Unknown) {
res.message = "Ethernet link status is 'Unknown' check the cable";
Serial.print("[ERROR]: "); Serial.println(res.message);
return res;
}
// Static IP assigned
res.error = false;
res.retry = false;
res.message = "Static IP Address";
return res;
} else {
// Received IP address from DHCP
Serial.print("[INFO]: Received DHCP IP: "); Serial.println(Ethernet.localIP());
res.error = false;
res.retry = false;
res.message = "DHCP IP Address";
return res;
}
// ToDo: check WiFi modules here
}
And the error message:
[Starting] Verifying sketch 'controller\controller.ino'
[Warning] Output path is not specified. Unable to reuse previously compiled files. Build will be slower. See README.
Loading configuration...
Initialising packages...
Preparing boards...
Verifying...
In file included from C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Dns.cpp:8:0:
C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Dns.cpp: In member function 'uint16_t DNSClient::BuildRequest(const char*)':
C:\Program Files (x86)\Arduino\libraries\Ethernet\src\utility/w5100.h:457:25: warning: result of '(256 << 8)' requires 18 bits to represent, but 'int' only has 16 bits [-Wshift-overflow=]
#define htons(x) ( (((x)<<8)&0xFF00) | (((x)>>8)&0xFF) )
~~~^~~
C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Dns.cpp:164:18: note: in expansion of macro 'htons'
twoByteBuffer = htons(QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG);
^~~~~
Sketch uses 22574 bytes (69%) of program storage space. Maximum is 32256 bytes.
Global variables use 1467 bytes (71%) of dynamic memory, leaving 581 bytes for local variables. Maximum is 2048 bytes.
IntelliSense configuration already up to date. To manually rebuild your IntelliSense configuration run "Ctrl+Alt+I"
[Done] Verifying sketch 'controller\controller.ino'