Hi
i am having a huge issue with my code and was hoping someone could help.
this might be a simple fix, i just can seem to see it. my arduino has a check to trigger a reset to a mini pc.
the check is done if the mains is pulled out, or if the ethernet module recieves a 1
Everytime i send a 1 to the ethernet module it resets perfectly, without any issues.
The problem happens when i do a mains check, the trigger works perfectly using the mains check, however then the ethernet part stops working.
#include <UIPEthernet.h> // Lbrary
EthernetServer server = EthernetServer(23); //
uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
IPAddress myIP(192,168,1,60);
IPAddress gateway(192, 168, 1, 254);
IPAddress subnet(255, 255, 255, 0);
String readString;
int x;
int led = 9;
///////////////////////////////////////////////////////////////////////
int val = 0;
int checking = 1;
int doublecheck;
int signal_in = 9;
int connect_led = 8; //red
int dissconnect_led = 7; //green
int voltage_inPin = 6;
int relay = 5;
int chiko;
//////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac,myIP,gateway,subnet);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
pinMode(signal_in, OUTPUT);
pinMode(connect_led, OUTPUT);
pinMode(dissconnect_led, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(voltage_inPin, INPUT);
//digitalWrite(relay, HIGH);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
}
void loop()
{
server.begin();
EthernetClient client = server.available();
///////////////////////////////////////////////////////////////////////////////////////////////////////////
val = digitalRead(voltage_inPin);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
while (client.available()> 0) {
char c = client.read();
readString += c; //makes the string readString
delay(5); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
int commaIndex = readString.indexOf(',');
int secondCommaIndex = readString.indexOf(',', commaIndex+1);
String firstValue = readString.substring(0, commaIndex);
String secondValue = readString.substring(commaIndex+1, secondCommaIndex);
String thirdValue = readString.substring(secondCommaIndex+1); // To the end of the string
x = firstValue.toInt();
int y = secondValue.toInt();
int z = thirdValue.toInt();
}
if (x == 1){
digitalWrite(signal_in, HIGH);
chiko = 1;
}else{
digitalWrite(signal_in, LOW);
chiko = 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
if (val == 0)
{
digitalWrite(dissconnect_led, HIGH);
digitalWrite(connect_led, LOW);
doublecheck = 1;
//Serial.println("0");
}
if (val == 1 || chiko == 1){
Serial.println("1");
digitalWrite(dissconnect_led, LOW);
digitalWrite(connect_led, HIGH);
//digitalWrite(signal_in, HIGH);
checking = 0;
}
if(checking == 0){
delay(11000);
digitalWrite(relay, LOW);
doublecheck = 0;
checking = 1;
}
if(checking == 1 && doublecheck == 0){
digitalWrite(relay, LOW);
}
else{
digitalWrite(relay, HIGH);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
readString=""; //empty for next input
x = 0;
//client.stop();
delay(300);
}
my theroy is that once the mains check works the loop does not begin again. i have uploaded the code, hoping someone out there can help me.
oh yeah also once the mains part works and the ethernet part stops working. the only way to fix it is to shut down power to the arduino.
thank you