Adafruit Feather M0 not connecting to computer/server

Hi all,

I am attempting to send data to a server, which happens to be a computer acting as a server, but am having some issues getting the connection.

I have USB-Mini powering my Feather M0 and connected to that board I have an Adafruit Ethernet FeatherWing. This FeatherWing is connected to my laptop via ethernet.

I've been trying to receive on the computer/server using SocketTest. I am using the Server tab and am using the IP address shown for the ethernet adapter in ipconfig /all. I am trying to listen in on port 21.

I know it's not connecting because the serial monitor repeatedly outputs that is has no connection (via the print statement). I am attempting to send data to the server in the loop function. The loop function is somewhat irrelevant however, and does not form any connections on its own. If someone would like to see it, please let me know!

My code to try to get these two to communicate looks like this (I have intentionally excluded the loop function):

#include <Ethernet.h>
#include <SPI.h>
#include <Adafruit_ZeroI2S.h>
#include "wiring_private.h"

#define SAMPLERATE_HZ 44100

// Setting up hardware and software info for the Ethernet connection
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(169,254,237,218); // Assigned IP Address for board. This is an arbitrary value.
IPAddress server(169,254,237,217); // IP Address of Ethernet Adapter.
EthernetClient client;

// Setting up sampling information for the microphone
int sample_left = 0;
int sample_right = 0;
int sample = 0;
int32_t left,right;
Adafruit_ZeroI2S i2s(0,1,9,11); // Initializing the I2S interface


void setup()
{
 
  // Begin both the Ethernet connection and I2S interface
  Ethernet.begin(mac,ip);
 
  i2s.begin(I2S_32_BIT,SAMPLERATE_HZ);

  // Begin Serial interface, and wait until it's fully set up
  Serial.begin(9600);
  while(!Serial) {
    ;
  }
 
  // Enabling the microcontroller to receive data, and setting Pin 11 as output (for channel select)
  i2s.enableRx();
  pinMode(11, OUTPUT);
 
  Serial.print("Local IP: ");
  Serial.println(Ethernet.localIP());
 
  Serial.println("connecting...");

  // Waiting for the client to the server (Client:Feather::Server:Labview)
  while(!client.connect(server,21)){ // The second argument is the port.
    Serial.println("Waiting for a connection"); // NEVER GETS PAST THIS LINE
  }
 
  Serial.println("connected!");
  client.println("Hello world!");

To clarify:

  • the ip variable has an arbitrary ethernet value
  • the server variable has the IP address displayed for the ethernet adapter in ipconfig /all
  • the MAC Address is right as far as I'm aware... (this code is a hand-me-down, and this is what they had when it was working). I would really appreciate it if someone told me where to find the MAC Address of the board.

My ethernet adapter on the computer looks like this if I run ipconfig /all:

Any ideas are welcome! I am a novice when it comes to networking, although I've been using Arduino for quite some time!

Thanks!

windows firewall

check the firewall inbound rules
wireshark is a useful tool for monitoring network traffic

Thanks for the replies! I moved to another computer that does not have a firewall and I tried out WireShark. Can you help interpret what some of this might mean?

In other words, does it look like it's receiving data? And if so, why is the serial monitor saying that it doesn't have a connection?

what does ipconfig/all on the new computer display - I assume you updated the Arduino code to match the new IP?
port 21 is a default FTP port

  1. are you already using that port, e.g. running FTP
  2. some operating systems reserve ports 0 to 1023 - try port 10000

I assume you are running a TCP server on the PC not UDP - have you any output from the server?

connected up a EthernetSheildV1 (which I had not used for a few years) to a UNO and tried a TCP client connection similar to your code without sucess
in the end I modified the code to connect using DHCP

  1. it works sometimes - usually takes 2 or 3 attampts to connect pressing the Ethernet board reset
  2. even when it connects the DHCP take 30 seconds or so to initialise

Arduino simple chat client code

// TCPcharClient.ino - a simple TCP chat program

#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xD0, 0x93 };
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 1,186);
IPAddress myDns(192, 168, 1,254);   // DNS server

// Initialize the Ethernet client library 
EthernetClient client;

byte server[] = { 192, 168, 1, 68 }; // server IP address
int serverPort=10000;                // server TCP port (open any firewall on server)

void setup() {
  Serial.begin(115200);   // Open serial communications and wait for port to open:
  while (!Serial) ;
  // start the Ethernet connection:
  Serial.println("\n\nInitialize Ethernet with DHCP:");
  if (Ethernet.begin(mac) == 0) {
      Serial.println("Failed to configure Ethernet using DHCP");
      // Check for Ethernet hardware present
      if (Ethernet.hardwareStatus() == EthernetNoHardware) {
        Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
        while (true)   delay(1);    // do nothing, no point running without Ethernet hardware
      }
      if (Ethernet.linkStatus() == LinkOFF)
        Serial.println("Ethernet cable is not connected.");
      // try to congifure using IP address instead of DHCP:
      Ethernet.begin(mac, ip, myDns);
  } else {
    Serial.print("  DHCP assigned IP ");
    Serial.println(Ethernet.localIP());
  }
  delay(1000);
  Serial.println("connecting to server...");
  // Ethernet ready, connect to server and transmit data
  if (!client.connect(server, serverPort)) {
     Serial.println("connection failed");
     while(1);
  }
  Serial.println("connection OK");
}

// chat server open
//   transmit text entered at keyboard to server 
//   display text received from server
void loop()
{
  char ch;
  static  String receivedLine = "", transmitLine="";   
  if (client.available())
    if((ch = client.read()) != '\n')
          receivedLine+=ch;                // add to currentline
    else {
          Serial.println("Received '" + receivedLine + "'");
          receivedLine="";
         }
  if(Serial.available())                // if keyboard test available
    if((ch=Serial.read()) != '\n')      // if not new line
         transmitLine+=ch;  // add to currentline
    else  {                               // on \n transmit line
        Serial.println("transmitting '" + transmitLine + "'");
        client.print(transmitLine + "\n");
        transmitLine="";
       }    
}

Simple Java chat server code

// TCPchatServer.java - simple peer-to-peer chat server program using TCP
//           - will wait for connection from remote TCPchatClient and send/display messages


import java.io.*;
import java.util.*;
import java.net.*;

public class TCPchatServerScanner extends Thread
{
   private final static Scanner in = new Scanner(System.in);
   int port=10000;                             // port to send/receive   on
   String remoteIPaddress= ("127.0.0.1");      // remote IP address
   private ServerSocket   serverSocket;
   Scanner br=null;
   PrintStream pw=null;
   Socket socket=null;

   // constructor, parameter is command line parameters
   public TCPchatServerScanner(String args[]) throws Exception
    {
    // get remote IP address and port from command line parameters
    if (args.length > 0)    remoteIPaddress =  (args[0]);           // get IPaddress
    if (args.length > 1)    port = Integer.parseInt(args[1]);        // get port number
    System.out.println("TCP chat server: IP address " + InetAddress.getLocalHost().toString() + " port " + port );
    
    try
        {
        System.out.println("TCP server starting: IP address " 
                       + InetAddress.getLocalHost().toString() + " port " + port );
        serverSocket = new ServerSocket(port);
        socket = serverSocket.accept();                                 // Wait for client to connect.
        System.out.println("Client connect from IP address " + socket.getInetAddress()
                                  + " port " + socket.getPort());
        br  = new Scanner(socket.getInputStream());
        pw = new PrintStream(socket.getOutputStream());
        start();                // start thread to receive messages
        while(true)        // loop sending messages
           {
            String s = in.nextLine();
            System.out.println("Sending: '" + s + "'");
            pw.println(s);                  // send message  
            }   
        }
      catch (Exception e) {System.err.println("Eror " +  e); Thread.sleep(10000); System.exit(1);  }

    }

   // thread run method, wait for message from remote machine
   public void run()                
    {
     System.out.println("thread to receive");
     while(true)                // loop receiving messages
        try
           {
            String code = (String) br.nextLine();
             // changed to receive single characters
           // char code =  br.findWithinHorizon(".",0).charAt(0);
            System.out.println( "Server received: '" + code + "'");
           }
        catch (Exception se) {System.err.println("Error " + se); System.exit(1); }
  }

public static void main(String args[]) throws Exception
{
   TCPchatServerScanner c=new TCPchatServerScanner(args);
   Thread.sleep(10000); 
}

}

a run displays - serial monitor (it took three attempts to connect)



Initialize Ethernet with DHCP:
Failed to configure Ethernet using DHCP
connecting to server...
connection failed


Initialize Ethernet with DHCP:
Failed to configure Ethernet using DHCP
connecting to server...
connection failed


Initialize Ethernet with DHCP:
Failed to configure Ethernet using DHCP
connecting to server...
connection failed


Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.1.115
connecting to server...
connection OK
Received 'test 1
'
Received 'server test 2'
transmitting 'client test 1'
transmitting 'client test 2'

Java displays

I don't remember any problems in the past
it looks like a hardware/software problem with the Arduino Ethernet shield and my new router

a web search for arduino EthernetSheildV1 TCP problems yeilds a number of links

I appreciate the in-depth response! I do seem to be having some trouble replicating what you have done. Here is my code, output, and ipconfig /all if you wanna check it out.

#include <Ethernet.h>
#include <SPI.h>
#include <Adafruit_ZeroI2S.h>
#include "wiring_private.h"

#define SAMPLERATE_HZ 44100 

// Setting up hardware and software info for the Ethernet connection
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(169,254,237,218); // Assigned IP Address for board. 
IPAddress myDns(169,254,237,219);

byte server[] = {169,254,237,217}; // IP Address of Ethernet Adapter. Look in LabVIEW?
int serverPort = 10000;

EthernetClient client;

// Setting up sampling information for the microphone
int sample_left = 0;
int sample_right = 0;
int sample = 0;
int32_t left,right;
Adafruit_ZeroI2S i2s(0,1,9,11); // Initializing the I2S interface


void setup()
{
  
  // Begin both the Ethernet connection and I2S interface

  // Begin Serial interface, and wait until it's fully set up
  Serial.begin(9600);
  while(!Serial) {
    ;
  }

  Serial.println("Beginning...");
  if (Ethernet.begin(mac) == 0) {
      Serial.println("Failed to configure Ethernet using DHCP");
      // Check for Ethernet hardware present
      if (Ethernet.hardwareStatus() == EthernetNoHardware) {
        Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
        while (true)   delay(1);    // do nothing, no point running without Ethernet hardware
      }
      if (Ethernet.linkStatus() == LinkOFF)
        Serial.println("Ethernet cable is not connected.");
      // try to congifure using IP address instead of DHCP:
      Ethernet.begin(mac, ip, myDns);
  } else {
    Serial.print(" DHCP assigned IP ");
    Serial.println(Ethernet.localIP());
   }

  delay(1000);
  Serial.println("connecting to server . . . ");
  if (!client.connect(server, serverPort)) {
    Serial.println("connection failed");
    while(1);
  }
  Serial.println("connection ok!");
  
  // Enabling the microcontroller to receive data, and setting Pin 11 as output (for channel select)
  i2s.enableRx();
  pinMode(11, OUTPUT);
}

void loop()
{     

  // Reading both the left and right channels of data
  i2s.read(&left, &right);
  sample_left = left;  
  sample_right = right;
  
  
  //convert to 18 bit signed
  sample_left >>= 14;
  sample_right >>= 14;

  // We have two channels of data to work with, if one channel is corrupted use the other one
  if(sample_left == -1){
    sample = sample_right;
  }
  else {
    sample = sample_left;
  }

  // Both channels could be corrupted, in which case loop back to the start and try again
  if(sample == -1){
    return;
  }

  // Print the sample we're going to use to both the serial monitor and the client
  Serial.println(sample);
  client.println(sample);  
}

Beginning...
Failed to configure Ethernet using DHCP
connecting to server . . . 
connection failed

The Arduino proceeds to sit at this step.

I really appreciate the help!

set the CS pin with Ethernet.init().
test without any other library and devices. remove SD card if it is inserted

as I mentiond in post #6 I could not remember having problems with the Ethernet shield in the past - I suspected a problem with my new(ish) router
I found an old D-LINK DSL-2740B and connected the Arduino Ethernet sheild with the chat client code from post #6 - all OK - each time I press reset the DHCP responds immediatly with an IP address
in the following run I press reset a couple of times

  1. the DHCP server responds with an IP address
  2. the server connection fails as it is not running

before the third reset I run the Java server

  1. the DHCP server responds with an IP address
  2. the server responds accepting the client connection
  3. text is then exchanged between the client and server
Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.1.11
connecting to server...
connection failed


Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.1.11
connecting to server...
connection failed


Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.1.11
connecting to server...
connection OK
Received 'data from server 11
'
Received '1111
'
Received '22222
'
transmitting 'daata from client'
transmitting 'client2client3'
Received 'bye
'

the Java server display
old_modem_test

fix arduino ethernet shield suggests a hardware fix for the problem

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.