Can someone suggest working Yun hardware configuration please?

Hello everyone.

I have been trying for several weeks to get one specific sketch working on my Uno + Dragino Yun. No matter what I do I cannot get it to work.

The sketch set I am trying to use is found at the following forum post, and is the basis for countless similar sketches I have seen in my explorations on this problem. Therefore it is clear that this is a workable sketch, but I cannot get it working:

http://forum.arduino.cc/index.php?PHPSESSID=sh8oc448lt4tffivf0ooiqp5u7&topic=236467.0

My setup is as follows: Two Arduino Uno's, and two Dragino Yun's.

The way the sketch is setup is that one Uno/Yun set works as a client, and one set works as the server. The client sends a numeric value to the server, and the server displays it on the Console Monitor. The code is incredibly minimal and seems very straightforward. The problem is there is no discussion ANYWHERE regarding how to setup the dozens of settings on the Yun hardware.

Based on assumptions made from various forum posts, the way I have it setup now is as follows:

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)

Inside the "client" sketch I have set the server IP address as appropriate (192,168,240,1).

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.

Everything compiled fine after that, uploaded wirelessly, etc. No problems.
Only thing is that nothing happens.

I put a variety of "console.println("test");" statements at various points in the server sketch as a test of what is happening within the sketch. What I have determined is that the sketch works through the setup block with no problem, enters the loop block with no problem, but does not drop down into the if(client) loop. That means there is no connection being made between the client and server.

I am completely lost as to what the problem is here, or what I need to do to fix it. 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.

PLEASE HELP - I have an entire system that is based on this one simple requirement - sending a number wirelessly from one Yun to the other. THANK YOU!!

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);
}

Hello ShapeShifter.

Thank you very much for the thoughtful and thorough reply to my inquiry.

In the next 2 hours I will find a minute to SSH into the "client" Yun to try a ping test directly into the "server" Yun.

I had previously joined a Windows laptop to the "Server" access point and was able to ping both devices successfully from the laptop, but I have not tried from within either device.

Just to preemptively ask a question... if I can NOT successfully ping one from the other (regardless of which one), what do I do at that point? What does that indicate hardware-wise (besides that there is a connectivity fault)? They are both paired to the "Server" access point as I am able to transfer sketches wirelessly to both, so at face value it appears to work, but I will have to explore it on port 5555.

I am nearly useless with Linux - I have very little experience with it, so I find the prospect of having to perform low-level network troubleshooting through a command line daunting. I would appreciate any information you can provide.

I will report back the results of my ping tests, and I will also post my code as well, albeit largely unmodified from what you see in the linked post.

Thank you again!

Hi ShapeShifter....

OK, so as anticipated, I was able to SSH into each device, and I CAN successfully ping the server from the client machine, and I CAN successfully ping the client from the server machine.

From the client machine, using the built-in telnet application, I attempted to connect to the server using the command

telnet 192.168.240.1 [5555]

, but the response was

telnet: can't connect to remote host (192.168.240.1): Connection refused

. So it seems like the client cannot connect to the server on the server's listening port of 5555.

Regarding the code I am using, it is basically a carbon copy of the original, with the minor modifications I mentioned for the deprecated Yun libraries:

CLIENT CODE:

#include <BridgeClient.h>
#include <Console.h>
IPAddress server(192,168,240,1);
void setup(){
  pinMode(13,OUTPUT);
  Bridge.begin();
  Serial.begin(9600);
  Console.begin();
  Console.println("In Setup");
}

void loop() {
  Console.println("In Loop");
  BridgeClient client;
  if(client.connect(server,5555)){
    client.write(42);
    Serial.println("42 sent");
    Console.println("42 sent");
  }
  client.stop();
  delay(500);
}

SERVER CODE:

#include <BridgeServer.h>
#include <BridgeClient.h>
#include <Console.h>

BridgeServer server;

void setup(){
  Serial.begin(9600);
  Bridge.begin();
  server.begin();
  Console.begin(); 
  Console.println("In Setup");
}

void loop() {
  Console.println("In Loop");
  BridgeClient client = server.accept();
  if(client){
    Console.println("In IF Loop");
    while(client.available()<1);
    Serial.println(client.read());
    Console.println(client.read());
    client.stop();
  }
}

Thank you again for any insight you can provide.

Just as an FYI, I did previously go into the web-based setup for both Yun units, into the firewall configuration, and I made sure ALL TRAFFIC was allowed, whether forwarded traffic, location traffic, etc. Since port 5555 is the default listening port for both the Arduino Yun as well as the Dragino Yun, I wouldn't assume that anything special would have to be done to ensure functionality.

-Dave

ALSO, I just ran a Netstat on both machines to see what ports are open, assuming maybe 5555 is not valid for some reason, and I get the following output.

5555 DOES seem to be a valid port, but it seems that there is no IP address assigned to the machine (or at least any of the ports).... the IP address comes up as 0.0.0.0. I'm at a loss.

acBusyBox v1.19.4 (2015-01-06 10:25:28 CST) multi-call binary.

Usage: netstat [-ral] [-tuwx] [-enWp]

Display networking information

        -r      Routing table
        -a      All sockets
        -l      Listening sockets
                Else: connected sockets
        -t      TCP sockets
        -u      UDP sockets
        -w      Raw sockets
        -x      Unix sockets
                Else: all socket types
        -e      Other/more information
        -n      Don't resolve names
        -W      Wide display
        -p      Show PID/program name for sockets

root@dragino-server:~# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:5700          0.0.0.0:*               LISTEN
tcp        0      0 localhost:6571          0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:www             0.0.0.0:*               LISTEN
tcp        1      0 0.0.0.0:5555            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:domain          0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:https           0.0.0.0:*               LISTEN
netstat: /proc/net/tcp6: No such file or directory
udp        0      0 0.0.0.0:domain          0.0.0.0:*
udp        0      0 0.0.0.0:bootps          0.0.0.0:*
udp        0      0 0.0.0.0:mdns            0.0.0.0:*
netstat: /proc/net/udp6: No such file or directory
netstat: /proc/net/raw6: No such file or directory
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node Path
unix  2      [ ACC ]     STREAM     LISTENING       1046 /var/run/ubus.sock
unix  2      [ ACC ]     STREAM     LISTENING       2366 /var/run/avahi-daemon/s                                                                                        ocket
unix  2      [ ACC ]     STREAM     LISTENING       2159 /var/run/dbus/system_bu                                                                                        s_socket

prosper50:
I am nearly useless with Linux - I have very little experience with it, so I find the prospect of having to perform low-level network troubleshooting through a command line daunting. I would appreciate any information you can provide.

I'm not totally lost with the Linux CLI, but I also find debugging a network using the command line to be daunting. I have no advice to offer, perhaps someone else will be along with some Linux networking advice (Jesse?)

But ping test shows the network is working, and the Telnet test shows that the server sketch is not working properly. I don't think the issue is with Linux.

Thanks for posting the code. My suggestion is still the two code snippets in my first post:

  • Specify an explicit port number in the server constructor
  • Call server.noListenOnLocalHost() before calling server.begin()

Personally, I don't like relying on default values. I like to specify the port explicitly because it's such an important parameter, and it's easy for arbitrary default values like that to change and that ends up breaking the system. It can't hurt to set the port number explicitly, it can only help.

But my biggest suspicion is the need for .noListenOnLocalHost() - by default, the sketch is listening for incoming connections on port 5555, but it's listening for connections coming from the Linux processor, and by default Linux is not listening for incoming connections on port 5555. (It's listening for HTTP requests on port 80, and if it finds a request which has a URL starting with the /arduino/ token, it forwards it to the YunServer running in the sketch.) By calling .noListenOnLocalHost(), you are essentially telling Linux that you don't want it to do that HTTP redirection, instead you want to receive incoming connections from the network on that port: therefore, it should listen for such connections and forward them to the sketch. In this case, the Linux side is a simple pass-through, allowing external connections to reach the sketch.

Before you worry more about the Linux networking configuration, add that .noListenOnLocalHost() call - there is a very good chance that will fix it.

ShapeShifter, thanks for the insight.

I changed my server code to the following, but still no go.

Tomorrow I think I will change the libraries back to YunServer and YunClient, even though I get errors, and I'll see if that gets me anywhere.

I will report back.

#include <BridgeServer.h>
#include <BridgeClient.h>
#include <Console.h>

BridgeServer server;

void setup(){
  Serial.begin(9600);
  Bridge.begin();
  server.noListenOnLocalhost();
  server.begin();
  Console.begin();  
}

void loop() {
  BridgeClient client = server.accept();
  if(client){
    while(client.available()<1);
    Serial.println(client.read());
    Console.println(client.read());
    client.stop();
  }
}