Hi
I am attempting to use an ENC28j60 to pass serial through to an Arduino Uno from Ethernet.
When I connect using putty, I can connect to the ENC28J60 and send commands. If the computer is left connected , all is well.
Should the Ethernet plug be disconnected , then the ENC28J60 stops passing serial.
I can still ping the ENC, but until the unit is repowered, then it will not respond.
Below is the code I am using
If anyone can see why the unit stops receiving , any assistance would be great
And I am using the ENC28J60 as I want to be able to make my own PCB for the project
[code]
#include <UIPEthernet.h>
#include <SPI.h>
// ethernet
byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x90, 0x86 };
byte ip[] = { 192, 168, 1, 151 };
byte gateway[] = { 192,168,1,129 };
byte subnet[] = { 255, 255 ,255 , 0 };
// serial connection
int serialBaud = 19200; // Baud speed
int serialCfg = SERIAL_8N1; // unit has 8 data,no parity, 1 stop bit
// socket parameters
int serverPort = 8888;
// start TCP servers
EthernetServer server(serverPort);
void setup() {
Serial.begin(serialBaud, serialCfg); // open serial communications
Ethernet.begin(mac, ip, gateway, subnet); // start the Ethernet connection
server.begin(); // begin listening for TCP connections
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
String clientMsg ="";
while (client.connected()) {
// transmit
while (client.available()) {
char c = client.read();
clientMsg+=c; // store received chars up to newline
if (c == '\n') {
Serial.print(clientMsg); // then send the message through serial
clientMsg = "";
Serial.flush();
}
}
// receive
int incomingByte = 0; // for incoming serial data
while (Serial.available() > 0) { // if data has been received from the serial connection
incomingByte = Serial.read();
client.print(char(incomingByte)); // print the char data back to the client
if (char(incomingByte) == '\n')
client.flush();
}
}
}
}
[/code]