Go Down

Topic: Sending data with Ethernet (Read 817 times) previous topic - next topic


Hi there

I was hoping some could offer some suggestions/thoughts.

I have an Arduino + ethernet shield in my house which gathers data from some weather sensors.  I want to send this data to a LCD at another house.  My plan is to have another Arduino with an Ethernet shield with the LCD connected to this display at the other house.

I had a look at the examples for Ethernet but I don't know what the best way would be.  Should I host the data on a web page and have the other fetch the data some how or use a chat server setup.

Does anyone have any experience of the easiest way of doing this or other suggestions or sample code?




It seems that UDP is best for this, but I don't understand it myself yet.


You could have one arduino/ethernet shield setup as a server to supply the data and another arduino/shield setup as a client to retreive the data from the server and display the data. The below server test code supplies analog pin data to a client web browser.

Code: [Select]

// zoomkat meta refresh server test code
// arduino IDE 1.0
// for W5100 ethernet shield
// the IP address will be dependent on your local network/router
// port 80 is default for HTTP, but can be changed as needed
// use IP address like in your brouser
// or http://zoomkat.no-ip.com:84 with dynamic IP service
// use the \ slash to escape the " in the html
// meta refresh set for 2 seconds

#include <SPI.h>
#include <Ethernet.h>

int x=0; //set refresh counter to 0
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,102); // ip in lan
EthernetServer server(84); //server is using port 84

void setup()
  // start the server
  Ethernet.begin(mac, ip);

void loop()
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
     while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // see if HTTP request has ended with blank line
        if (c == '\n') {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          //meta-refresh page every 2 seconds
          x=x+1; //page upload counter
          client.print("<meta http-equiv=\"refresh\" content=\"2\">");
          client.print("<TITLE />Zoomkat's meta-refresh test</title>");
          client.print("Zoomkat's meta-refresh test IDE 1.0");
          client.println("<br />");
          client.print("page refresh number ");
          client.println(x); //current refresh count
          client.println("<br />");
          client.println("<br />");
          client.print("Zoomkat's arduino analog input values:");
          client.println("<br />");
          client.println("<br />");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(" is ");
            client.println("<br />");
    // give the web browser time to receive the data
    // close the connection:

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)


Does anyone have any experience of the easiest way of doing this or other suggestions or sample code?

The easiest way to do this depends on your knowledge in this field. Using the HTTP protocol has the advantage that you can test your server part with your every day web browser. The chat server example is more like the equivalent serial protocol version, so if you have experience with designing and parsing serial protocols, that's the better way to go.

The UDP version suggest by Krodal doesn't give you much benefit in this context. UDP uses less network resources but the use case you describe produces such a small amount of network traffic that the additional complexity and the fewer tutorials available probably don't pay off.


You can try our new free service KSduino: http://ksduino.org
You can connect two Arduinos with Ethernet Shields to KSduino and send parameters between it.

KSduino uses UDP to transfer packets so it will be fast. (see: http://blog.ksduino.org/post/37944359140/how-ksduino-works)

Best regards,
Kirill Scherba.

Go Up