I am new with the arduino yun and i have a problem: I want to send data from on Yun to an other (via wifi). Unfortunately it doesn't work.. I would be happy if you could help me My code looks like this:
1st Yun:
#include <YunServer.h>
YunServer server;
void setup() {
Bridge.begin();
server.begin();
}
void loop() {
server.write(analogRead(A0)); // server should write this data to all connected clients
delay(10000);
}
2nd Yun:
include <YunClient.h>
IPAddress server(192,168,0,101); //Because Yun1 has this IP adress
void setup() {
pinMode(13,OUTPUT);
Bridge.begin();
}
void loop() {
YunClient client;
client.connect(server,5555));
if(client.connected()){
if(client.available()>0){
int value = client.read();
if(value> 25){
digitalWrite(13,HIGH);
}
client.stop();
}
}
delay(30);
}
It doesn't work how i want, but i hope you understand what i am trying to do. Is something like that even possible?
Would be great if you can give me some tipps!
Take a look at the TemperatureWebPanel example for the server part of your communication. You need to get a client object (yes, a client object on the server) using the server.accept() method.
Thank you a lot! your hint really helped me i managed it to connect with the server, but an other problem popped up.
How can i write and read data from an client? it just doesn't work with client.write() and client.read()
This is my code:
Client:
You didn't wait for the data to be transmitted. client.available() returns the number of bytes available in the input buffer. Try with a short delay and a while(client.available()) loop afterwards. Note that client.read() returns exactly one byte of data.