controling two Arduino on the same LAN

hello every one ,

I already connect two Arduino at the same LAN and connect them to each other

but the problem now is how to make one of them send an message and make one of them receive it

i have
Arduino UNO with Ethernet shield (i connected by a wire)
Arduino YUN (i connected by wifi)

but the problem now is how to make one of them send an message and make one of them receive it

Why is that a problem? One acts a server. The other acts as a client. The clients sends a GET request. The server provides a response.

PaulS:

but the problem now is how to make one of them send an message and make one of them receive it

Why is that a problem? One acts a server. The other acts as a client. The clients sends a GET request. The server provides a response.

.... and you could probably base your solution on the WebServer and Webclient sketches in the IDE, with appropriate MACs and IPs, and the right GET and response.

Why is that a problem? One acts a server. The other acts as a client. The clients sends a GET request. The server provides a response

that what i did
the UNO is the server

the YUN is the client

the YUN send GET request to UNO
the UNO send GET request to YUN

that how i connect them

i have 4 led
this 4 led attached to UNO

i want to control these LED from the YUN by 4 push buttons

Have the code at the client add a ?LEDxON or similar to the GET which you send to the server. Then the server checks for that text in the arriving GET and if it finds LED1ON or LED2ON or whatever, acts accordingly.

that what i did
the UNO is the server

Serving porridge? Where is your code?

the YUN is the client

Making what kind of request? Getting what kind of response? Where is your code?

This is NOT the "Do my homework for me hotline". You need to post your code.

this the code for UNO

// FILENAME = LED2.ino
// SOURCE= http://www.instructables.com/id/Control-an-LED-over-the-internet-using-the-Arduino/
// Control an LED over the internet using the Arduino Ethernet Shield and Transistor
// http://www.instructables.com/id/Control-an-LED-over-the-internet-using-the-Arduino/
// code SOURCE= http://pastebin.com/CZ6J62qJ
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
#include <HttpClient.h>

// initialize the library with the numbers of the interface pins




Servo myservo; // create servo object to control a servo
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 177 }; // fixed IP addr in LAN
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
//////////////////////
void setup(){
pinMode(6, OUTPUT); //pin selected to control LED
pinMode(7, OUTPUT); //pin selected to control LED
pinMode(8, OUTPUT); //pin selected to control LED
pinMode(9, OUTPUT); //pin selected to control LED

//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
//the pin for the servo co
//enable serial data print
Serial.begin(9600);
Serial.println("server LED test 1.0 ---- FILENAME = LED2.ino "); // so I can keep track
while (!Serial); // wait for a serial connection
}
void loop(){
  
    HttpClient client;
   client.get("http://192.168.1.4"); 
    if (client.available()){ 
  Serial.println("Avilable");
     Serial.println();
     
     
  
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Local network EX</TITLE>");
client.println("</HEAD>");
client.println("<BODY bgcolor='#FFFDD8'>");
client.println("<H1>Local network ex</H1>");
client.println("
");
client.println("TEST number 2");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();

  } 
  else {
        Serial.println("connection failed");
    Serial.println();

///////////////////// control arduino pin

if(readString.indexOf("?lightR") >0)//checks for on
{

digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(6, HIGH);


Serial.println("LED RED");
}


  
if(readString.indexOf("?lightG") >0)//checks for off
{

digitalWrite(6, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);  
digitalWrite(7, HIGH);


Serial.println("LED GREEN");
}



if(readString.indexOf("?lightY") >0)//checks for off
{

digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);

Serial.println("LED YELLOW");
}

 

if(readString.indexOf("?lightO") >0)//checks for off
{

digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);

Serial.println("LED ORANGE");
}


if(readString.indexOf("?A") >0)//checks for off
{
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
Serial.println("LED closed");
}
}
}
}
readString=""; //clearing string for next read
}
}
 delay(1000);
}

this the code for YUN

/*
  Yun HTTP Client

 This example for the Arduino Yún shows how create a basic
 HTTP client that connects to the internet and downloads
 content. In this case, you'll connect to the Arduino
 website and download a version of the logo as ASCII text.

 created by Tom igoe
 May 2013

 This example code is in the public domain.

 http://arduino.cc/en/Tutorial/HttpClient

 */

#include <Bridge.h>
#include <HttpClient.h>

void setup() {
  // Bridge takes about two seconds to start up
  // it can be helpful to use the on-board LED
  // as an indicator for when it has initialized
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);

  Serial.begin(9600);

  while (!Serial); // wait for a serial connection
}

void loop() {
  // Initialize the client library
  HttpClient client;

  // Make a HTTP request:
  client.get("http://192.168.1.177");
  
  if (client.available()){ 
  Serial.println("Avilable");
     Serial.println();
  } 
  else {
        Serial.println("connection failed");
    Serial.println();
  }
  // if there are incoming bytes available
  // from the server, read them and print them:

  delay(5000);
}

So what's the question? How to send the GET from the client?

Looks like you have the server side taken care of.

I've not used that http library but it looks as if the client.get sends a literal as part of a GET. So I'm surmising you could send a literal that contains the parts you're looking for in the server.

Along the lines of (and this is a wild guess)...

if (button1 == HIGH) {
client.get("lightG");
}

Disclaimer: wild guess

Why are you trying to use both an HttpClient and an EthernetClient on the same Arduino? Why is the HttpClient making a GET request?

Why is your code so poorly indented? Use the Tools + Auto Format function!

client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Local network EX</TITLE>");
client.println("</HEAD>");
client.println("<BODY bgcolor='#FFFDD8'>");
client.println("<H1>Local network ex</H1>");
client.println("
");
client.println("TEST number 2");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");

What is a client that connects to this server supposed to do with this? There is nothing here that tells a client what to do.

if(readString.indexOf("?lightR") >0)//checks for on

What is there that suggests that it is reasonable for the client to add this bit to the GET request?

Is the server supposed to be driving the client? Or is the client supposed to be driving the server?

What serial output are you seeing?

Along the lines of (and this is a wild guess)...

I think it would be more like:

                                    client.get("http://192.168.1.177?lightG");

to keep up the poor indenting, etc. And, of course, it looks like HttpClient::get() needs a complete URL.

Why is your code so poorly indented? Use the Tools + Auto Format function!

sorry for that , thats because im still work on it

What is a client that connects to this server supposed to do with this? There is nothing here that tells a client what to do.

well i need it to controlling the LEDs from my computer (i will work on it later )

s the server supposed to be driving the client? Or is the client supposed to be driving the server?

the client driving the server

client.get("http://192.168.1.177?lightG");

I try it but i need to send this code to time to activate the LED why ?

well i need it to controlling the LEDs from my computer (i will work on it later )

Your computer is neither the server nor the client. So, what role is is supposed to play?

I try it but i need to send this code to time to activate the LED why ?

Because that's what the server expects.

I try it but i need to send this code to time to activate the LED why ?

Sorry I mean two times

I should send the code two time to activate the led

Also when I use if function to send the code to the server nothing are happened

I should send the code two time to activate the led

Why? You should not need to, and you most certainly do not want to set up a situation where that is necessary.

Also when I use if function to send the code to the server nothing are happened

So, you've made code changes (or should have), and you'd like us to guess what you changed, and what serial output you are seeing, having added Serial.print() statements to debug the code. You did add them, right?

I try it but i need to send this code to time to activate the LED why ?

No idea..... although maybe it's becasue I think this:

client.get("http://192.168.1.177?lightG");

is missing a / before the ?

client.get("http://192.168.1.177/?lightG");

So, you've made code changes (or should have), and you'd like us to guess what you changed, and what serial output you are seeing, having added Serial.print() statements to debug the code. You did add them, right?

i attached the push button to pin 7 on the client

i attached 4 led to pin 6 , 7 , 8 and 9 on the server

the codes

the server

// FILENAME = LED2.ino
// SOURCE= http://www.instructables.com/id/Control-an-LED-over-the-internet-using-the-Arduino/
// Control an LED over the internet using the Arduino Ethernet Shield and Transistor
// http://www.instructables.com/id/Control-an-LED-over-the-internet-using-the-Arduino/
// code SOURCE= http://pastebin.com/CZ6J62qJ
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>


// initialize the library with the numbers of the interface pins




Servo myservo; // create servo object to control a servo
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 177 }; // fixed IP addr in LAN
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
//////////////////////
void setup(){
pinMode(6, OUTPUT); //pin selected to control LED
pinMode(7, OUTPUT); //pin selected to control LED
pinMode(8, OUTPUT); //pin selected to control LED
pinMode(9, OUTPUT); //pin selected to control LED

//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
//the pin for the servo co
//enable serial data print
Serial.begin(9600);
Serial.println("server LED test 1.0 ---- FILENAME = LED2.ino "); // so I can keep track

}
void loop(){

  
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Local network EX</TITLE>");
client.println("</HEAD>");
client.println("<BODY bgcolor='#FFFDD8'>");
client.println("<H1>Local network ex</H1>");
client.println("
");
client.println("TEST number 2");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();

///////////////////// control arduino pin

if(readString.indexOf("?lightR") >0)//checks for on
{

digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(6, HIGH);


Serial.println("LED RED");
}


  
if(readString.indexOf("?lightG") >0)//checks for off
{

digitalWrite(6, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);  
digitalWrite(7, HIGH);


Serial.println("LED GREEN");
}



if(readString.indexOf("?lightY") >0)//checks for off
{

digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);

Serial.println("LED YELLOW");
}

 

if(readString.indexOf("?lightO") >0)//checks for off
{

digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);

Serial.println("LED ORANGE");
}


if(readString.indexOf("?A") >0)//checks for off
{
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
Serial.println("LED closed");
}
}
}
}
readString=""; //clearing string for next read
}
}

client

/*
  Yun HTTP Client

 This example for the Arduino Yún shows how create a basic
 HTTP client that connects to the internet and downloads
 content. In this case, you'll connect to the Arduino
 website and download a version of the logo as ASCII text.

 created by Tom igoe
 May 2013

 This example code is in the public domain.

 http://arduino.cc/en/Tutorial/HttpClient

 */

#include <Bridge.h>
#include <HttpClient.h>

const int buttonPin = 7;     // the number of the pushbutton pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
   pinMode(buttonPin, INPUT);
  
  // Bridge takes about two seconds to start up
  // it can be helpful to use the on-board LED
  // as an indicator for when it has initialized
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);

  Serial.begin(9600);

  while (!Serial); // wait for a serial connection
}

void loop() {
    HttpClient client;
  // Initialize the client library
  if (buttonState == HIGH) {
      Serial.println("work");
     Serial.println();


  // Make a HTTP request:
  client.get("http://192.168.1.177?lightO");


  if (client.available()){ 
  Serial.println("Avilable");
     Serial.println();
  } 
  else {
        Serial.println("connection failed");
    Serial.println();
  }
  // if there are incoming bytes available
  // from the server, read them and print them:

  delay(500);
}
}
Serial.println(readString); //print to serial monitor for debuging

But, you have no intention of telling us what you see. Well, good luck.

Servo myservo; // create servo object to control a servo

Why?

Code:
Serial.println(readString); //print to serial monitor for debuging
But, you have no intention of telling us what you see. Well, good luck.

GET /?lightO HTTP/1.1

The LED activated only when i open serial monitor