TCP/IP communication struggles

I'm using the Ethernet Shield 2 in a project along with the Uno. I am trying to read in strings from a software called Epson RC+, a software meant for programming Epson robots. I've tried several configurations but the Arduino will not connect to the port the controller is opening. I've been able to write to other programs, however, such as tcping and PuTTY, but after trying to emulate the same configurations in the IDE it still doesn't work.

I've set the Epson controller as the server, the configurations are as follows:
IP address: 127.0.0.1
IP mask: 2555.255.255.0
IP gateway: 127.0.0.2

It has opened port 2000 and is writing to an IP address of 127.0.0.1 (as I understand it, when opening ports as a server, you want to write to your own IP. This has worked when writing to other software).

Here is my Arduino code, sorry if it seems sloppy, I have code for other hardware commented out:

#include "Adafruit_FONA.h" // Cloud connectivity
#define SIMCOM_7000
#include <Ethernet.h> // Robot connectivity
#include <SPI.h>

char URL[150]; // buffer for dweet URL
char imei[16] = {0}; //IMEI number of shield
Adafruit_FONA_LTE fona = Adafruit_FONA_LTE(); // basically our LTE variable
#define FONA_PWRKEY 6
//unsigned int imeiLen = fona.getIMEI(imei); // get imei number
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(127, 0, 0, 2);
byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0x6E, 0x7C }; // physical address of shield, this should be on the sticker on the back of the shield
IPAddress ip(127, 0, 0, 200); // IP address of shield, only different from robot at 4th argument
IPAddress epsonIP(127, 0, 0, 1);// IP address of robot
EthernetClient client;



void setup()
{
  
  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.begin(9600);
  Serial.println("connecting...");
  delay(500);
  if (client.connect(epsonIP, 2000)){
    Serial.println("connected to robot");
  } else {
    Serial.println("failed");
  }
  
//  // startup LTE shield
//  fona.powerOn(FONA_PWRKEY); // power on
//  fona.setFunctionality(1); // this needs to be set to 1
//  fona.setNetworkSettings(F("teal")); // our handy dandy SIM card
//  fona.setPreferredLTEMode(1); // Use LTE CAT-M only, not NB-IoT
}

void loop()
  {

  // if an incoming client connects, there will be bytes available to read:
  if (client.connected() == true) {
    Serial.println(client.read());
  } 

//  if (client.available()) {
//    String line = client.readString();
//    
//    #ifdef SIMCOM_7000
//      Serial.println("sending data to dweet...");
//      sprintf(URL, "dweet.io/dweet/for/%s?temp=%s&batt=%s", imei, line);
//
//      if (!fona.postData("GET", URL))
//              Serial.println(F("Failed to complete HTTP GET..."));
//              
//    #endif
//  }
//
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}

When I open the serial monitor, the output is always:

connecting...
failed

disconnecting.

This has been stumping me for a while, would appreciate any help. Thanks in advance.

I am not sure what you are asking but this should help. You can perform a simple PING test, depending on what operating system. In Linux, open the terminal, enter ping 127.0.0.1 If the address is active it should respond, if not your arduino does not have a chance. In windows I use DOS and the ping command.

iirc 127.0.0.x is the loopback address on a machine, try it with a more normal address one of the 192.168.x.x ones and see if that makes any difference.

If the Epsom server software isn't literally running on the same Arduino as your sketch is running, then the loopback address won't work.

The sections in this chapter describe common features of TCP/IP and provide best information and guide to some of the most common TCP/IP problems. The following items will be covered:

spectrumbilus:
The sections in this chapter describe common features of TCP/IP and provide best information and guide to some of the most common TCP/IP problems. The following items will be covered:

Did you intend to put a link in your posting?

gilshultz:
I am not sure what you are asking but this should help. You can perform a simple PING test, depending on what operating system. In Linux, open the terminal, enter ping 127.0.0.1 If the address is active it should respond, if not your arduino does not have a chance. In windows I use DOS and the ping command.

Thanks for the reply. Unsure of how to respond individually to replies (maybe it's not a feature?) so hopefully you get notifications when I quote you. I've tried doing some pinging tests, weirdly enough I get request timeouts when I try to run this program: Ethernet - Arduino Reference. I've literally just copy/pasted it into a new sketch, but when I ping that IP address it times out. Any ideas?

That sketch ought to work assuming your network config is compatible. The chipset underlying the Ethernet Shield 2 definitely supports ICMP (it would be amazing if it didn't I suppose!) so ping should work.

The sketch assigns the server IP address 10.0.0.177. What's the address of your PC? If it's a 192.x.y.z address it's not going to work.

Oh -- and for the avoidance of confusion and doubt, it might be worth describing your network topology.

For example, I might say something like:

"My PC and Arduino are both connected to a little desktop switch which itself connects using an Ethernet cable to my home router. The router is running DHCP, and hands out addresses 192.168.1.x. I've set up my PC and Arduino to use DHCP from the router. Once my Arduino has a DHCP address I log it using the serial port so I know what address to ping from the PC"

A quick description like this of how you're hooking everything up would probably help, otherwise we're all just guessing.

tomparkin:
That sketch ought to work assuming your network config is compatible. The chipset underlying the Ethernet Shield 2 definitely supports ICMP (it would be amazing if it didn't I suppose!) so ping should work.

The sketch assigns the server IP address 10.0.0.177. What's the address of your PC? If it's a 192.x.y.z address it's not going to work.

tomparkin:
Oh -- and for the avoidance of confusion and doubt, it might be worth describing your network topology.

For example, I might say something like:

"My PC and Arduino are both connected to a little desktop switch which itself connects using an Ethernet cable to my home router. The router is running DHCP, and hands out addresses 192.168.1.x. I've set up my PC and Arduino to use DHCP from the router. Once my Arduino has a DHCP address I log it using the serial port so I know what address to ping from the PC"

A quick description like this of how you're hooking everything up would probably help, otherwise we're all just guessing.

Yes hello, I can explain a bit more.
Currently, I just have the Uno and the and Ethernet Shield 2 connected to my laptop (Uno via USB, Shield via ethernet cable). I'm still pretty bad at figuring out exactly what IP goes to what, but from what I can tell the ethernet IP for my PC is 192.168.100.x. I'm still using that sketch from the Ethernet reference but have now changed the Shield's IP to 192.168.100.y per your suggestion, which partly worked this time (would this mean I'd have to configure the Epson's IP in a similar way? I think I've tried something similar, but perhaps I was missing something). I say partly because no data packets were lost, but I have this code in the loop() function that doesn't seem to think there's a client to the server (it doesn't print anything):

// if an incoming client connects, there will be bytes available to read:
  EthernetClient client = server.available();
  if (client == true) {
    // read bytes from the incoming client and write them back
    // to any clients connected to the server:
    Serial.println("Client is available");
  }

Is that because pinging from the command prompt doesn't actually produce a telnet client?
For the actual project, the setup is going to have the Uno + Ethernet Shield connected to an Epson robot via ethernet cable (the Uno will just be plugged into power). In the Epson programming, I am attempting to write strings to the Arduino using TCP/IP over the ethernet connection. I've tried a dozen different configurations of IPs on both sides but they just don't seem to see each other. I'm think I'm going to try and use PuTTY as a client to the Arduino server.

"Is that because pinging from the command prompt doesn't actually produce a telnet client?"

Yes. Ping uses ICMP, while the Ethernet server is waiting for a TCP connection.

The ping test is just to establish that the PC can "see" the Arduino. So long as the PC says ping is being responded too you're golden.

FWIW, telnet is a protocol of its own layered on top of TCP.

Hello everyone. I figured it out. The final configuration was:
Arduino and Shield as server, IP address of 192.168.100.x, opening port 2000
Epson robot as client, IP address of 192.168.100.y (should differ from Arduino IP only in last octet) writing to port 2000.

Thanks for the help everyone, especially @tomparkin!

Glad you got it sorted!

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