Go Down

Topic: Can not chat in two directions using Arduino Ethernet Shield, why? (Read 4 times) previous topic - next topic

iDroid



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



Highly trained chimps?


Monkeys, workers.

Shouldn't have threw that joke to someone who might not get it, sorry :3

creativen


SurferTim


creativen


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: [Select]
#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");
  }
}



Hello SurferTim, oh yeah I just tested the code you gave me:
The result is my Netbook (say it PC2 --> client) can respond in telnet "Hello"
But the problem in my Notebook (say it PC1 --> server) can not open the serial monitor, what's wrong then yah?
it show red warning:
Code: [Select]
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.BoxLayout.preferredLayoutSize(BoxLayout.java:282)
at java.awt.Container.preferredSize(Container.java:1599)
at java.awt.Container.getPreferredSize(Container.java:1584)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1636)
at java.awt.BorderLayout.layoutContainer(BorderLayout.java:804)
at java.awt.Container.layout(Container.java:1421)
at java.awt.Container.doLayout(Container.java:1410)
at java.awt.Container.validateTree(Container.java:1507)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validate(Container.java:1480)
at java.awt.Window.show(Window.java:860)
at java.awt.Component.show(Component.java:1563)
at java.awt.Component.setVisible(Component.java:1515)
at java.awt.Window.setVisible(Window.java:841)
at processing.app.Editor.handleSerial(Editor.java:2416)
at processing.app.Editor$18.actionPerformed(Editor.java:671)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1225)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1266)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

dxw00d


SurferTim

#35
May 12, 2012, 01:15 pm Last Edit: May 12, 2012, 02:58 pm by SurferTim Reason: 1
@creativen: Have you used the serial monitor successfully before? If you have trouble with that, you can also use PuTTY (a terminal program) or HyperTerminal.

edit: Also remember the Arduino is normally reset when you connect to the serial port with a terminal program. If there are any connections active on the w5100, they will be thrown off.

If you want to disable that feature, there is a pair of small pads labeled "reset en" on the Uno/Mega circuit board. There is a very small trace between those pads. If you cut the trace, the Arduino will not reset when you connect with a terminal program. However, you will now be required to press the reset button on the Arduino/shield during the program upload to start the bootloader. Solder them back together, and it returns to resetting the Arduino.

creativen


Does the notebook have the Arduino USB connection?


Sure the notebook has usb cable to arduino UNO.
The netbook doesn't..it only connect to arduino ethernet shield via RJ 45 cable

Quote
@creativen: Have you used the serial monitor successfully before? If you have trouble with that, you can also use PuTTY (a terminal program) or HyperTerminal.

edit: Also remember the Arduino is normally reset when you connect to the serial port with a terminal program. If there are any connections active on the w5100, they will be thrown off.

If you want to disable that feature, there is a pair of small pads labeled "reset en" on the Uno/Mega circuit board. There is a very small trace between those pads. If you cut the trace, the Arduino will not reset when you connect with a terminal program. However, you will now be required to press the reset button on the Arduino/shield during the program upload to start the bootloader. Solder them back together, and it returns to resetting the Arduino.


Yes, I had used the serial monitor successfully before...It can show what I am typing in my netbook(in telnet terminal)...it could not send any string to the netbook (telnet terminal), so whatever I type in the serial monitor, will not appear in the netbook.
But now the serial monitor even can not appear due to the red warning.

zoomkat

Quote
The netbook doesn't..it only connect to arduino ethernet shield via RJ 45 cable


Hope it is a crossover cable. I just got an Acer Aspite One (11.3") and will connect my arduino soon to see how well it works.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

creativen


Quote
The netbook doesn't..it only connect to arduino ethernet shield via RJ 45 cable


Hope it is a crossover cable. I just got an Acer Aspite One (11.3") and will connect my arduino soon to see how well it works.


I use straight cable, but it works when I had used it to activate WORKGROUP where we can share folder from many computers.
What will you connect to your Arduino?Crossover cable? do you use ethernet shield? or you mean usb cable to connect your acer aspite one to the arduino?

Go Up