Hi,
I'm trying to build a very simple serial-to-Ethernet server (code below). But I can only receive over Ethernet when I'm sending something. If I don't send anything, then the characters get stuck somewhere until I send them.
Does anyone have any ideas as to why Ethernet sending only happens when I'm receiving characters?
/*
Serial to ethernet
*/
#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.
// gateway and subnet are optional:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xE1, 0xAB };
IPAddress ip(192, 168, 0, 200);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
// telnet defaults to port 23
EthernetServer server(23);
void setup() {
// Disable SD card
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Chat server address:");
Serial.println(Ethernet.localIP());
}
void loop() {
// wait for a new client:
EthernetClient client = server.available();
if (client) {
if (Serial.available() > 0) {
char thisChar = Serial.read();
if (client.connected()) {
client.print(thisChar);
}
}
if (client.connected() && client.available()) {
// read the bytes incoming from the client:
char thisChar = client.read();
Serial.print(thisChar);
}
}
}
Thanks,
Ag Primatic