Quantity of Data

Hi
I’m experiencing dropouts with my device and the Blynk server, and am wondering if the quantity of sends in the following code is the problem. I’m reading a BME280 and sending it to three different widgets (LCD, Terminal, and Table). I’m using Timers for various grouping, but all this happens inside one timer. Would it be more appropriate to group the three Widgets into their own timer function?

// Write current data to Terminal Widget //////
      terminal.print(tempData);
      terminal.print("*C\t\t\t");
      terminal.print(pressureData);
      terminal.print("hPa\t\t\t");
      terminal.print(humidityData);
      terminal.print("%RH\t\t\t");
      terminal.println(digitalRead(doorPin));
      terminal.flush();

// Write current data to LCD Widget ////////
      lcd.print(0, 1, "T="); 
      lcd.print(2, 1, round(tempData));
      lcd.print(4, 1, " "); // clear any characters in this location
      lcd.print(5, 1, "P=");
      lcd.print(7, 1, round(pressureData));
      lcd.print(11, 1, " "); // clear any characters in this location
      lcd.print(12, 1, "H=");
      lcd.print(14, 1, round(humidityData));
      if (bme.readHumidity() >= 100.0) setup(); // reset if sensor error

// Write current data to Table Widget /////////////
      Blynk.virtualWrite(V20, "update", 0, "Temperature (\u00B0C)", tempData);
      Blynk.virtualWrite(V20, "update", 1, "Pressure (hPa)", pressureData);
      Blynk.virtualWrite(V20, "update", 2, "Humidity (%RH)", humidityData);
// Read WiFi Signal Strength  and send to Table ////////////
      Blynk.virtualWrite(V20, "update", 4, "WiFi Signal Strength", map(WiFi.RSSI(), -105, -40, 0, 100) + String('%'));

```cpp

It’s easier if you post the full code.

Pete.

Ok here it is without the defines etc (only functions)

/////////////////////////////////////////////
void buttonLedWidget()
{
  // Read button
  boolean isPressed = (digitalRead(btnPin) == LOW);

  // If state has changed...
  if (isPressed != btnState) {
    if (isPressed) {
      led3.off();
    } else {
      led3.on();
    }
    btnState = isPressed;
  }
}


///////////////////////////////////////////////////
void readSensorWidget() {
      tempData = bme.readTemperature();
      delay (20); // add delay between sensor reads - may reduce instability
      pressureData = (bme.readPressure()/100);
      delay (20);
      humidityData = bme.readHumidity();
      if (tempData < 100 && tempData > -100) Blynk.virtualWrite(V10, tempData); // push data to Super Chart
      if (pressureData < 1100 && pressureData > 950) Blynk.virtualWrite(V11, pressureData); // push data to Super Chart
      if (humidityData < 100 && humidityData > 0) Blynk.virtualWrite(V12, humidityData); // push data to Super Chart
      Blynk.virtualWrite(V13, digitalRead(doorPin)); // push data to Super Chart

      Serial.print(tempData,1);
      Serial.print("\t");
      Serial.print(pressureData,1);
      Serial.print("\t");
      Serial.print(humidityData,1);
      Serial.print("\t");
      Serial.println(digitalRead(doorPin));
      
// Write current data to Terminal Widget //////
      terminal.print(tempData);
      terminal.print("*C\t\t\t");
      terminal.print(pressureData);
      terminal.print("hPa\t\t\t");
      terminal.print(humidityData);
      terminal.print("%RH\t\t\t");
      terminal.println(digitalRead(doorPin));
      terminal.flush();

// Write current data to LCD Widget ////////
      lcd.print(0, 1, "T="); 
      lcd.print(2, 1, round(tempData));
      lcd.print(4, 1, " "); // clear any characters in this location
      lcd.print(5, 1, "P=");
      lcd.print(7, 1, round(pressureData));
      lcd.print(11, 1, " "); // clear any characters in this location
      lcd.print(12, 1, "H=");
      lcd.print(14, 1, round(humidityData));
      if (bme.readHumidity() >= 100.0) setup(); // reset if sensor error

// Write current data to Table Widget /////////////
      Blynk.virtualWrite(V20, "update", 0, "Temperature (\u00B0C)", tempData);
      Blynk.virtualWrite(V20, "update", 1, "Pressure (hPa)", pressureData);
      Blynk.virtualWrite(V20, "update", 2, "Humidity (%RH)", humidityData);
// Read WiFi Signal Strength  and send to Table ////////////
      Blynk.virtualWrite(V20, "update", 4, "WiFi Signal Strength", map(WiFi.RSSI(), -105, -40, 0, 100) + String('%'));
}

///////////////////////////////////////////////////
// V6 Door Widget represents the physical door state
void doorStateWidget()
{
doorState = digitalRead(doorPin);
  if(doorState == HIGH)  {
    lcd.print(0, 0, "Door: Open  ");
    led6.setColor(BLYNK_RED);
    led7.setColor(BLYNK_RED);
    Blynk.virtualWrite(V13, doorState);
    Blynk.virtualWrite(V20, "update", 3, "Roller Door",  "Open");

  }
  else {
    lcd.print(0, 0, "Door: Closed");
    led6.setColor(BLYNK_GREEN);
    led7.setColor(BLYNK_GREEN);
    Blynk.virtualWrite(V13, doorState);
    Blynk.virtualWrite(V20, "update", 3, "Roller Door",  "Closed");
    }
} 

/////////////////////////////////////////////////
BLYNK_WRITE(V0) {
    digitalWrite(btnPin, param.asInt());
    if(param.asInt() == HIGH && doorState == HIGH) {
      while(param.asInt() == HIGH && digitalRead(doorPin) == HIGH) {
        lcd.print(0, 1, "Door closing    "); // keep this text on the display while door is moving
        led6.setColor(BLYNK_YELLOW); // display transitional colour
        led7.setColor(BLYNK_YELLOW); // display transitional colour
      }   
    }
    else {
      lcd.print(0, 0, "Door: Closed ");
      lcd.print(0, 1, "                ");  // clear line
    }
}


//////////////////////////////////////////////////////
// Open Door button on V4
BLYNK_WRITE(V4) { 
  prevMillis1 = millis(); // capture time of button press
  if(param.asInt() == HIGH && doorState == LOW) {  // run only when door is open
    doorTimerArray[count] = millis(); // save button press time to array
    count += 1;
    Serial.print("Count = ");
    Serial.println(count);
  }
  if (count <= 3) {
      if (count != 0) { 
        lcd.print(0, 1, "Access Denied!  ");
        delay(100);
      }
      else lcd.print(0,1,"               "); // clear line on LCD
  }
    else {
    Serial.println(doorTimerArray[3] - doorTimerArray[0]);
    if(doorTimerArray[3] - doorTimerArray[0] < 3000){ // must all happen within 3 seconds
      digitalWrite(relayPin, HIGH); // activate door control
      led5.on();
      lcd.print(0,1,"Open Sesame...  ");

      delay(500);
      digitalWrite(relayPin, LOW); // deactivate door control
      delay(1000);
      led5.off();
    }    
    count = 0;  // reset counter 
  }
}

//////////////////////////////////////////////
void setup()
{
  // Debug console
  Serial.begin(9600);
  bme.begin(0x76);
  Blynk.begin(auth, ssid, pass);

  // Setup physical relay pin (active low)
  pinMode(relayPin, OUTPUT);
  pinMode(relayPin, INPUT_PULLUP);
  pinMode(btnPin, OUTPUT);
  pinMode(doorPin, INPUT_PULLUP);
  digitalWrite(doorPin, LOW);


  timer1.setInterval(5000L, readSensorWidget);
  timer2.setInterval(100L, buttonLedWidget);
  timer3.setInterval(1000L, doorStateWidget);
 

// Add rows to Table Widget ////////
  Blynk.virtualWrite(V20, "add", 0, "Temperature", "Updating");
  Blynk.virtualWrite(V20, "add", 1, "Pressure", "Updating");
  Blynk.virtualWrite(V20, "add", 2, "Humidity", "Updating");
// or use this //////////
  table.addRow(3, "Roller Door", "Updating");
  table.addRow(4, "WiFi Signal Strength", "Updating");

//// Set up initial read because future reads only occur when the door changes state
//  if (digitalRead (doorPin) == LOW) {
//    Blynk.virtualWrite(V20, "update", 3, "Roller Door",  "Closed");
//    lcd.print(0, 0, "Door: Closed");
//  }
//  if (digitalRead (doorPin) == HIGH) {
//    Blynk.virtualWrite(V20, "update", 3, "Roller Door",  "Open");
//    lcd.print(0, 0, "Door: Open  ");
//  }

//  lcd.clear(); //Use it to clear the LCD Widget
}

////////////////////////////////////////////
void loop()
{
  Blynk.run();
  timer1.run(); // read BME Sensor
  timer2.run(); // monitor button state
  timer3.run(); // monitor door state

if(count != 0) {  // only run if count is not zero
  if (millis() - prevMillis1 > 5000) {
    count = 0; // reset count to zero if time exceeds 15 sec
    lcd.print(0, 1, "            "); // erase bottom line on LCD screen
    }
  }
  
   // Testing for wifi and reconnecting if not connected
  if (WiFi.status() != WL_CONNECTED) 
  {
    Serial.println ();
    Serial.println ("Reconnecting ...");
    setup();
    Serial.println(WiFi.localIP());
  }

}

And it will look better, showing all those defines etc. that we may need to see as well, with triple backticks, not commas :stuck_out_tongue:

Blynk - FTFC

duh, sorry about the commas

In all it’s glory…

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  Blynk Garage Monitor

 *************************************************************/

#include "Adafruit_BME280.h" //https://github.com/Takatsuki0204/BME280-I2C-ESP32
#include <Wire.h>
#define I2C_SDA 32
#define I2C_SCL 33
#define BME280_ADDRESS 0x76  //If the sensor does not work, try the 0x77 address as well

Adafruit_BME280 bme(I2C_SDA, I2C_SCL);

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.
char auth[] = "xxx";

// Your WiFi credentials.
char ssid[] = "xxx";
char pass[] = "xxx";


/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_GREEN     "#23C48E"
#define BLYNK_BLUE      "#04C0F8"
#define BLYNK_YELLOW    "#ED9D00"
#define BLYNK_RED       "#D3435C"
#define BLYNK_DARK_BLUE "#5F7CD8"

const int btnPin = 2; // Onboard LED to activate when Open button on app is pressed
const int button = V0; // door Open button in app
int doorPin = 23; // input from reed relay door sensor
int count = 0; // used to count Door Open button presses
unsigned long prevMillis1;
//unsigned long millis4;
boolean doorState; // either open or closed
boolean prevdoorState; // used to track a state change
boolean relayPin = 20; // output to door activation relay
float tempData; // BME data
float pressureData; // BME data
float humidityData; // BME data

unsigned long doorTimerArray[4]; // holds millis for each button press

WidgetLCD lcd(V1); // 2x16 LCD display
WidgetLED led3(V3); // BUTTON
WidgetLED led5(V5); // DOOR Opening
WidgetLED led6(V6); // DOOR State
WidgetLED led7(V7); // DOOR State
WidgetTerminal terminal(V8);
WidgetTable table;
BLYNK_ATTACH_WIDGET(table, V20);

BlynkTimer timer1; // sent Terminal data
BlynkTimer timer2; // monitor button state
BlynkTimer timer3; // monitor door state
BlynkTimer timer4; // read BME Temperature
BlynkTimer timer5; // read BME Pressure
BlynkTimer timer6; // read BME Humidity

// V3 LED Widget represents the physical button state
boolean btnState = false;

/////////////////////////////////////////////
void buttonLedWidget()
{
  // Read button
  boolean isPressed = (digitalRead(btnPin) == LOW);

  // If state has changed...
  if (isPressed != btnState) {
    if (isPressed) {
      led3.off();
    } else {
      led3.on();
    }
    btnState = isPressed;
  }
}


///////////////////////////////////////////////////
void readSensorWidget() {
      tempData = bme.readTemperature();
      delay (20); // add delay between sensor reads - may reduce instability
      pressureData = (bme.readPressure()/100);
      delay (20);
      humidityData = bme.readHumidity();
      if (tempData < 100 && tempData > -100) Blynk.virtualWrite(V10, tempData); // push data to Super Chart
      if (pressureData < 1100 && pressureData > 950) Blynk.virtualWrite(V11, pressureData); // push data to Super Chart
      if (humidityData < 100 && humidityData > 0) Blynk.virtualWrite(V12, humidityData); // push data to Super Chart
      Blynk.virtualWrite(V13, digitalRead(doorPin)); // push data to Super Chart

      Serial.print(tempData,1);
      Serial.print("\t");
      Serial.print(pressureData,1);
      Serial.print("\t");
      Serial.print(humidityData,1);
      Serial.print("\t");
      Serial.println(digitalRead(doorPin));
      
// Write current data to Terminal Widget //////
      terminal.print(tempData);
      terminal.print("*C\t\t\t");
      terminal.print(pressureData);
      terminal.print("hPa\t\t\t");
      terminal.print(humidityData);
      terminal.print("%RH\t\t\t");
      terminal.println(digitalRead(doorPin));
      terminal.flush();

// Write current data to LCD Widget ////////
      lcd.print(0, 1, "T="); 
      lcd.print(2, 1, round(tempData));
      lcd.print(4, 1, " "); // clear any characters in this location
      lcd.print(5, 1, "P=");
      lcd.print(7, 1, round(pressureData));
      lcd.print(11, 1, " "); // clear any characters in this location
      lcd.print(12, 1, "H=");
      lcd.print(14, 1, round(humidityData));
      if (bme.readHumidity() >= 100.0) setup(); // reset if sensor error

// Write current data to Table Widget /////////////
      Blynk.virtualWrite(V20, "update", 0, "Temperature (\u00B0C)", tempData);
      Blynk.virtualWrite(V20, "update", 1, "Pressure (hPa)", pressureData);
      Blynk.virtualWrite(V20, "update", 2, "Humidity (%RH)", humidityData);
// Read WiFi Signal Strength  and send to Table ////////////
      Blynk.virtualWrite(V20, "update", 4, "WiFi Signal Strength", map(WiFi.RSSI(), -105, -40, 0, 100) + String('%'));
}

///////////////////////////////////////////////////
// V6 Door Widget represents the physical door state
void doorStateWidget()
{
doorState = digitalRead(doorPin);
  if(doorState == HIGH)  {
    lcd.print(0, 0, "Door: Open  ");
    led6.setColor(BLYNK_RED);
    led7.setColor(BLYNK_RED);
    Blynk.virtualWrite(V13, doorState);
    Blynk.virtualWrite(V20, "update", 3, "Roller Door",  "Open");

  }
  else {
    lcd.print(0, 0, "Door: Closed");
    led6.setColor(BLYNK_GREEN);
    led7.setColor(BLYNK_GREEN);
    Blynk.virtualWrite(V13, doorState);
    Blynk.virtualWrite(V20, "update", 3, "Roller Door",  "Closed");
    }
} 

/////////////////////////////////////////////////
BLYNK_WRITE(V0) {
    digitalWrite(btnPin, param.asInt());
    if(param.asInt() == HIGH && doorState == HIGH) {
      while(param.asInt() == HIGH && digitalRead(doorPin) == HIGH) {
        lcd.print(0, 1, "Door closing    "); // keep this text on the display while door is moving
        led6.setColor(BLYNK_YELLOW); // display transitional colour
        led7.setColor(BLYNK_YELLOW); // display transitional colour
      }   
    }
    else {
      lcd.print(0, 0, "Door: Closed ");
      lcd.print(0, 1, "                ");  // clear line
    }
}


//////////////////////////////////////////////////////
// Open Door button on V4
BLYNK_WRITE(V4) { 
  prevMillis1 = millis(); // capture time of button press
  if(param.asInt() == HIGH && doorState == LOW) {  // run only when door is open
    doorTimerArray[count] = millis(); // save button press time to array
    count += 1;
    Serial.print("Count = ");
    Serial.println(count);
  }
  if (count <= 3) {
      if (count != 0) { 
        lcd.print(0, 1, "Access Denied!  ");
        delay(100);
      }
      else lcd.print(0,1,"               "); // clear line on LCD
  }
    else {
    Serial.println(doorTimerArray[3] - doorTimerArray[0]);
    if(doorTimerArray[3] - doorTimerArray[0] < 3000){ // must all happen within 3 seconds
      digitalWrite(relayPin, HIGH); // activate door control
      led5.on();
      lcd.print(0,1,"Open Sesame...  ");

      delay(500);
      digitalWrite(relayPin, LOW); // deactivate door control
      delay(1000);
      led5.off();
    }    
    count = 0;  // reset counter 
  }
}

//////////////////////////////////////////////
void setup()
{
  // Debug console
  Serial.begin(9600);
  bme.begin(0x76);
  Blynk.begin(auth, ssid, pass);

  // Setup physical relay pin (active low)
  pinMode(relayPin, OUTPUT);
  pinMode(relayPin, INPUT_PULLUP);
  pinMode(btnPin, OUTPUT);
  pinMode(doorPin, INPUT_PULLUP);
  digitalWrite(doorPin, LOW);


  timer1.setInterval(5013L, readSensorWidget);
  timer2.setInterval(989L, buttonLedWidget);
  timer3.setInterval(1011L, doorStateWidget);

// Add rows to Table Widget ////////
  Blynk.virtualWrite(V20, "add", 0, "Temperature", "Updating");
  Blynk.virtualWrite(V20, "add", 1, "Pressure", "Updating");
  Blynk.virtualWrite(V20, "add", 2, "Humidity", "Updating");
// or use this //////////
  table.addRow(3, "Roller Door", "Updating");
  table.addRow(4, "WiFi Signal Strength", "Updating");

//// Set up initial read because future reads only occur when the door changes state
//  if (digitalRead (doorPin) == LOW) {
//    Blynk.virtualWrite(V20, "update", 3, "Roller Door",  "Closed");
//    lcd.print(0, 0, "Door: Closed");
//  }
//  if (digitalRead (doorPin) == HIGH) {
//    Blynk.virtualWrite(V20, "update", 3, "Roller Door",  "Open");
//    lcd.print(0, 0, "Door: Open  ");
//  }

//  lcd.clear(); //Use it to clear the LCD Widget
}

////////////////////////////////////////////
void loop()
{
  Blynk.run();
  timer1.run(); // read BME Sensor
  timer2.run(); // monitor button state
  timer3.run(); // monitor door state

if(count != 0) {  // only run if count is not zero
  if (millis() - prevMillis1 > 5000) {
    count = 0; // reset count to zero if time exceeds 15 sec
    lcd.print(0, 1, "            "); // erase bottom line on LCD screen
    }
  }
  
   // Testing for wifi and reconnecting if not connected
  if (WiFi.status() != WL_CONNECTED) 
  {
    Serial.println ();
    Serial.println ("Reconnecting ...");
    setup();
    Serial.println(WiFi.localIP());
  }

}


NOW it is all in its glory with proper formatting :stuck_out_tongue_winking_eye: … I also edited your past posts… You should be able to do that as well in the future?

What did you do that I didn’t?

Used the proper character… Google Backtick character. Also needs the cpp in the leading group AKA ```cpp to help account for some C++ formatting.

As for your issue… you may be blasting too much at a time and possibly causing enough delay to trigger the heartbeat disconnect.

BTW, a single timer can handle 16 separate instances… unsure if all those extra named timers affect anything or not.

I was using the apostrophe symbol !!
I also thought the cpp was part of the example, not required entry.

Ya live and learn. I’ll do better next time :sunglasses:

I’m running a vastly stripped down version of the code now, which has almost no data upload commands, so will watch performance and add code back in progressively.

To use the same timer in multiple instances, do you simply call the same timer or do you have to denote it as a different instance?

Much appreciate your help

You can just create a single timer

BlynkTimer timer;

And keep calling up to 16 times, but each timer will be separate “process” from the others

You can even add names to them if you require the ability to enable/disable them, etc.

  // ===== Timer Setup =====
  PingTimer = timer.setInterval(510L, PingSensor);  // Ping distance routine - switched
  timer.disable(PingTimer);  // Disable timer until needed

  PIRTimer = timer.setInterval(530L, PIRSensor);  // PIR motion routine - switched
  timer.disable(PIRTimer);  // Disable timer until needed

  timer.setInterval(500L, CNTRDisplay);  // Update Loop counter Widget
  timer.setInterval(1000L, timeDisplay);  // Update Time Widget
  timer.setInterval(1750L, AnalogSensors);  // Misc analog sensors on CodeShield
  timer.setInterval(2040L, whiteLED);  // White LED button monitor on CodeShield
  timer.setInterval(4050L, SuperCapVoltage);  // Super Cap charge display
  timer.setInterval(30060L, DHTSensor);  // DHT22 sensor
  timer.setInterval(30900L, thermTemp);  // Thermistor  on CodeShield
  timer.setInterval(60040L, sendUptime);  // Up Time Widget
  timer.setInterval(400090L, dateDisplay);  // Update Date Widget

Then if you need more than 16, you can create another timer and carry on…

BlynkTimer timer2;

Try to make sure that whatever function a timer calls will be completed before the timer called it again… and as you have done, stagger them so that no two or more functions are getting called at the same time if at all possible… once in a blue moon is OK.

Perfect, thanks very much.