Hi,
This should be very simple but as I am new to arduino programming, I am having a bit of a problem connecting to ethernet.
I have W5500 ethernet shield for Arduino Uno R3 controller. My project involes tranmitting the temperature data over the internet. The first step I took as to connect to ethernet was to get the correct IP address using the inbuilt example in arduino IDE. Then I used the same IP address in the code mentioned below. However, when I print the IP address using Serial.println(Ethernet.localIP());, the output is 0.0.0.0
It would great if you can give any insight or solution to this!
TIA!
#include <SPI.h>
#include "EthernetV2_0.h"
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
IPAddress ip(10, 2, 28, 10);
EthernetServer server(80);
#define W5200_CS 10
#define SDCARD_CS 4
void setup() {
Serial.begin(9600);
// Open serial communications and wait for port to open:
pinMode(SDCARD_CS,OUTPUT);
digitalWrite(SDCARD_CS,HIGH);//Deselect the SD card
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
delay(10);
Serial.print(client);
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
}
}
}
}
}
TEST1.ino (1.47 KB)