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?
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.
// 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 http://192.168.1.102:84 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);
server.begin();
}
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");
client.println();
//meta-refresh page every 2 seconds
x=x+1; //page upload counter
client.println("<HTML>");
client.print("<HEAD>");
client.print("<meta http-equiv=\"refresh\" content=\"2\">");
client.print("<TITLE />Zoomkat's meta-refresh test</title>");
client.print("</head>");
client.println("<BODY>");
client.print("Zoomkat's meta-refresh test IDE 1.0");
client.println("
");
client.print("page refresh number ");
client.println(x); //current refresh count
client.println("
");
client.println("
");
client.print("Zoomkat's arduino analog input values:");
client.println("
");
client.println("
");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
break;
client.println("</BODY>");
client.println("</HTML>");
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
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.
Hi,
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.
I had a look at ksduino but I am very close to finishing and figured I would just carry on the path I am on.
I got one arduino posting the data to a web address which is great. Does anyone have any examples or suggests of places of where to look for code of an arduino connecting to a web page to collect data? My web page is very very simple - a few lines with a value on each line. My web page is formatted as follows -
Wind speed - 1.57
Wind direction - 55
Wind speed - 1.57
Temperature - 3.06
dewpoint - 3.40
Pressure - 1011.00
Humidity - 94
Days - 18
Months - 12
Years - 2012
Hours - 18
Minutes - 4
I'll finish one new KSduino example and description soon. In this example one Arduino will send data to another one. I'll send link to you when this test will be ready. I can help you to add all your parameters when this test and description will be finished.
Client code that when the arduino receives an e from the serial monitor, the arduino gets a test file from my web server and sends it to the serial monitor. You can try it downloading the page from your web site.
//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
char serverName[] = "web.comporium.net"; // zoomkat's test web page server
EthernetClient client;
//////////////////////
void setup(){
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
Serial.begin(9600);
Serial.println("Better client test 9/22/12"); // so I can keep track of what is loaded
Serial.println("Send an e in serial monitor to test"); // what to do to test
}
void loop(){
// check for serial input
if (Serial.available() > 0) //if something in serial buffer
{
byte inChar; // sets inChar as a byte
inChar = Serial.read(); //gets byte from buffer
if(inChar == 'e') // checks to see byte is an e
{
sendGET(); // call sendGET function below when byte is an e
}
}
}
//////////////////////////
void sendGET() //client function to send/receive GET request data.
{
if (client.connect(serverName, 80)) { //starts client connection, checks for connection
Serial.println("connected");
client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
client.println("Host: web.comporium.net");
client.println(); //end of get request
}
else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read(); //gets byte from ethernet buffer
Serial.print(c); //prints byte to serial monitor
}
Serial.println();
Serial.println("disconnecting.");
Serial.println("==================");
Serial.println();
client.stop(); //stop client
}