App not updating while in background

I am making a Raspberry Pi weather station that uploads its data using Blynk. I recently discovered that the weather station is only uploading data to the Blank app when the app is running. Shortly after I close the app (hit the home button), the weather station stops uploading data. This leads to my Supercharts missing large chunks of data. I also have a lightning detector set up to send notifications with a time stamp when it detects a lightning strike; however, I only receive the notification when I open the app and the time stamp isn’t when the strike occurred but rather when I opened the app. I am using the python Blynk library. I am also using the latest iOS app. I would greatly appreciate any help as I am new to coding and Blynk. Here is my code for the Raspberry Pi.

import BlynkLib_Outdoor
import time
import Adafruit_TCS34725
from Adafruit_BME280 import *
from RPi_AS3935 import RPi_AS3935
import SI1145.SI1145 as SI1145
import RPi.GPIO as GPIO
from datetime import datetime
import smbus

BLYNK_AUTH = 'This is where my token normally is'

# Initialize Blynk
blynk = BlynkLib_Outdoor.Blynk(BLYNK_AUTH)

# Initialize Lightning detector
as3935 = RPi_AS3935(address=0x03, bus=1)
as3935LastInterrupt = 0
as3935LightningCount = 0
as3935LastDistance = 0
as3935LastStatus = ""
as3935Interrupt = False

def process_as3935_interrupt():

    global as3935Interrupt
    global as3935, as3935LastInterrupt, as3935LastDistance, as3935LastStatus

    as3935Interrupt = False

    reason = as3935.get_interrupt()


    as3935LastInterrupt = reason

    if reason == 0x00:
        now ='%H:%M:%S - %m/%d')
        as3935LastStatus = "Spurious Interrupt %s" % now
    elif reason == 0x01:
        now ='%H:%M:%S - %m/%d')
        as3935LastStatus = "Noise Floor too low - adjusting (%s)" % now
    elif reason == 0x04:
        now ='%H:%M:%S - %m/%d')
        as3935LastStatus = "Disturber detected - masking (%s)" % now
    elif reason == 0x08:
        now ='%H:%M:%S - %m/%d')
        distance = as3935.get_distance()
        as3935LastDistance = distance
        as3935LastStatus = "Lightning Detected " + str(distance) + "km away. (%s)" % now

    blynk.virtual_write(6, as3935LastStatus)

def handle_as3935_interrupt(channel):
    global as3935Interrupt

    blynk.virtual_write(6, "as3935 Interrupt")

    as3935Interrupt = True

as3935pin = 17

GPIO.setup(as3935pin, GPIO.IN)
GPIO.add_event_detect(as3935pin, GPIO.RISING, callback=handle_as3935_interrupt)

# Other sensors 

def v1_read_handler():
    sensor_1 = BME280(t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, h_mode=BME280_OSAMPLE_8)
    degrees = sensor_1.read_temperature_f()
    blynk.virtual_write(1, '{0:0.1f}'.format(degrees))

def v2_read_handler():
    sensor_2 = BME280(t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, h_mode=BME280_OSAMPLE_8)
    # atm = sensor.read_pressure_atm()
    pascals = sensor_2.read_pressure()
    hectopascals = pascals / 100
    blynk.virtual_write(2, '{0:0.0f}'.format(hectopascals))

def v3_read_handler():
    sensor_3 = BME280(t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, h_mode=BME280_OSAMPLE_8)
    humidity = sensor_3.read_humidity()
    blynk.virtual_write(3, '{0:0.1f}'.format(humidity))

def v4_read_handler():
    tcs = Adafruit_TCS34725.TCS34725(integration_time=Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_154MS,
    r, g, b, c = tcs.get_raw_data()
    lux = Adafruit_TCS34725.calculate_lux(r, g, b)
    blynk.virtual_write(4, lux)

def v5_read_handler():
    sensor_4 = SI1145.SI1145()
    vis = sensor_4.readVisible()
    IR = sensor_4.readIR()
    uv = sensor_4.readUV()
    uvindex = uv / 100.0
    blynk.virtual_write(5, uvindex)

def v6_read_handler():
    if as3935Interrupt == True:

# Start Blynk

Do you use Blynk Cloud?


In that case this is expected. VIRTUAL_READ handlers are triggered only when the app is active. You may change this with the local server with option. Otherwise, you need to use some kind of timer within your code that will trigger VIRTUAL_READ.

At some point we will also enable this on the server side on the Blynk Cloud.

Thank you so much for helping me out. This was really bugging me. So how could I use a timer to trigger the VIRTUAL_READ handler?