Brown outs or reboots

Your full code with our mods is working fine with the $2 ENC28J60 :slight_smile:

So you can upload my sketch, power off, disconnect internet, power on and have verified that the functions are executing prior to reinstating the network?

I haven’t done exhaustive testing but yes.
Maybe you can PM the QR code and I’ll test further.

@myggle I added Terminal, LCD and 4 display widgets for temperature and humidity of 2 sensors.
I changed my virtual pin from V11 to V121 as you were already using V11. Screenshots below. First Mega has been running for 29275 seconds and second after disconnecting and reconnecting the power after 20 seconds. LCD and Terminal updating fine. I don’t have any DHT sensors, only DS18B20’s, so the display widgets show 0. I do have 4 or 5 RTC boards that I bought a few years ago but other than testing them I have never used them, hence the weird looking time in the LCD.

When I have time I might hook up a physical RTC to test your project further.

Same result when powering the router down and back up but this doesn’t reset the Mega.

setup start...
dhtA.begin()...
dhtB.begin()...
setting DHT's...
Wire.begin()...
RTC.begin()...
turning relays off...
setting pump pinMode's...
setting timers...
beginning Blynk...
BLYNK_CONNECTED
setup complete.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
syncRTCHardware
Server Time: 28/08/2017 11:28:58
Resynching RTC Time...
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
Checking again in 25s.
Blynk not connected. Exiting syncRTCHardware.
displayDateTime
	Look, no Blynk block.
displayDateTime
	Look, no Blynk block.
displayDateTime
	Look, no Blynk block.
Blynk not connected. Exiting syncRTCHardware.
displayDateTime
	Look, no Blynk block.
displayDateTime
	Look, no Blynk block.
	Unable to connect to server. Checking again in 25s.
Blynk not connected. Exiting syncRTCHardware.
displayDateTime
	Look, no Blynk block.
displayDateTime
	Look, no Blynk block.
displayDateTime
	Look, no Blynk block.
displayDateTime
	Look, no Blynk block.
Blynk not connected. Exiting syncRTCHardware.
displayDateTime
	Look, no Blynk block.
	Unable to connect to server. Checking again in 25s.
Blynk not connected. Exiting syncRTCHardware.
displayDateTime
	Look, no Blynk block.
displayDateTime
	Look, no Blynk block.
displayDateTime
	Look, no Blynk block.
displayDateTime
	Look, no Blynk block.
displayDateTime
	Look, no Blynk block.
BLYNK_CONNECTED
	Unable to connect to server. Checking again in 25s.
syncRTCHardware
Server Time: 28/08/2017 11:30:29
Resynching RTC Time...
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
syncRTCHardware
Server Time: 28/08/2017 11:30:44
Resynching RTC Time...
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
Checking again in 25s.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
syncRTCHardware
Server Time: 28/08/2017 11:30:59
Resynching RTC Time...
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
syncRTCHardware
Server Time: 28/08/2017 11:31:14
Resynching RTC Time...
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
Checking again in 25s.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
displayDateTime
	Look, no Blynk block.
	Ethernet still connected.
syncRTCHardware
Server Time: 28/08/2017 11:31:29

P.S. I switched the month and day around to cover our local standard.

Hooked up the physical RTC now and it looks much better. I’m intrigued to know why you need to sync server and physical RTC every 15s, in fact why do you need a physical RTC at all? Your Mega will keep time from the server even when the server is not available.

@myggle got your project now from the QR image. I think Blynk said recently that tinyurl are encoding the url’s and that’s probably why they weren’t working.

Screenshot to follow shortly.

The physical RTC is an absolute must for this project as there are many timed based events that simply need to be adhered to in order to maintain a thriving crop. So if for example the network were to fail for hours, days or months, as it is now the project would crash and nothing would get done and all plants would die because the project was too dependent on Blynk to function. TBH, I plan to change the sync time to roughly once a month or twice a month as it’s a fairly accurate RTC and will maintain time for very long periods of time as I’m sure you know. So your server reprograms my RTC, and the time kept on it is what I use to test the time based functions. I also wish to point out that I started building this project about 2 years prior to Blynk, so a lot of code I already wrote for this purpose.

1 Like

Screenshot of your project. I noticed that when I changed the TZ in Blynk’s RTC widget it didn’t update the app. I needed to reflash the Mega. Perhaps you have the time code in setup().

I don’t have the time code in setup. Are suggesting I put it there?


#include <SPI.h>                    // Used by Blynk
#include <Ethernet.h>               // Used by Blynk
#include <BlynkSimpleEthernet.h>    // Used by Blynk
//#include <BlynkSimpleEthernet2.h>
//#include <BlynkSimpleEthernetV2_0>
#include <Wire.h>                   // I2c
#include <WidgetRTC.h>
#include <DHT.h>                    // DHT data wire connected to I/O pin with a 10k pullup resistor to 5V
#include <RTClib.h>                 // RealTimeClock Library for DS1307 and DS3231
#define BLYNK_PRINT Serial

char auth[] = "AUTH";
char server[] = "blynk-cloud.com";
unsigned int port = 8442;

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

//  DHT Reference Values - CHANGE THESE TO MANAGE YOUR ROOM'S CLIMATE - //
byte hiMaxTemp = 80;   // temp that triggers heat removal device(s) on
byte lowMaxTemp = 70;  // temp that triggers heat removal device(s) off
byte hiMinTemp = 55;   // temp that triggers heater on
byte lowMinTemp = 65;  // temp that triggers heater off
byte hiHum = 58;       // High humidity value that triggers dehumidifier on
byte lowHum = 40;      // Low humidity value that triggers dehumidifier off

//-Digital Pins - Peristaltic Pump Variables - 00 Series Pins
const int pumpPin[8] = { 2, 3, 4, 5, 6, 7, 8, 9 };
int dosingLEDs[8]  = { V14, V15, V16, V17, V18, V19, V20, V21 };
uint32_t multiplier[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; //ms per ml
uint32_t startPump = 0;
uint32_t runCount;
bool pumpRunning;
const char *nuteType[8] = { "GH Armor Si", "GH Flora Blend", "GH CALiMAGic", "GH Kool Bloom",
                            "GH Flora Gro", "GH Flora Micro", "GH Flora Bloom", "GH pH Down"
                          }; //Text Printed to Terminal Widget^^

float DOSEml;      //Step Widget (0.25 per step, send step/NO, loop values ON)
int button = 0;   //Button Widget set to Switch
int x;           //Correlates Array Positions with Pump Motor Pins
int calibration;

BLYNK_WRITE(V4) {
  x = param.asInt() - 1;
}
BLYNK_WRITE(V5) {
  DOSEml = param.asFloat();
}
BLYNK_WRITE(V6) {
  button = param.asInt();
}
BLYNK_WRITE(V13) {
  calibration = param.asInt();
}
//
uint32_t msPerGallon = 33000; //ms per gallon
uint32_t ROstart = 0;
uint32_t countGallons;
boolean runningRO = false;
int pumpAon;          //Blynk Override to turn pumpA back on
int pumpBon;          //Blynk Override to turn pumpB back on

int ROpumpOn = 0;     //Blynk Triggered RO Pump
float totalGallons;   //Number of RO Gallons Selected in Widget
BLYNK_WRITE(V9) {
  pumpAon = param.asInt();  // pumpA remote
}
BLYNK_WRITE(V10) {
  pumpBon = param.asInt();  // pumpB remote
}
BLYNK_WRITE(V11) {
  ROpumpOn = param.asInt();  // ROpump remote
}
BLYNK_WRITE(V12) {
  totalGallons = param.asFloat();  // ROpump remote
}

// Digital Pin 10 is <RESERVED> for W5100 Wiznet chip
// Digital Pins - 8 Channel Relay Assignments - 20 Series Pins - 120VAC~ switching
#define lightA 22             //Relay 1/a  
#define lightB 23             //Relay 2/b  
#define pumpA 24              //Relay 3/c 
#define pumpB 25              //Relay 4/d  
#define ROpump 26             //Relay 5/e  
#define scrubberFan 27        //Relay 6/f  
#define VentA 28              //Relay 7/g  
#define VentB 29              //Relay 8/h 

//-Digital Pins - 8 Channel Relay Assignments - 30 Series Pins - 120VAC~ switching
// -Dpins 30-37 are reserved for another bank of Relays.

//Digital Pin Valves Assignments - 40 Series Pins - Hi/Lo Solenoid Valves
//const byte valve[13] = { 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52 };

#define TURN_ON LOW // TURN_ON and TURN_OFF are defined to account for Active LOW relays
#define TURN_OFF HIGH // Used to switch relay states for on/off of 120VAC~ devices  

RTC_DS1307 RTC;
float UTCOffset = -5.0;    // Your timezone relative to UTC (http://en.wikipedia.org/wiki/UTC_offset)

WidgetLCD lcdA(V7);  //Set LCD widget to Advanced Mode - Widget to display project clock
WidgetTerminal terminal(V8);
DHT dhtA(A0, DHT22);     // DHT instance named dhtA, (I/O pin, sensor type)
DHT dhtB(A2, DHT22);     // DHT instance named dhtB, (I/O pin, sensor type)
BlynkTimer timer;       // SimpleTimer instance named timer
WidgetRTC rtcWidget;  // requires RTC widget in app

#define W5100_CS  10
#define SDCARD_CS 4

//**********************Functions***************************//
//**********************************************************//
// This is called for all virtual pins that do not have BLYNK_WRITE handler
BLYNK_WRITE_DEFAULT()
{
  Serial.println("BLYNK_WRITE_DEFAULT()");
  terminal.print("BLYNK_WRITE for pin ");
  terminal.print(request.pin);
  terminal.println(" not defined.");
  terminal.println("Values: ");
  for (auto i = param.begin(); i < param.end(); ++i) {
    terminal.print("* ");
    terminal.println(i.asString());
  }
  terminal.flush();
}

// This is called for all virtual pins that do not have BLYNK_READ handler
BLYNK_READ_DEFAULT()
{
  Serial.println("BLYNK_READ_DEFAULT");
  terminal.print("BLYNK_READ for pin ");
  terminal.print(request.pin);
  terminal.println(" not defined.");
  terminal.flush();
}

// This is called when Blynk has successfully connected
BLYNK_CONNECTED()
{
  Serial.println("BLYNK_CONNECTED");
  rtcWidget.begin();      // Synchronize with widget (server) time on connection
  setSyncInterval(5 * 60); // subsequent time sync interval in seconds (5 minutes)

  for (int i = V4; i <= V6; i++)
    for (int j = V9; j <= V21; j++)
    {
      Blynk.virtualWrite(i, j, 0);
    }
}

void myfunction() {
  Serial.println("\tLook, no Blynk  block.");
  if (Blynk.connected()) {
    Serial.println("\tEthernet still  connected.");
    Blynk.virtualWrite(V11, millis() / 1000);
  }
}

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

void displayDateTime()
{
  Serial.println("displayDateTime");
  DateTime now = RTC.now();          // reads time at beginning of loop
  byte HOUR = now.hour();
  byte twelveHour = now.hour() - 12; // Variable used to display 13+ hours in 12 hour format
  byte zeroHour = 12;                // Variable use to convert "0" zero hour to display it as 12:00+
  byte displayHour;
  byte MIN = now.minute();
  byte SEC = now.second();
  char* meridian;

  if (now.hour() == 0)  // First we test if the hour reads "0"
  {
    displayHour = zeroHour;
    meridian = "AM";
  }
  else if (now.hour() >= 13)  // if no, Second we test if the hour reads "13 or more"
  {
    displayHour = twelveHour;
    meridian = "PM";
  }
  else
  {
    displayHour = now.hour();
    meridian = "AM";
  }
  if (Blynk.connected())
  {
    char stamp[16];
    lcdA.clear();
    sprintf(stamp, "%02d:%02d:%02d-%02s", displayHour, MIN, SEC, meridian);
    lcdA.print(3, 0, stamp);
    sprintf(stamp, "%02d/%02d/%04d", now.month(), now.day(), now.year());
    lcdA.print(3, 1, stamp);
  }
}
// synchronize the RTC hardware device with our server provided date/time values
void syncRTCHardware()
{
  if (!Blynk.connected())
  {
    Serial.println("Blynk not connected. Exiting syncRTCHardware.");
    return;
  }
  Serial.println("syncRTCHardware");
  DateTime now = RTC.now();          // reads time at beginning of loop

  char currentTime[16];
  char currentDate[16];
  sprintf(currentDate, "%02d/%02d/%04d", month(), day(), year());
  sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
  Serial.print("Server Time: ");
  Serial.print(currentDate);
  Serial.print (" ");
  Serial.println(currentTime);

  // time library is synchronized by the Blynk WidgetRTC
  if (Blynk.connected())
  {
    bool syncClocks;
    if (now.hour() != hour() && now.minute() != minute()) syncClocks = true;
    if (syncClocks == true)
    {
      syncClocks = false;
      Serial.println("Resynching RTC Time...");
      terminal.println("Resynching RTC Time...");
      RTC.adjust(DateTime(year(), month(), day(), hour(), minute(), second()));
      terminal.flush();
    }
  }
}

// checks connection to Blynk server and attempts reconnect if disconnectedd checkBlynkConnection()
void checkBlynkConnection()
{
  Serial.println("Attempting to Connect");
  if (!Blynk.connected())
  {
    Serial.println("checkBlynkConnection");
    Blynk.connect();  // try to connect to server with default timeout
  }
}

void climateRoutine()
{
  byte h1 = dhtA.readHumidity();          // f1 and h1 are fahrenheit and humidity readings
  byte f1 = dhtA.readTemperature(true);   // from DHT/A
  byte h2 = dhtB.readHumidity();          // f2 and h2 are fahrenheit and humidity readings
  byte f2 = dhtB.readTemperature(true);   // from DHT/B
  if (isnan(f1) || isnan(f2) || isnan(h1) || isnan(h2)) {
    terminal.println("Failed to read from a DHT sensor");
    terminal.flush();
    return;
  }
  Blynk.virtualWrite(V0, f1);      //  Set Virtual Pin 0 frequency to PUSH in Blynk app
  Blynk.virtualWrite(V1, h1);      //  Set Virtual Pin 1 frequency to PUSH in Blynk app
  Blynk.virtualWrite(V2, f2);      //  Set Virtual Pin 2 frequency to PUSH in Blynk app
  Blynk.virtualWrite(V3, h2);      //  Set Virtual Pin 3 frequency to PUSH in Blynk app
  //-------------------Bloom A Temp Test---------------------------------------//
  if (f1 >= hiMaxTemp)  //if "f1" is greater than or equal to hiMaxTemp,
  {
    digitalWrite(VentA, TURN_ON);  // TURN_ON heatVentA (fan).
    terminal.println("Exhausting the heat from Bloom A"); //  Text printed to terminal monitor
  }
  else if (f1 <= lowMaxTemp)  //  or else if "f1" is less than or equal to lowMaxTemp
  {
    digitalWrite(VentA, TURN_OFF); //  TURN_OFF relay E.
  }
  //-----------------------Bloom A Humidity Test-------------------------//
  if (h1 >= hiHum)  //if "h2" is greater than or equal to hiHum,
  {
    digitalWrite(VentA, TURN_ON);  // TURN_ON heatVentA (fan).
    terminal.println("Exhausting the RH from Bloom A"); //  Text printed to terminal monitor
  }
  else if (h1 <= lowHum)  //  or else if "h1" is less than or equal to lowHum
  {
    digitalWrite(VentA, TURN_OFF);
  }
  //-----------------------Bloom B Temp Test-----------------------------//
  if (f2 >= hiMaxTemp)  //if "f2" is greater than or equal to hiMaxTemp,
  {
    digitalWrite(VentB, TURN_ON);  // TURN_ON heatVentA (fan).
    terminal.println("Exhausting the heat from Bloom B"); //  Text printed to terminal monitor
  }
  else if (f2 <= lowMaxTemp)  //  or else if "f2" is less than or equal to lowMaxTemp
  {
    digitalWrite(VentB, TURN_OFF);
  }
  //-----------------------Bloom B Humidity Test-------------------------//
  if (h2 >= hiHum)  //if "h2" is greater than or equal to hiHum,
  {
    digitalWrite(scrubberFan, TURN_ON);  // TURN_ON heatVentA (fan).
    terminal.println("Exhausting the RH from Bloom B"); //  Text printed to terminal monitor
  }
  else if (h2 <= lowHum)  //  or else if "h2" is less than or equal to lowHum
  {
    digitalWrite(scrubberFan, TURN_OFF);
  }
  terminal.flush();
}

void timeRoutine()
{
  DateTime now = RTC.now();          // reads time at beginning of loop

  //------------------12/12 BloomA Light - 5AM-5PM
  //Adjust hours and minutes in accordance with 24 hour time format.
  //Create tests where true is ON time and false is OFF time.
  boolean lightAstate = false;
  if (now.hour() >= 5 && now.hour() <= 16) lightAstate = true;
  if (lightAstate == true)
  {
    digitalWrite(lightA, TURN_ON);
    terminal.println("Lights On In Bloom A");  //  Text printed to terminal monitor
  }
  else
  {
    digitalWrite(lightA, TURN_OFF);
  }
  //--------------------12/12 Bloom B Light - 5PM-5AM
  //lightB is lit during the opposing 12 hours to lightA to conserve current draw from HID ballasts.
  boolean lightBstate = false;
  if (lightAstate == false) lightBstate = true;
  if (lightBstate == true)
  {
    digitalWrite(lightB, TURN_ON);
    terminal.println("Lights On In Bloom B");  //  Text printed to terminal monitor
  }
  else
  {
    digitalWrite(lightB, TURN_OFF);
  }
  //---------------Bloom A Feed Times------------------------
  boolean pumpAstate = false;
  if (pumpAon == 1) pumpAstate = true;
  if (now.hour() == 6 && now.minute() >= 0 && now.minute() < 10) pumpAstate = true;    //6:00 am - 10 mins
  if (now.hour() == 8 && now.minute() >= 30 && now.minute() < 40) pumpAstate = true;  //8:30 am - 10 mins
  if (now.hour() == 11 && now.minute() >= 00 && now.minute() < 10) pumpAstate = true;  //11:00 am - 10 mins
  if (now.hour() == 13 && now.minute() >= 30 && now.minute() < 40) pumpAstate = true;  //1:30 pm - 10 mins
  if (now.hour() == 16 && now.minute() >= 0 && now.minute() < 10) pumpAstate = true;  //4:00 pm - 10 mins
  if (pumpAstate == true)
  {
    Blynk.virtualWrite(V9, 1);
    digitalWrite(pumpA, TURN_ON);
    terminal.println("Pump A Is On");  //  Text printed to terminal monitor
  }
  else
  {
    pumpAon = 0;
    Blynk.virtualWrite(V9, 0);
    digitalWrite(pumpA, TURN_OFF);
  }
  //---------------------------Bloom B Feed Times-------------------------------------
  boolean pumpBstate = false;
  if (pumpBon == 1) pumpBstate = true;
  if (now.hour() == 18 && now.minute() >= 0 && now.minute() < 10) pumpBstate = true;     //6:00 pm - 10 mins -//- 1 hour after light on
  if (now.hour() == 20 && now.minute() >= 30 && now.minute() < 40) pumpBstate = true;   //8:30 pm - 10 mins
  if (now.hour() == 23 && now.minute() >= 0 && now.minute() < 10) pumpBstate = true;     //11:00 pm - 10 mins
  if (now.hour() == 1 && now.minute() >= 30 && now.minute() < 40) pumpBstate = true;    //1:30 am - 10 mins
  if (now.hour() == 4 && now.minute() >= 0 && now.minute() < 10) pumpBstate = true;     //4:00 am - 10 mins
  if (pumpBstate == true)
  {
    Blynk.virtualWrite(V10, 1);
    digitalWrite(pumpB, TURN_ON);
    terminal.println("Pump B Is On");  //  Text printed to terminal monitor
  }
  else
  {
    pumpBon = 0;
    Blynk.virtualWrite(V10, 0);
    digitalWrite(pumpB, TURN_OFF);
  }
  terminal.flush();
}

void ROcheck()  //RO Pump = 34 seconds on time per gallon
{
  if (ROpumpOn == 1 && runningRO == false)            // Activates when Blynk button is toggled
  {
    digitalWrite(ROpump, TURN_ON);
    Blynk.virtualWrite(V11, 255);                     // Illuminates Blynk button widget
    runningRO = true;
    ROstart = millis();
    countGallons = msPerGallon * totalGallons;        // Calculates length of runtime for pump
    Blynk.virtualWrite(V12, 0);
    terminal.print("Pumping:");
    terminal.print(totalGallons);
    terminal.println(" Gallons of RO");
  }
  if (millis() - ROstart > countGallons)              // Determines when runtime ends
  {
    ROpumpOn = 0;
    runningRO = false;
    digitalWrite(ROpump, TURN_OFF);
    Blynk.virtualWrite(V11, 0);
    //Blynk.virtualWrite(V22, 0);
  }
  terminal.flush();
}

void dosingPumps()
{
  if (button == 1 && pumpRunning == false)
  {
    multiplier[x] = calibration;                      // Gets the value in [x] position from Blynk
    Blynk.virtualWrite(V4, 0);
    Blynk.virtualWrite(V5, 0);
    Blynk.virtualWrite(V6, 0);                        // Keeps button ON until fully executed
    pumpRunning = true;
    digitalWrite(pumpPin[x], HIGH);
    Blynk.virtualWrite(dosingLEDs[x], 255);           // [x] position Blynk indicator LED
    startPump = millis();
    runCount = DOSEml * multiplier[x];
    terminal.print("Dosing in: ");
    terminal.print(DOSEml);
    terminal.print(" milliliters of ");
    terminal.println(nuteType[x]);
  }
  if (millis() - startPump > runCount)
  {
    digitalWrite(pumpPin[x], LOW);
    Blynk.virtualWrite(dosingLEDs[x], 0);
    pumpRunning = false;
    button = 0;
  }
  terminal.flush();
}

void setup()
{
  Serial.begin(9600);
  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);
  }
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  
  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

  Serial.println("beginning Blynk...");
  // Blynk stuff after timers
  //Blynk.config(auth, server, port);
  Blynk.begin(auth, server, port);
  while (Blynk.connect() == false)
  {
    Blynk.connect();
    if (millis() > startConnecting + myEthernetTimeout) {
      Serial.print("\tUnable to connect to server. ");
      break;
    }
    //Blynk.disconnect(); // skip connecting to the Blynk server until checkBlynkConnection timer fires

    Serial.println("setup complete.");
  }
}
  void loop()
  {
    // only attempt Blynk-related functions when connected to Blynk
    if (Blynk.connected())
    {
      Blynk.run();
    }
    timer.run();
  }

No, I was just thinking that would be a reason for the project not to update the physical RTC when you change Blynk’s RTC TZ. Maybe I didn’t leave it long enough and perhaps I’ll try changing the TZ again to see what happens.

1 Like

Are you trying to (momentarily) change the project time zone to see if populates my RTC with your local time? Do you think line 101 in my sketch is influencing that?

Edit - sorry, no lin numbers, this;

float UTCOffset = -5.0;    // Your timezone relative to UTC (http://en.wikipedia.org

Yes I remember setting that to +3 last night. Just “moved” to Poland at +2 in the project and I was going to say there was no change but when I look at the LCD it now states 1:58 rather than true local time of 2:58 so it looks fine. Not checked your timers to see how long it takes for the update, thought it would be the 15s sync I saw earlier but you must have a second timer somewhere.

OK you have a 5 minute RTC sync. I “moved” to Addis Ababa in Africa at 14:00:28 Polish time and at 15:02:28 local African time the LCD updated. So with the 5 minute sync it will update anytime in the next 5 minutes depending where in the sync cycle you are. This is fine.

No, that is actually dead code. If you search for UTCOffset you will see it’s not used anywhere in the sketch. Again this is fine because you are using the power of Blynk’s RTC TZ’s.

If memory serves me, I think the UTC line is used by the RTClib library, but seeing as how my app requested my timezone to build the app (or widget), I see this line is moot.

FYI, my time is displaying current to my EST region

Would I be right in thinking you use a UPS with your system for the welfare of your crop?

What’s a UPS?

It’s magic Energy not a parcel carrier, Uninterruptible Power Supply.

Not yet, but I’ll look into it unless a wall wart fits the description. But I think you’re hinting at some form of emergency backup power supply, albeit batteries or a generator. At the moment, no, but as the project expands (and we plan to grow it outward and migrate it over to rPi with remote Pi Zero W’s) and to include nutrient/water recipes for every known supplier of nutrients. Functionality will expand and so too will the code. My experience is strictly with Arduino, but the guy that’s helping me is well versed in them all and is leading me in the direction of Widows 10 IoT on the Pi. Irregardless of where this goes, we intend to keep Blynk right in the thick of it for reasons I’m sure you can quickly guess.