Blynk python - stops sending data through web socket

edit: I’m using a local Blynk server

I’m having a really simple script running in a background by root.
It reads the DHT sensors values from the GPIO pins and writes them to the appropriate virtual pins on my local web server.
These values are used by different devices in the network (Wemos D1 with G135 gas sensor). Since I don’t think the library comes with bridge implementation, i simply make the script to write the values to the Wemos virtual pins using blynk API.

#!/usr/bin/python
import Adafruit_DHT
import blynklib
import blynktimer
from blynkapi import *
from time import sleep

# correction offset
hoffset = 1
toffset = 1

# style vars
T_COLOR = '#f5b041'
H_COLOR = '#85c1e9'
P_COLOR = '#a2d9ce'
A_COLOR = '#58d68d'
ERR_COLOR = '#444444'

# blynk initialize
auth_token='fooo'
auth_mq135='baar'

# initialize the Wemos device using blynkapi lib 
mq135_temp = Blynk(auth_mq135, pin='V3', server='localhost', port='8081')
mq135_humi = Blynk(auth_mq135, pin='V4', server='localhost', port='8081')


blynk = blynklib.Blynk(auth_token, heartbeat=15, server='localhost', port='8081')
timer = blynktimer.Timer()

@timer.register(interval=60, run_once=False)
@blynk.handle_event('read V3')
def read_handler():
  # read sensor vals multiple times, apply the correction offsets and use the median of the readings
  hs = []
  ts = []
  for _ in range(6):
    h, t = Adafruit_DHT.read_retry(11, 4)
    print('{0}, {1}'.format(t, h))
    hs.append(h)
    ts.append(t)
  hs.sort()
  ts.sort()
  h = hs[len(hs)/2-1] + hoffset
  t = ts[len(ts)/2-1] + toffset
  hs = []
  ts = []
  if all([t, h]):
    print('median: (+offset) {0}, {1}'.format(t, h))
    blynk.set_property(3, 'color', T_COLOR)
    blynk.set_property(4, 'color', H_COLOR)

    blynk.virtual_write(3, t)
    blynk.virtual_write(4, h)

    # vw to mq135 vpins using api
    mq135_temp.set_val([t])
    mq135_humi.set_val([h])
  else:
    #print('[ERROR] reading DHT22 sensor data')
    blynk.set_property(3, 'color', ERR_COLOR)
    blynk.set_property(4, 'color', ERR_COLOR)

while True:
    blynk.run()
    timer.run()
  • now here’s the catch.
    The values are flowing in but only for certain amount of time (last time it was working for 8 hours straight). After that, the temp and humidity values nor widget properties (colors) are no longer pushed to Blynk.
    BUT, the Gas sensor keeps receiving the values! I can tell as it’s CO2 values are being written in the given interval to the Blynk.

  • The Wemos device simply waits for the Write event to its V3 or V4; calculates CO2 PPM value and writes to the blynk.

  • what is going on? can it do something with the WS connection being timed out or something?
    thanks!