-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOmegaBlynkTest.py
79 lines (55 loc) · 2.05 KB
/
OmegaBlynkTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import BlynkLib
import time
import logging
import random
import OmegaGPIOHelper
logging.basicConfig(level=logging.DEBUG)
gpio = OmegaGPIOHelper.OmegaGPIOHelper()
def user_task_handler_2(task_state, blynk_ref):
logging.getLogger().debug("user_task_handler_2: {}".format(time.time()))
logging.getLogger().debug("user_task_handler_2: Blynk State: {}".format(blynk_ref.state))
pass
def v127_write_handler(value, pin, state, blynk_ref):
logging.getLogger().debug("V127 Param: {}".format(value))
pass
def v126_read_handler(pin, state, blynk_ref):
value = get_random_digital_value()
if 'last_value' not in state:
state['last_value'] = -1
state['last_value'] = value
return value
def user_task_handler(task_state, blynk_ref):
# logging.getLogger().debug("v33 read handler")
# we must call virtual write in order to send the value to the widget
if task_state['led_state']:
task_state['led_state'] = 0
else:
task_state['led_state'] = 1
blynk_ref.virtual_write(33, 255 * task_state['led_state'])
def hw0_write_handler(value, pin, state, blynk_ref):
logging.getLogger().debug("HW0 write value: {}".format(value))
gpio.setPin(0, value)
def hw26_read_handler(pin, state, blynk_ref):
pin26 = gpio.getPin(pin)
logging.getLogger().debug("hw26_read_handler: {}".format(pin26))
return pin26
def hw1_read_handler(pin, state, blynk_ref):
value = get_random_digital_value()
return value
def get_random_digital_value():
if random.randint(0, 100) <= 50:
value = 0
else:
value = 1
return value
auth_token = ''
blynk = BlynkLib.Blynk(auth_token)
blynk.add_user_task(user_task_handler, 2, {'led_state': 0})
blynk.add_user_task(user_task_handler_2, 2)
blynk.add_digital_hw_pin(0, write=hw0_write_handler)
blynk.add_digital_hw_pin(1, read=hw1_read_handler)
blynk.add_virtual_pin(127, write=v127_write_handler)
blynk.add_virtual_pin(126, read=v126_read_handler)
blynk.add_digital_hw_pin(26, read=hw26_read_handler)
logging.getLogger().info("Running...")
blynk.run()