Arduino don´t send ASCII

In the sketch attached below, I am trying to transmit an ASCII character trough ethernet. With this Sketch the ASCII character don't get to hyperterminal until I send any character before.
I need arduino send the character always, from the first power on without any need of request.

/*

*/
const int entrada0 = A0; // Nombre de la entrada analógica 0 de la placa, asignada como entrada 0 en programación

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,95);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup ()
{
pinMode(A0, INPUT);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();

}

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

//TRANSMISIÓN DE SEÑAL
{
if
(digitalRead(entrada0) == HIGH)
{server.println("A");
delay(100);
}
else if
(digitalRead(entrada0) == LOW)
{server.println("B");
delay(100);
}
}

}
}

TX_2.ino (1.04 KB)

You seem to have implemented a server which waits for an incoming connection from a client, waits for the client to send a byte, and then sends a response.

I need arduino send the character always, from the first power on without any need of request.

Where is it sending it to?

  1. Please reformat your code so it's readable.

  2. Please use code tags.

  3. Please reformat
    your code so
    it is read
    able.

Not your actual problem, but:

      if
        (digitalRead(entrada0) == HIGH)
        {server.println("A");
                delay(100);
      }
  else if
       (digitalRead(entrada0) == LOW)
        {server.println("B");
              delay(100);
      }

Is digitalRead(entrada0) HIGH? No. Ok, is it LOW? Of course it is! Why are you asking? You know it's not HIGH, so therefore it must be LOW - there is no other possible state.

This Arduino board must send data to a monitoring alarm software; this software don't ask to arduino, only receive data, so Arduino must transmit from the beginning, without wait for a connection.

Maybe choose a client better than a server?

Maybe choose a client better than a server?

That might work better.

elcano:
This Arduino board must send data to a monitoring alarm software; this software don't ask to arduino, only receive data

What port and protocol does the 'monitoring alarm software' use to receive the data?

The purpose of this project is that arduino could adapt to any alarm protocol and port. This way, I can install it in any existing system, only changing the bytes to send in the respective status of the input.

In my project, already works the tx of alarms and rx of relay signals in rs232, but it's imposible to make it run in Ethernet mode.

but it's imposible to make it run in Ethernet mode.

No, it's impossible to make it work in client/server mode, because, apparently, the alarm is neither a client (making GET requests) or a server (responding to GET requests).

There are other modes that the Ethernet shield can be used in, though client/server is the simplest.

elcano:
The purpose of this project is that arduino could adapt to any alarm protocol and port.

That's nonesense. To interact with a specific alarm server you need to know the protocol and port needed to access that server. Then you need to implement a client that uses that protocol to send the alarm to that server. Pick one, implement it and get it working. Once you've done that, you could consider generalising it to support other protocols.