Hello everyone!
I have connected my arduino uno R3 to intern site in small factory. I go pulses from PLC to SQL (always every 100 sec. i got one pulse).
My code work perfectly but once per 14 hours arduino restarting itself (my prediction).
Because second part (with temp variable) didnt process.
HERE IS AN EXAMPLE OF CODE:
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = {
// 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
IPAddress ip(xx);
IPAddress gateway(xx);
IPAddress dns(xx);
IPAddress subnet(xx);
EthernetClient client;
const int InputSignal[6] = {2,3,4,5,6,7}; // InputSignal[0] = 2
const bool Validation[6] = {true, true, true, true, true, true};
bool val = true;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip, dns, gateway, subnet);
Serial.println(F("Inicializace proměnných."));
delay(100); // Bezpečnostní čas pro nastartování čipu
pinMode(7, INPUT);
//Serial.println(Ethernet.localIP());
}
void loop(){
// I know i can use loop with other arguments, but this is more lovely solution
ProcessData("Machine=1&Validation=secret",7,val);
}
void ProcessData(String InputString, int InputSignal, bool &temp) {
if(digitalRead(InputSignal) == HIGH) {
if(temp == true){
if (client.connect("(my secret ip)",80)) { // 443 = HTTPS
client.println("GET (my secret file)");
client.println(" HTTP/1.1");
client.println("Host: (my secret ip)");
client.println("User-Agent: Arduino");
client.println("Accept: text/html");
client.println(InputString.length());
client.println();
}
if (client.connected()) {
client.stop();
}
temp = false;
}
}
if(digitalRead(InputSignal)==LOW && temp==false){
if (client.connect("(my secret ip)",80)) {
client.println("GET (my secret file)");
client.println(" HTTP/1.1");
client.println("Host: (my secret ip)");
client.println("Accept: text/html");
client.println(InputString.length());
client.println();
}
if (client.connected()) {
client.stop();
}
temp = true;
}
}
The second part starting with:
if(digitalRead(InputSignal)==LOW && temp==false) once per 14 hours is killed. Only one reason is why, because help variable is restarted by starting a chip.
Im thinking about add to every client.println(F(
Please can you help me why it is possible? I can filter the one bad input per this long period, but im lil bit nervous. Thanks guys!!!