Ethernet bidirectional communication

Hello, i’m new to Arduino, so maybe this question it’s already solved.

I have an arduino setup as a server, sending over ethernet (telnet port) constant data about the input values. What I want now is, if the client machine sends a command (suppose the client saw an irrgular value and wants to switch the ouotput pin 4 from HIGH to LOW) arduino responds to it.

I saw some implementations of it as a shell (arsh http://biot.com/arsh/ or breakfast http://inhocsignovinces.net/2008/10/30/breakfast-serial-for-arduino/) but I want to do an implementation over the ethernet shield, instead of the serial port.

Right now the code I have is:

#include <Client.h>
#include <Ethernet.h>
#include <Server.h>

int ledPin = 13;
int err = 0;
int val = 0;
int pin = 0;
char version[] = "Prototipo";
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 1, 0, 121 };
byte gw[] = { 10, 1, 0, 100 };
byte subnet[] = { 255, 255, 255, 0 };
Server server = Server(23);

void setup()
{
  pinMode(ledPin, OUTPUT);
  Ethernet.begin(mac, ip, gw, subnet);
  server.begin();
}

void loop()
{
  Client client = server.available();
  if (client) {
    while (pin <= 5) {
      val = analogRead(pin);
      delay(1000);
      server.print("INPUT");
      server.print(":");
      server.print(pin);
      server.print(":");
      server.print(val);
      server.print(":");
      server.print("\n\r");
      pin++;
    }
    pin = 0;
  }
  // Debug condition
  else {
    server.print("Ningun programa cliente conectado.");
    digitalWrite(ledPin, HIGH);
  }
}

As you can see, right now it only sends data through ethernet if someone is connected. Is there any way to do the other part?

Another more graphical example of what I want to do:

  • Client connects to arduino
    arduino: input 4 232
    arduino: input 5 123
    arduino: input 0 0
  • Client watches that value is incorrect and wants to disconnect the device connected to the output pin related to that input
    client: output 3 LOW
  • Arduino sets the output pin 3 to LOW and continues to send input data

Sorry if it’s a fuzzy explanation, but I’m not english (I already asked in the respective international forum, but they only pointed me to arsh)

Thanks.

Hi, Oscar C.:

At the risk of suggesting another shell: I have tested Bitlash (http://bitlash.net) over telnet with both the Adafruit and the WIZ-5100 based ethernet shields. It worked fine for me.

You'll have to enable a definition in bitlash.h -- search for and enable WIZ_ETHERNET and you'll find documentation of the pinout I tested, which may need adjusting for your hardware.

You will need to use Arduino 0016, or fix a small Bitlash bug to use 0017 (the bug: 0017 doesn't like '-' in filenames or folder names. the fix: remove them from the filenames in bitlash/examples.)

Happy to take questions.

Cheers!

-br http://bitlash.net

Thanks for the quick reply! I'll take a look on it tomorrow (here it's 4AM right now). I have a standard arduino ethernet shield, so it should work fine.

I installed it as a 0016 library and it gave me this error just when the program started:

In file included from bitlash.cpp:32:
src/bitlash-cmdline.c:43: warning: only initialized variables can be placed into program memory area
src/bitlash-cmdline.c:231: warning: only initialized variables can be placed into program memory area
In file included from bitlash.cpp:36:
src/bitlash-functions.c:72: warning: only initialized variables can be placed into program memory area
src/bitlash-functions.c:75: warning: only initialized variables can be placed into program memory area
In file included from bitlash.cpp:38:
src/bitlash-parser.c:55: warning: only initialized variables can be placed into program memory area
src/bitlash-parser.c:109: warning: only initialized variables can be placed into program memory area
src/bitlash-parser.c:297: warning: only initialized variables can be placed into program memory area
src/bitlash-parser.c:298: warning: only initialized variables can be placed into program memory area
src/bitlash-parser.c:364: warning: only initialized variables can be placed into program memory area
src/bitlash-parser.c:365: warning: only initialized variables can be placed into program memory area

Those warnings are normal (or perhaps "expected"). Your install is fine.

You might want to start by uploading one of the plain vanilla bitlash examples to your Arduino and make sure you're happy with how it works over USB serial. Then turn on the WIZ_ETHERNET define and get it working over telnet.

-br