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
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.
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
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.
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.
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.
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.
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?
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();
}