Question

I made a project with the Arduino and the ethernet-shield. The Arduino is hosting a website which I can open via the browser on my laptop. The Arduino is connected to the router via ethernet. All of this works just fine.

Now I have to present this project at school. To prevent unpleasant surprises I wanted to connect the Arduino directly with the laptop via ethernet. My problem is that I am really not well informed about this topic. Please, if possible, tell me what I should do.

Was it helpful?

Solution

If you take the router out of the loop you will need to:

Assign a manual IP address to the laptop's Ethernet connection say 192.168.0.1

Subnet mask 255.255.255.0

Assign a manual IP address to the Arduino's Ethernet say 192.168.0.2

Subnet mask 255.255.255.0

default Gateway empty

Use a cross-over cable to link the two (a standard patch lead will NOT work)

You should then be able to get your Arduino site up on http://192.168.0.2 from the laptop.

To look smart :) edit your hosts table on the laptop (C:\windows\system32\drivers\etc\hosts for windows) (/etc/hosts for linux) and make an entry:

192.168.0.2 my.arduino

Then you can access it with http://my.arduino

Good luck

OTHER TIPS

You must assign a manual IP address to the laptop and Arduino. Then include Ethernet.h in your sketch and try to make Ethernet connection. Finally you can see your webpage in your laptop by enter Arduino's IP in your browser. Example:

#include <SPI.h> 
#include <Ethernet.h>
/******************** ETHERNET SETTINGS ********************/
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x85, 0xD9 };   //physical mac address
byte ip[] = { 192, 168, 1, 172 };                   // ip in lan
byte subnet[] = { 255, 255, 255, 0 };              //subnet mask
byte gateway[] = { 192, 168, 1, 254 };              // default gateway
EthernetServer server(80);                       //server port
void setup()
{
Ethernet.begin(mac,ip,gateway,subnet);     // initialize Ethernet device
server.begin();                                // start to listen for clients
pinMode(8, INPUT);                            // input pin for switch
}
void loop()
{
EthernetClient client = server.available();    // look for the client
// 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();
/* 
This portion is the webpage which will be
sent to client web browser one can use html , javascript
and another web markup language to make particular layout 
*/
client.println("<!DOCTYPE html>");      //web page is made using html
client.println("<html>");
client.println("<head>");
client.println("<title>Ethernet Tutorial</title>");
client.println("<meta http-equiv=\"refresh\" content=\"1\">");
/*
The above line is used to refresh the page in every 1 second
This will be sent to the browser as the following HTML code:
<meta http-equiv="refresh" content="1">
content = 1 sec i.e assign time for refresh 
*/
client.println("</head>");
client.println("<body>");
client.println("<h1>A Webserver Tutorial </h1>");
client.println("<h2>Observing State Of Switch</h2>");
client.print("<h2>Switch is:  </2>");
if (digitalRead(8))
{
client.println("<h3>ON</h3>");
}
else
{
client.println("<h3>OFF</h3>");
}
client.println("</body>");
client.println("</html>");
delay(1);         // giving time to receive the data
/*
The following line is important because it will stop the client
and look for the new connection in the next iteration i.e
EthernetClient client = server.available();
*/
client.stop();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top