Brown outs or reboots

Something like this https://www.amazon.com/APC-Back-UPS-Battery-Protector-BE750G/dp/B000Z80ICM which is fine for Arduino’s etc but your pumps would need much more powerful units.

I was just thinking that if time is critical so is the power to feed and water your crop. If you lose power and therefore clock time from Blynk the crop will perish even with a physical, battery powered RTC.

I don’t know how this project would need to be modified to fit into other peoples realities, but in mine, a brown out consists of a few seconds of no power to as much as a “few” minutes at most. I suppose if we were to lose power extensively, an indoor garden probably wouldn’t be a priority unless in a Doomsday prepping scenario. I suppose as the project is grown more and funds to invest into become more plentiful I will try to tackle that concern as I’m a fan of redundancies. Still though, all of that is kind of a moot point because when power is returned, if internet access isn’t quickly made available, the project halts functionality and impatiently waits like Sonic the Hedgehog did in the original Sega game.
https://www.youtube.com/watch?v=9VfGDYuMaD0

How long does it normally take for your W5100 to make an internet connection?

Did you try varying the 5s and 25s variables?

When the network is connected during a test scenario, the project goes right through setup in maybe as long as 15 seconds. However, in actual brown outs, the router reboots which averages 5 minutes, and if the router becomes corrupted, or I have to call the ISP and troubleshoot extended losses of connection, I’m sure you can imagine how this can easily snowball into a several hour ordeal which is why I am adamantly trying to chase down this bug, but with my novice level coding skills, I’m limited to what I can do.

I here bad things about the W5100 but you could try:

Setting the 5 to 20.
Setting the 25 to 30.

1 Like

It’s changed. I’ll test to see if it gets through setup after a reboot with no network.

unsigned int myEthernetTimeout =   20000;  //  5.0s Ethernet Connection Timeout (ECT)
unsigned int blynkInterval     =  30000;  // 25.0s Check Server Frequency      (CSF)
unsigned long startConnecting = millis();

Edit - I had to change void myFunction from V11 to V22 as 11 was already in use.

I can’t understand why this isn’t exiting the setup and progressing into the loop/timers/functions?

  while (Blynk.connect() == false)
  {
    Blynk.connect();
    if (millis() > startConnecting + myEthernetTimeout) {
      Serial.print("\tUnable to connect to server. ");
      break;
    }

Dunno but that’s not how I coded it in setup().

I have the following setup:

void setup()
{
  //Serial.begin(9600);
  Serial.begin(115200);
  Serial.println("setup start...");

  Serial.println("dhtA.begin()...");
  dhtA.begin();

  Serial.println("dhtB.begin()...");
  dhtB.begin();

  Serial.println("setting DHT's...");
  pinMode(A0, INPUT_PULLUP);    // DHT22 use internal 20k pullup resistors
  pinMode(A2, INPUT_PULLUP);

  Serial.println("Wire.begin()...");
  Wire.begin();

  Serial.println("RTC.begin()...");
  RTC.begin();

  Serial.println("turning relays off...");
  for (int allRelays = lightA; allRelays <= VentB; allRelays++)
  {
    pinMode(allRelays, OUTPUT);
    digitalWrite(allRelays, TURN_OFF);
  }

  Serial.println("setting pump pinMode's...");

  for (int p = 0; p <= 7; p++)
  {
    pinMode(pumpPin[p], OUTPUT);
  }

  Serial.println("setting timers...");
  timer.setInterval(2000L, timeRoutine);      // 2 second intervals between timed routiness
  timer.setInterval(5001L, climateRoutine);   // 5 second intervals between climate routines
  timer.setInterval(15000L, syncRTCHardware);  // synchronize the RTC device with the server time every 15 seconds
  timer.setInterval(5000L, displayDateTime);   // update the LCD Widget every 5 seconds
  //timer.setInterval(15000L, checkBlynkConnection); // check Blynk connection every 15 seconds
  timer.setInterval(207L, dosingPumps);       // 0.2 second interval to maintain accuracy (+/- .25)
  timer.setInterval(1003L, ROcheck);          // 1 second interval between RO pump routines
  timer.setInterval(myEthernetTimeout, myfunction);
  timer.setInterval(blynkInterval, checkBlynk);   // check connection to server per blynkInterval
  //Ethernet.begin(arduino_mac, arduino_ip, dns_ip, gateway_ip, subnet_mask );
  Serial.println("beginning Blynk...");
  // Blynk stuff after timers
  Blynk.config(auth, server);
  Blynk.connect();
  Serial.println("setup complete.");
}

Notice I have commented out your original connection check so it’s now:

//timer.setInterval(15000L, checkBlynkConnection); // check Blynk connection every 15 seconds

and for me I have the Ethernet.begin() active.

When first reading through your function, I noticed the break; statement, but didn’t know exactly what it was so I went to arduino/Reference and learned that it’s a way to exit from a function, so I figured, “why not try it, the worst that can happen is that it doesn’t work” which BTW it doesn’t, lol

but have you tried the simplified version of setup() without the while statement?

Not sure why the W5100 would be that much different to the super cheap ENC28J60.

Presumably you have the proper W5100 not the cheap clones with the wrong resistor values.

I have a Chinese clone Mega that came with Ethernet shield both for $30. I also have a Freetronics Ethermega that was intended to be the board I use, but they no longer support their own driver, so I would need to revert my OS back to Windows 7 to be able to upload a sketch to it which I am not considering. All other things aside though, this clone is doing every single task I program it to do, so I assume the resistors are good enough. I also can’t comprehend how it could do all other tasks, but gets hungup in the setup after a reboot. That said, I will accept that the Wiznet is simply out dated and I will get the chip you suggested as it’s a cheap attempt at a bug fix and then resume the bug hunt.

This is the thread for fixing the wrong resistors but as you say probably not your issue https://forum.arduino.cc/index.php?topic=351477.0

I did notice that the Freetronics and presumably your clone Meg and Ethernet shield can use the standard Arduino Ethernet library. Most, if not all, of the examples use MAC assignment and Ethernet.begin() just like my ENC28J60. Not sure why you are not using them in your sketch.

prior to this situation, I never had need of adding in the extra language as the functionality was good and constant.

This is a Freetronics page for fixing the Ethernet on some W5100 systems after a reset https://www.freetronics.com.au/pages/usb-power-and-reset#.WaQ--j6g-00

For the record, the board that is now running my sketch, that I also use for testing and development is the Chinese clones. The Ethermega was rendered into a paperweight when I upped my PC OS to Windows 10 from Windows 7. The Freetronics driver that is needed to be able to upload sketches is only written to run on Windows 8 at the latest. Several, including myself have expressed our concerns on the Freetronics forums, but I believe our requests have fallen on deaf ears. So the way I see it, if your suspicions regarding the weaknesses of the W5100 hold merit, I’m not able to advance my project beyond this point until I get a new Ethernet chip. I found one locally from a 3D print hardware shop for under $6 which is more than reasonable. After receipt on my current order from them is complete, if the shipping time is also reasonable. I will order the chip from them and get back to chasing that bug.

Which board is the $6 unit?

https://reprapchampion.com/products/enc28j60-ethernet-lan-module-3-3v-for-arduino-51-avr-spi-stm32-lpc

edit - now that I have a 3d printer, I no longer need as much tech smashed into one board to fit into small project cases, I can design and print my own custom cases.

1 Like

I just added your code (finally) with the Ethernet language, but for some reason, the UIPEthernet library isn’t recognized. I added 0.4.8 last night and merged it with 0.4.7. Is this a known problem that others have had?

This is only for the ENC28J60 not the W5100.

1 Like

I think that was probably because you were using the nasty Blynk.begin() function. Below is a sketch that compiles for a W5100 but it’s untested. You will need to enter your details for IP’s etc at lines 12 to 15. You might need to vary the 25 and 30s entries at lines 19 and 20.

When your ENC arrives you will then need to switch to the UIP library version.

// W5100NoBlock.ino for https://community.blynk.cc/t/brown-outs-or-reboots/16909
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#define W5100_CS  10
#define SDCARD_CS 4

char server[] = "blynk-cloud.com";
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };  // Normally any MAC is OK

char auth[] = "YourAuthToken";                // ENTER YOUR TOKEN
IPAddress arduino_ip ( 192, 168,  10, 120);   // SET UP A STATIC IP
IPAddress dns_ip     ( 192, 168,  10,  90);   // ADD ROUTER IP FOR DNS
IPAddress gateway_ip ( 192, 168,  10,  90);   // ADD ROUTER IP FOR GATEWAY

IPAddress subnet_mask( 255, 255, 255,   0);   // Standard subnet mask

unsigned int myEthernetTimeout =   25000;     // Ethernet Connection Timeout (ECT)
unsigned int blynkInterval     =   30000;     // Check Server Frequency      (CSF)
unsigned long startConnecting = millis();

BlynkTimer timer;

void setup()
{ 
  Serial.begin(115200); // Debug console
  Serial.println();
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  timer.setInterval(myEthernetTimeout, myfunction);
  timer.setInterval(blynkInterval, checkBlynk);   // check connection to server per blynkInterval
  //Blynk.begin(auth);  // blocking routine, not to be used
  Ethernet.begin(arduino_mac, arduino_ip, dns_ip, gateway_ip, subnet_mask );
  Serial.println("\tBeginning Blynk...");
  Blynk.config(auth, server);
  Blynk.connect();
  Serial.println("\tSetup complete.");  
}

void myfunction() {
  Serial.println("\tLook, no Blynk block.");
  if (Blynk.connected()) {
    Serial.println("\tEthernet still connected.");
    Blynk.virtualWrite(V121, millis() / 1000);   // SELECT A VIRTUAL PIN TO SEND MILLIS() TO
  }
}

void checkBlynk() {
  while (!Blynk.connected()) {
    Blynk.connect();
    if (millis() > startConnecting + myEthernetTimeout) {
      Serial.println("\tUnable to connect to server. ");
      break;
    }
  }
  Serial.println("\tChecking again in 25s.");
}

void loop()
{
  if(Blynk.connected()){  // this ensures it doesn't just loop trying to reconnect
    Blynk.run();
  }
  timer.run();
}