Go Down

Topic: TCP/IP communication struggles (Read 276 times) previous topic - next topic


I'm using an Arduino Uno and the Arduino Ethernet Shield 2. I have a simulation of an Epson robot and I am trying to send cycle time data (just a string of numbers) over to the Arduino via TCP/IP (on a real robot there would be an ethernet cable connecting the two, using a simulation it's hooked up to my computer). This was working at one point, but I must have changed something because no matter what I've seemed to try the Arduino just doesn't receive data from the robot. I've tried it both as a server and a client. I've also done this with the robot.  I at least know that the robot is sending data out as I've been able to receive it with other software (PuTTY). I don't think my code will tell you much, I would be more than happy with just some rules of thumb when trying to communicate as a client or server. But if something sticks out to you, please feel free to bring it up. The commented out code shouldn't be relevant. Thanks in advance for any help. 

Am I wrong in that all that should be needed is the server's IP and the port number?

In this particular case, the output is always "failed." Client.connect is returning a 0. 
Code: [Select]
#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
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);
  // begin ethernet connection
  if (client.connect(epsonIP, 2000)){
    Serial.println("connected to robot");
  } else {
//  // 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.available() == true) {

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

Juraj is the loopback address

why did you put this in "WiFi101 shield" section?

Go Up