How to access ethernet shield from multiple devices


hi,

i'm new arduino (more familiar basic stamp) , i'm trying utilize ethernet shield along arduino uno i'm connected to.  i'm trying access access shield multiple computers seem have problem.  can run ethernet shield on computer it's connected when type in ip address on other computer or try ping shield different device not connect.  below simple code turn led on/off through browser.  please me figure out way access led different computer.


/*
  web server
a simple web server
circuit:
* ethernet shield attached pins 10, 11, 12, 13
*/
//-------------------------------------------------------------------------------------------------------
#include <spi.h>
#include <ethernet.h>

// enter mac address , ip address controller below.
byte mac[] = {0x90, 0xa2, 0xda, 0x0f, 0x28, 0x6f };

// ip address dependent on local network:
// assign ip address controller:

ipaddress ip = ipaddress(169,254,234,76);
//ipaddress gateway(10,0,0,4);
//ipaddress subnet(255, 255, 0, 0);

// initialize ethernet server library port want use.
ethernetserver server(80);
string readstring;
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------
// codes declaration :

// declare pin 8 led because thats connecting led to.you use other pin , have change pin number.
int led = 8;

//-------------------------------------------------
//-------------------------------------------------------------------------------------------------------
void setup()
{
//-------------------------------------------------

// set code:
pinmode(led, output); //pin selected control

//-------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//enable serial data print
  serial.begin(9600);

  //start ethernet
  ethernet.begin(mac, ip);
  //ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  serial.print("server @ ");
  serial.println(ethernet.localip());
  serial.println("led controller test 1.0");
}
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------

void loop()
{
  // listen incoming clients
  ethernetclient client = server.available();
  if (client)

  {
    serial.println("new client");

    while (client.connected())
    {
      if (client.available())

      {
        char c = client.read();

        //read char char http request
        if (readstring.length() < 100)

        {

          //store characters string
          readstring += c;
          //serial.print(c);


          serial.write(c);
          // if you've gotten end of line (received newline
          // character) , line blank, http request has ended,
          // can send reply
          //if http request has ended
          if (c == '\n') {
            serial.println(readstring); //print serial monitor debuging
//--------------------------------------------------------------------------------------------------------
// needed display site:
client.println("http/1.1 200 ok"); //send new page
            client.println("content-type: text/html");
            client.println();
            client.println("<html>");
            client.println("<head>");

//--------------------------------------------------------------------------------------------------------
//-------------------------------------------------

// being displayed :     
       
            client.println("<title>michael & erin, mech 208, ethernet shield</title>");
             client.println("<center>");
            client.println("</head>");
            client.println("<body>");
            client.println("<h1>michael & erin, mech 208, ethernet shield</h1>");
            client.println("<hr />");
            client.println("<center>");

            client.println("<a href=\"/?lighton\"\">turn on light</a>");
            client.println("<br />");
            client.println("<br />");
            client.println("<a href=\"/?lightoff\"\">turn off light</a><br />");     

            client.println("</body>");
            client.println("</html>");

            delay(1);
            //stopping client
            client.stop();

            //-------------------------------------------------
            // code needs implemented:
            if(readstring.indexof("?lighton") >0)//checks on
            {
              digitalwrite(8, high);    // set pin 8 high
              serial.println("led on");
            }
            else{
              if(readstring.indexof("?lightoff") >0)//checks off
              {
                digitalwrite(8, low);    // set pin 8 low
                serial.println("led off");
              }
            }
            //clearing string next read
            readstring="";

            // give web browser time receive data
            delay(1);
            // close connection:
            client.stop();
            serial.println("client disonnected");

          }
        }
      }
    }
  }
}

this reason. connected directly computer?
code: [select]
paddress ip = ipaddress(169,254,234,76);
if so, need connect router instead. easier route if connected computer's ethernet port.



Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > How to access ethernet shield from multiple devices


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support