Pages: 1 [2] 3   Go Down
Author Topic: Can not chat in two directions using Arduino Ethernet Shield, why?  (Read 4017 times)
0 Members and 1 Guest are viewing this topic.
Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't mean to tell you anything. I was just asking if you already had a broadband router.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So many misconceptions and misunderstandings that even I got lost in the way.


I'll try to get this straight, to everyone, including myself:

So he's got 2 PCs. Call them PC1 and PC2. The PC1 is connected to the Arduino using the USB cable, so that means he is controlling the arduino with PC1?

And the Arduino (and the Ethernet shield) and PC2 are connected via Ethernet cable. So he's sending a message from PC1 to PC2 via the Arduino, and wondering why he cannot reverse that, am I right?

If this is the case, the Arduino serves as a vessel for the message from PC1 to PC2, respectively "Sender" and "Receiver". The Arduino between Sender and Receiver acts as Forwarder, it forwards to message to the Receiver, via the Ethernet cable.

Now, metaphorically this is like a superball that doesn't bounce back, because you're throwing it in a bucket of cement.

For each connection, you need something that delivers it. In this case, you want a connection like this:
- PC1 to Arduino -> Arduino to PC2

Simplifying this you need 3 different connections (Though in reality you need more). Now you only have 2, so you need a connection from PC2 back to PC1. It's just like upload and download connections, you need both while browsing the internet.

If I am right, you can achieve this by connecting the Arduino to your broadband router/modem, or the same network your PC1 and PC2 are on.
However, I doubt the same sketch would work in that case.

Logged

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So he's got 2 PCs. Call them PC1 and PC2. The PC1 is connected to the Arduino using the USB cable, so that means he is controlling the arduino with PC1?

And the Arduino (and the Ethernet shield) and PC2 are connected via Ethernet cable. So he's sending a message from PC1 to PC2 via the Arduino, and wondering why he cannot reverse that, am I right?

I just upload code using PC1...
I'm sending message from PC2 to PC1 via Arduino, it works, but I wonder why I cannot reverse it (sending message from PC1 to PC2)
The rest is right... smiley-wink
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 149
Posts: 6119
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Take a look at the code in this thread:
http://arduino.cc/forum/index.php/topic,104390.msg783084.html#msg783084

It is a simple telnet type connection that works both ways. It is by no means complete, just a test. But it should give you an idea how it works. Feel free to modify it to your heart's content.

edit: That code above is a bit lacking. Try this. It is a bit better for two way comm. Change the network settings to yours. It will timeout the connected client if there is no input for about a minute.
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip( 192,168,2,2 );
IPAddress gateway( 192,168,2,1 );
IPAddress subnet( 255,255,255,0 );

EthernetServer server(23);

int loopCount = 0;
boolean isStopped;

void setup()
{
  Serial.begin(9600);
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  delay(2000);
  server.begin();
  Serial.println("Ready");
}

void loop()
{
  EthernetClient client = server.available();

  if(client)
  {
    Serial.println("Client connected");
    client.flush();
    isStopped = false;
    loopCount = 0;
    char c;
   
    client.println("Hello");

    while(Serial.available()) Serial.read();
   
    while (client.connected())
    {
      while(client.available())
      {
        c = client.read();

        if(c == 'x')
        {
          client.stop();
          Serial.println("stop - user request");
          isStopped = true;
        }
        else Serial.write(c);

        loopCount = 0;
      }

      delay(10);
     
      loopCount++;

      if(loopCount > 10000)
      {
        client.stop();     
        Serial.println("stop - timeout");
        isStopped = true;
      }

      while(Serial.available())
       {
          c =Serial.read();
          client.write(c);
          Serial.write(c);
       }
    }

    if(!isStopped)
    {
      client.stop();
      Serial.println("stop - disconnect");
    }   

    Serial.println("disconnected");
  }
}
« Last Edit: May 08, 2012, 06:49:33 am by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just upload code using PC1...
I'm sending message from PC2 to PC1 via Arduino, it works, but I wonder why I cannot reverse it (sending message from PC1 to PC2)
The rest is right... smiley-wink

Like I said, you don't have the necessary connections. Right now, you have a connection from PC2 to PC1, but not the other way around.
Logged

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I just upload code using PC1...
I'm sending message from PC2 to PC1 via Arduino, it works, but I wonder why I cannot reverse it (sending message from PC1 to PC2)
The rest is right... smiley-wink

Like I said, you don't have the necessary connections. Right now, you have a connection from PC2 to PC1, but not the other way around.

Danke for the response!:D

So, how I can get the connection from PC1 to P2 ?
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Aside from the use of the router mentioned earlier, you mean? You can't. Accept it and move on.
Logged

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Aside from the use of the router mentioned earlier, you mean? You can't. Accept it and move on.
So you mean if I use router, the I can do two or more way of communication?
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Possibly. The Ethernet shield allows for a small number of simultaneous connections. I don't know whether the sketch allows it though. The point of the Arduino is to allow for quick experimentation. Try it and see.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Aside from the use of the router mentioned earlier, you mean? You can't. Accept it and move on.
So you mean if I use router, the I can do two or more way of communication?

Yes, but you'll probably have to modify the sketch a little.
Logged

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Vielen Dank to all of you!
At least I find some hope!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Vielen Dank to all of you!
At least I find some hope!

You're welcome.

Earlier you said that you this was just an experiment for some project.
So what are you trying to do when you have this working?
Logged

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is just the experiment to get the idea how it communicate in many ways.

Then I can use the idea to send and receive information from 7segment display the distribute it to many client using LAN...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I see, so you're aiming for some sort of system to send messages to highly trained chimps in your mansion? smiley-grin
Logged

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I see, so you're aiming for some sort of system to send messages to highly trained chimps in your mansion? smiley-grin


Highly trained chimps?
Logged

Pages: 1 [2] 3   Go Up
Jump to: