The code is great, I put only the part of the PING and the button of the Application that serves to enable PING. Without PING enable, operate without disconnecting, from the moment PING starts, it starts to connect and disconnect. Both on the serial monitor and in the application.
If the problem is the time Arduino gets busy with PING, I wonder if there is any way to increase this timeout.
All of my app displays and widgets are set to read more than 5 seconds. So I do not think that’s it.
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <EEPROM.h>
#include <ICMPPing.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
#define rele 3
#define saida1 4
#define saida2 5
#define saida3 6
#define saida4 7
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEB};
IPAddress ip(192, 168, 2, 115);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dnServer(8, 8, 8, 8);
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
IPAddress pingAddr1(192,168,2,120); SOCKET pingSocket1 = 0; ICMPPing ping1(pingSocket1, (uint16_t)random(0, 255));
int habilita_ping1 = 0; int conta_ping1 = 0;
BLYNK_WRITE(V25) { int buttonState = param.asInt();
if (buttonState == 1) {habilita_ping1 = 1;} if (buttonState == 0) {habilita_ping1 = 0;} Serial.println(habilita_ping1); }
SimpleTimer timer;
void pingar()
{
if (habilita_ping1 == 1){ICMPEchoReply echoReply = ping1(pingAddr1, 4);
if (echoReply.status == SUCCESS){conta_ping1=0;Serial.println("Ping");}
else{conta_ping1++; Serial.print("Nao Pingou "); Serial.println(conta_ping1);}
if(conta_ping1 > 5){ Serial.println("reset"); digitalWrite(saida1,HIGH); delay(5000); conta_ping1=0; digitalWrite(saida1,LOW);}}
}
void setup()
{
analogReference(DEFAULT); Serial.begin(9600);
Blynk.begin(auth, "blynk-cloud.com", 8442, ip, dnServer, gateway, subnet, mac);
timer.setInterval(10000L, pingar);
}
void loop()
{
Blynk.run();
timer.run();
}