Send informations from Yun to Yun

Hello,

I want my 2 Arduino Yun sending informations each other and I have some problems in programming Wifi !!!!

1 - Yun 1 send temperature to Yun 2
2 - Yun 2 analyse temperature and switch on the buzzer if the temperature is too high.
3 - On Yun 2 you push on a BP, it switch off the buzzer and send info to Yun 1 to switch on a DC motor.

I don't know how to send the information between my 2 Yun.... Please help me!!!

You can use YunClient and YunServer to transfer data between the two Yun.

Start a YunServer on each Yun, and then Yun1 send temperature value to Yun2 through YunClient class and vice versa.

Both Yun need to be in the same local network.

Thank you. I'll try this :wink:

Is it right?

[Yun1]
IPAddress server(192,168,0,102);//Yun2 IP adress
  if(client.connect(server,5555)){
      client.write(temperature);
  }
  client.stop();
  delay(500);

[Yun2]
YunClient client = server.accept();

if(client){
while(client.available()<1);
float temperature = client.read();
Serial.write(temperature);
client.stop();
}

}
[/code]

Yes, it it seems right.

Just one question: in the second Yun, the how do you declare the server variable? IPAddress or YunServer?

YunServer I think. Why?

  #include <YunServer.h>     // inclusion de la librairie pour le serveur
  #include <YunClient.h>     // inclusion de la librairie pour le client
  #include <LiquidCrystal.h> // inclusion de la librairie pour afficheur LCD
 
//WIFI
  YunServer server;// instancie un serveur permettant à la Yun d'écouter les clients connectés
  YunClient client;// instancie un client permettant à la Yun de répondre au server



void setup() {

  server.begin();             // demarre le serveur
  
} // fin du void setup



void loop() {     
  YunClient client = server.accept();          // créer une instance nommée YunClient pour obtenir des 
                                               //clients venant du serveur.
  if(client){
    while(client.available()<1);
    float Temperature = client.read();         // lecture des bytes
    Serial.write(Temperature);                 // ecriture de la temperature 
                                                         /*->(voir à mettre Serial.print(Temperature);*/
    client.stop();  

    
    Affichage();                               // appel de la fonction affichage

    if (Temperature >= seuilTempHaute){        // si la température dépasse le seuil
        int etatledPin = digitalRead (ledPin); // lecture de l'état de la LED
        if (etatledPin==LOW){                   // si la LED est éteinte
          Sirene();                                  // appel la fonction Sirene()
          }
          else {           
           noTone(buzzerPin);         
          }       
     }
    } 
  
IPAddress server(192,168,0,101);          // adresse IP de la YUN1
  int etatledPin = digitalRead (ledPin);  // lecture de l'état de la LED  
  if(client.connect(server,5555)){        // si on est connecté au serveur
      client.write(etatledPin);           // envoi la valeur de la LED
                                                /*->(voir à mettre client.print(etatledPin);*/
  }
  client.stop();
  delay(500);     

}//fin du loop

Just to be sure, because in the code of Yun 1 you declared server as IPAddress

Did you have any issues sending the data as an integer instead of bytes or char?
I see u put an integer directly in the write function

IPAddress server(192,168,0,101); // adresse IP de la YUN1
int etatledPin = digitalRead (ledPin); // lecture de l'état de la LED
if(client.connect(server,5555)){ // si on est connecté au serveur
client.write(etatledPin); // envoi la valeur de la LED <<<------- HERE
/->(voir à mettre client.print(etatledPin);/