prosper50:
Server Yun:
-Name - "Dragino-Server"
-Set to Master (access point)
-Broadcasting SSID "Test-Wireless" (open access - no security)
-Using default IP address (192.168.240.1)
Client Yun:
-Name - "Dragino-Client"
-Set to "client"
-Paired to "Test-Wireless" access point (open access - no security)
-Using static IP address (192.168.240.5)
That looks reasonable. Have you verified that you can actually connect from one Yun to another? For example, log onto the SSH command line of the client Yun and run [color=blue]ping -c 5 192.168.240.1[/color]
- do you get valid replies?
If this isn't working, don't even try to run the sketch - you must have a working network first.
Several warnings came up at compile time indicating that YunServer.h, YunClient.h, etc. were deprecated and to use BridgeServer.h, BridgeClient.h, etc..... so I made those changes. THAT IS ALL.
That sounds like Dragino's own enhancement? I have no familiarity with that, I've only used the actual Arduino Yun boards, not the Dragino Yun shields. I hear that there are some subtle differences.
but does not drop down into the if(client) loop. That means there is no connection being made between the client and server.
To help debug between the two sides, you can try making a Telnet connection to the server Yun. If it responds, you know the server is working and the client is not. If it doesn't respond, then you know there is a problem with the server side (and can draw no conclusions about the client.) You will need a Telnet client to make a connection 192.168.240.1 port 5555
I was wondering whether this needs to be an AdHoc setup, but it doesn't make sense to me given the "client/server" structure of the original sketch.
No, it should make no difference at all to the sketch. As long as you have network connectivity between the two Yuns, the sketch should work (assuming there isn't a bug in the sketch.) It shouldn't matter whether one is an access point and the other is a client connected to it, or they are two clients connected to a different access point, or they are wired Ethernet connections, or whatever. As long as you can ping from the client to the server, the sketch should work.
You say you've used the code from the other post, and made some changes. Even with minor changes, it's very helpful to post your actual code so there isn't any misunderstanding. Even trivial changes can be made incorrectly and cause subtle errors. When posting your code, always use code tags (in the IDE, select "copy for forum" before pasting your code, or click the </> button in the forum editor tool ribbon and paste between the tags.)
Looking at the code in that other topic, it looks like some details may be missing. Maybe they are not needed, but I've had good luck including them:
When defining the server object, I use:
YunServer server(PORT);
Where PORT was defined as the port number I wanted to use. By not including a port number in the YunServer constructor, you are using the default port number. Perhaps Dragino's library uses a different default port number? Or since you changed to their BridgeServer object, maybe it uses a different default port number?
The other thing I do is before calling .begin on the server, I call .noListenOnLocalHost():
server.noListenOnLocalhost();
server.begin();
I think the default is to listen only for connections from the local Linux server, you need to call .noListenOnLocalHost() to listen for connections from the outside network.
I have worked on similar sample code for client/server communications. For reference, this is the code I use (it's a bit more robust than the sample code you referenced, as it keeps the connection open longer than the time to send one number, and does a bit more careful connection management.
The server code:
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#define PORT 255
YunServer server(PORT);
YunClient client;
void setup()
{
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
Bridge.begin(); // Bridge startup
Serial.begin(115200);
while (!Serial)
{
digitalWrite(13, HIGH);
delay(125);
digitalWrite(13, LOW);
delay(125);
}
Serial.println("Server listening on port 255");
server.noListenOnLocalhost();
server.begin();
client = server.accept();
}
void loop()
{
// There are two interesting flags in the client:
// opened - read by converting the client object to a bool.
// connected - read by calling the connected() method
// This gives four combinations:
// closed and no connection - Try to accept a new connection.
// closed and connected - Not possible.
// open and no connection - Connection just closed, stop the client to clean up.
// open and connected - Ready to go, process the connection
if (client.connected())
{
// There is a valid connection open.
// Read and echo any input to the serial port
if (client.available())
{
Serial.print("From client: \"");
while (client.available())
Serial.print((char)client.read());
Serial.println("\"");
}
// Send something to the client
client.println("Hello Client!");
}
else
{
// The client is not connected. Is it open (previously connected?)
if ((bool)client)
{
// The client is currently open, but is not connected.
// That means that there was a valid connection the last time around the loop.
// There was a connection on the client, but it has just closed.
// It's necessary to stop a closed connection, otherwise resoruces are not freed
// and the server will stop accepting new connections after about 256 sessions.
client.stop();
Serial.println("Client disconnected.");
}
// At this point the client is not connected, and has been gracefully closed.
// Try to accept a new connection.
client = server.accept();
// Is the client now connected? If so, we have a new connection.
if (client.connected())
Serial.print("New client connection: ");
}
}
And the client code:
#include <Bridge.h>
#include <YunClient.h>
#define PORT 255
// Define our client object
YunClient client;
void setup()
{
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
// Bridge startup
Bridge.begin();
digitalWrite(13, LOW);
}
void loop()
{
// Make the client connect to the desired server and port
IPAddress addr(192, 168, 42, 185);
// Or define it using a single unsigned 32 bit value
// IPAddress addr(0xc0a8sab9); // same as 192.168.42.185
// Or define it using a byte array
// const uint8 addrBytes = {192, 168, 42, 185};
// IPAddress addr(addrBytes);
client.connect(addr, PORT);
// Or connect by a server name and port.
// Note that the Yun doesn't support mDNS by default, so "Yun.local" won't work
// client.connect("ServerName.com", PORT);
if (client.connected())
{
digitalWrite(13, HIGH);
// Send something to the client
client.println("Something...");
// Cheap way to give the server time to respond.
// A real application (as opposed to this simple example) will want to be more intelligent about this.
delay (100);
// Read all incoming bytes available from the server and print them
while (client.available())
client.read();
// Close the connection
client.stop();
digitalWrite(13, LOW);
}
else
Serial.println("Could not connect to the server.");
// Give some time before trying again
delay (100);
}