Hello,
I work for a while on a ethernet project with NANO+ENC28J60.
To improve realibility, I’ve done several improvements:
-lighter sketch/variable size (83% sketch - 74% memory variables)
-lighter library uipethernet
-no widget terminal use (it made the project crashing more often)
-local server on rasp zero
-new bootloader on NANO for using watchdog and winning space
I’m nearly happy of the result now.
But I still have some heartbeat-> disconnect->watchdog issues I would like to understand.
The problem is still present if I use a very light sketch (see below), and happens sometimes (not always) on several devices at the same time.
The devices and the server are on the same LAN, so I don’t think about a network issue but more a server issue.
So the question is what could I check on the raspberry? Which file? (the admin page don’t seems to be useful for that…)
What I can see on serial when it happens ->
__
_[28408864] Heartbeat timeout: 28408864, 28392863, 28406866_
_[28408865] Disconnected_
_[28408886] Connecting to 109.89.253.243_
_INTERRUPT COUNT=0_
_INTERRUPT COUNT=1_
_[28433732] Connecting to 109.89.253.243_
_INTERRUPT COUNT=2_
_INTERRUPT COUNT=3_
_INTERRUPT COUNT=4_
_[28458734] Disconnected_
_[28458735] Connecting to 109.89.253.243_
_INTERRUPT COUNT=5_
_INTERRUPT COUNT=6_
_INTERRUPT COUNT=7_
_[28483736] Connecting to 109.89.253.243_
_INTERRUPT COUNT=8_
_GO RESET IN 8SEC_
_WDT SETUP OK_
_[0] Using static IP_
_[1052] IP:192.168.0.57_
_[1053] _
_ / _ )/ /_ _____ / /___
_ / _ / / // / _ \/ '_/_
_ /____/_/\_, /_//_/_/\_\_
_ /___/ v0.4.8 on Arduino Uno_
_[1164] Free RAM: 467_
_[1186] Connecting to 109.89.253.243_
_[2714] <[02|00|01|00] _
_[2715] <4dxxxxxxxxxxxxxxxxxxxxxxxae_
_[2760] >[00|00|01|00|C8]_
_[2761] Ready (ping: 46ms)._
//JUST CONNECT+WD R7 ->to test stability connection & debug (23648/1357)
//<<LIBRARIES>>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save flash space
#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_NO_BUILTIN // Disable built-in analog & digital pin operations to spare flash space
#define BLYNK_NO_FLOAT // Disable float operations to spare flash space
#define BLYNK_NO_INFO // Skip device info to spare flash space
#include <BlynkSimpleUIPEthernet.h> // ENC28J60 ethernet BLYNK library
#include <avr/wdt.h> // Watchdog library
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";//R7////////////////////////////
char Flag_Init_Boot='0';
byte Counter_WD = 0; // Count number of times ISR is called.
unsigned long lastRunTime=0;
float test=0;
// Mac address should be different for each device in your LAN
//byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; //Original mac address
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xAA, 0xA7 }; // modify the last 2 colomn hexa dicimal only ex.. (0xAA, 0xA1 };)
IPAddress localip ( xxxxxxxxxxxxxxx); // your arduino i.p address, through ENC28J60
IPAddress mydns (xxxxxxxxxxxxxxxxx);
IPAddress gateway ( xxxxxxxxxxxxxxxxx);
IPAddress subnet (xxxxxxxxxxxxxxxxxx);
IPAddress serverip (xxx, xx, xxx, xxx); // your local server i.p address
void setup() {
Serial.begin(9600); // start serial for output
watchdogSetup();
Blynk.begin(auth, serverip, <PORT>, localip, mydns, gateway, subnet, mac); // full IP config to spare 2.5k sketch
}
//FONCTIONS WATCHDOG
void watchdogSetup(void) {
cli(); // disable all interrupts PS: la fonction disable, puis enable ne fonctionne pas => j'utilise la méthode de config directe des registres WDTCSR et MCUSR
MCUSR = 0; //to re-enable the interrupt by clearing the flag 1 in the bit WDRF -> automatique avec NANO OPTIBOOT au démarrage et après reset
wdt_reset(); // reset the WDT timer
WDTCSR |= (1<<WDCE) | (1<<WDE); // Enter Watchdog Configuration mode:
WDTCSR = (1<<WDIE) | (0<<WDE) | (1<<WDP3) | (0<<WDP2) | (0<<WDP1) | (1<<WDP0); // Set Watchdog settings: ->interrupt only 8sec
sei();
Serial.println(F("WDT SETUP OK"));
}
ISR(WDT_vect) { // Watchdog timer interrupt code - be careful not to use functions they may cause the interrupt to hang and prevent a reset.
Serial.print(F("WD INTERRUPT COUNT="));Serial.println(Counter_WD);
if (Counter_WD < 8) //byte CounterMax_WD = 22; // Timer expires after about 8x8sec = 64 secs (with WD timer=8 sec) -->>test 22 (~3minutes) KO, parfois reste planté!
{
wdt_reset(); // start timer again (still in interrupt-only mode)
Counter_WD+=1;
}
else // then change timer to reset-only mode with short (16 ms) fuse
{
Serial.println(F("GO RESET IN 8SEC"));
cli(); // disable all interrupts
WDTCSR |= (1<<WDCE) | (1<<WDE); // Enter Watchdog Configuration mode:
WDTCSR = (0<<WDIE) | (1<<WDE) | (1<<WDP3) | (0<<WDP2) | (0<<WDP1) | (1<<WDP0); // Set Watchdog settings: ->reset only 8sec
sei();
}
}
void loop(){
unsigned long currentTime = millis();
while (Blynk.connected()==false) {Blynk.disconnect(); Blynk.connect();} //wait connection serveur//semble mieux reprendre la connexion que Blynk.run(); //reste true ~10sec qd la connexion est perdue -> cfr heartbeat? & la boucle tourne au ralentis (~15sec) qd =false -> cfr fonctions discoonnect/connect?
Blynk.run();
if (Flag_Init_Boot=='0'){ //envoi initial vers serveur BLYNK
Blynk.email(F("R7"),F("WD"));
Blynk.notify(F("DEBUG R7"));
Flag_Init_Boot='1';
}
if (currentTime - lastRunTime >= 5000) {
lastRunTime = currentTime;
test=20+(10*sin(lastRunTime/10000));
Serial.print("Serial= ");Serial.println(test);
Blynk.virtualWrite(V19,String(test)); // affichage sur page LIVE = widget poids
}
wdt_reset();Counter_WD=0; //reset timer watchdog & compteur interrupt
}