Use of timers with Python 3

Hi,

I cannot get more than a timer to work with Python and I’m not sure if it’s possible. Here’s a test code:

#!/usr/bin/python3

# import libraries
import BlynkLib
import time

BLYNK_AUTH = '**'

# set virtual pins
t1 = 17
t2 = 18

# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

@blynk.VIRTUAL_READ(t1)
def test1():
    t = time.localtime()
    s = t.tm_sec
    print('Test_1: {}'.format(s))
    blynk.virtual_write(t1, str(s))

@blynk.VIRTUAL_READ(t2)
def test2():
    t = time.localtime()
    s = t.tm_sec
    print('Test_2: = {}'.format(s))
    blynk.virtual_write(t2, str(s))

#activate timers
blynk.set_user_task(test1, 3000)
blynk.set_user_task(test2, 5000)

# Start Blynk (this call should never return)
blynk.run()

and this’ what I get. Test 1 doesn’t fire:

___  __          __

/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/

Give Blynk a Github star! => GitHub - vshymanskyy/blynk-library-python: Blynk library for Python. Works with Python 2, Python 3, MicroPython.

TCP: Connecting to blynk-cloud.com:80
Blynk connection successful, authenticating…
Access granted, happy Blynking!
Test_2: = 58
Test_2: = 3
Test_2: = 8
Test_2: = 13
Test_2: = 18
Test_2: = 23
Test_2: = 28

See this topic…

Meanwhile you are already using @blynk.VIRTUAL_READ(vPin) which should pull its reading frequency from the widget itself (do not set them to PUSH), not via any code based tasker or timer.

@Emilio the other fairly easy hack is to use the one available timer set to 1000 and then two counters. When counter x == 3 do test1 and when counter y == 5 do test2.

Clever, thank you!