4

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:

enter image description here

[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'
dda
1,5951 gold badge12 silver badges17 bronze badges
asked Apr 22, 2022 at 8:20
0

1 Answer 1

1

Everything is alright. There is no compiler error and your sketch is ready to upload.

The compiler warning "result of '(256 << 8)' requires 18 bits to represent, but 'int' only has 16 bits" from the Ethernet library source code is nothing you have to worry about.

answered May 15, 2022 at 17:29
1
  • the warning is fixed in Ethernet 2.0.1 released Jul 6, 2022 Commented Feb 10, 2023 at 6:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.