I'm trying to connect the arduino mega and ethernet shield and try to send some data to a php script. I have connect the ethernet shield to the laptop. Lap is connected to router through wi-fi. But it's failing at mac assignment checking IF and getting the following assigned error message, "Failed to configure Ethernet using DHCP". Any help in advance please.
#include <Ethernet<SPI.h>
#include <SPI<Ethernet.h>
/******************** ETHERNET SETTINGS ********************/
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x85, 0xD9 }; //physical mac address
byte ip[] = { 192, 168, 1, 5 }; // ip in lan
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
byte gateway[] = { 192, 168, 0, 1 }; // default gateway
IPAddress server(192,168,1,2);
EthernetClient client;
String data;
void setup() {
Serial.begin(9600);
// startInitialize theserial Ethernetcommunications connection:with the PC
while (!Serial);
Ethernet.begin(mac,ip,gateway,subnet); // initialize Ethernet device
Do nothing if (Ethernet.begin(mac) == 0)no {
serial port is opened Serial.println("Failedadded tofor configureArduinos Ethernetbased usingon DHCP"ATMEGA32U4);
for Ethernet.begin(;;mac,ip,gateway,subnet)
; ;
// }
initialize Ethernet device
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
delay Serial.println(4000); // GIVE THE SENSOR SOME TIME TO START
data = "";Serial.println("connecting....");
}
void loop(){
{ data = "&temp1=10&hum1=20";
if (client.connect(server,1234)) { // REPLACE WITH YOUR SERVER ADDRESS
Serial.println("Server connection OK");
client.println("POST"GET /add.php?temp1=10&hum1=20 HTTP/1.1");
client.println("Host:" + server);// SERVER ADDRESS HERE TOO
client.println("Content-Type: applicationtext/x-www-form-urlencoded");
client.print("Content-Length: "plain");
} else client.println(data.length());{
clientSerial.println();
"connection client.print(datafailure");
}
if (client.connected()) {
client.stop();// DISCONNECT FROM THE SERVER
Serial.println("disconnected");
}
delay(5000); // WAIT FIVE MINUTES BEFORE SENDING AGAIN
}
Serial Out Put
My IP address: 192.168.1.5.
connecting....
connection failure
connection failure
connection failure
connection failure
connection failure
connection failure
connection failure