Ethernet Library & Wiz850io - How to reconnect after cable pull WITHOUT power cycle
Hi, I use various Teensy's for projects, and generally go with a Wiz850io for ethernet comms, and I often run into an annoying problem where my code doesn't catch and fix when a cable is accidentally disconnected. This is only a problem when the Wiz chip and PC are actually communicating, if happens I can't reconnect to the Wiz Chip until i turn everything off and on again. There must be a simple way to watch for this and reset the WIZ850io but I haven't found a way via examples or Google. Need help!
Here is the stripped down version of the code I use to run the chips. This is using Ethernet.h library, and in my test setup I'm using Teensy 3.2 & Wiz850io.
Thanks!
Hi, I use various Teensy's for projects, and generally go with a Wiz850io for ethernet comms, and I often run into an annoying problem where my code doesn't catch and fix when a cable is accidentally disconnected. This is only a problem when the Wiz chip and PC are actually communicating, if happens I can't reconnect to the Wiz Chip until i turn everything off and on again. There must be a simple way to watch for this and reset the WIZ850io but I haven't found a way via examples or Google. Need help!
Here is the stripped down version of the code I use to run the chips. This is using Ethernet.h library, and in my test setup I'm using Teensy 3.2 & Wiz850io.
Thanks!
Code:
#include <Arduino.h> //Arduino to use PIO
#include <SPI.h> //spi for Ethernet
#include <Ethernet.h> //using newer wiz chip
#include <EEPROM.h> //collect data from memory
////////ETHERNET SETTINGS/////////
byte mac[] = {0xDE, 0xAD, 0xFE, 0xEF, 0xFE, 0xFD}; //MAC address of the shield
byte ip[] = {192, 168, 1, 102}; //IP Address of the shield
EthernetServer server(22); //name Server server port 6340
EthernetClient client; //name Client client
unsigned long inByte = 0; // ALL THE INCOMING TCP MESSAGES CALL INBYTE
/////////TIMER SETTINGS////////////
unsigned long previousMicros = 0; //USED FOR SENDING TCP SENSOR STRING
unsigned long previousMicros2 = 0; //USED FOR SENDING SERIALTEST STUFF
unsigned long currentMicros; //current time - START OF EVERY MAIN LOOP
void sensorstring() //ETHERNET STUFF
{
if (currentMicros - previousMicros >= 30000) // check that current time - last updated time = x ms
{
String dataString; //RE ESTABLISH STRING
dataString += String("5000"); // send "5000"
dataString += ",";
server.print(dataString); // send data string
server.write(0x0D); // carriage return
server.write(0x0A); // end terminal ***These two hex commands are needed for labview in order for TCP read to not over/under read
previousMicros = currentMicros; //stamp time
}
}
void serialstring()
{
if (currentMicros - previousMicros2 >= 25000)
{
Serial.println("Serial");
previousMicros2 = currentMicros; //stamp time
}
}
void setup()
{
digitalWrite(LED_BUILTIN, HIGH);
//////////ETHERNET STUFF/////////////
pinMode(9, OUTPUT);
digitalWrite(9, LOW);
delay(200);
digitalWrite(9, HIGH); //This^ is needed to RESET the WIZ820io, will not work without this...
// Initialize the ethernet device
Ethernet.begin(mac, ip); // begin ethernet....working without subnet?
// Start listening for clients
server.begin(); // open as server
Serial.begin(9600);
}
void loop()
{
currentMicros = micros(); // get the time at the start of this loop() - call it currentMicros
client = server.available(); // broadcast to client
client.setTimeout(5); // max waiting time is 10ms
sensorstring();
serialstring();
}