-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy path12_app_connect_disconnect.py
74 lines (60 loc) · 3.91 KB
/
12_app_connect_disconnect.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
"""
[APP CONNECT DISCONNECT EVENTS EXAMPLE] ============================================================
Environment prepare:
In your Blynk App project:
- in Project Settings enable flag "Notify devices when APP connected"
- define your auth token for current example and run it
- Run the App (green triangle in the upper right corner).
This started program will call handlers and print messages for APP_CONNECT or APP_DISCONNECT events.
Schema:
====================================================================================================
+-----------+ +--------------+ +--------------+
| | | | | |
| blynk lib | | blynk server | | blynk app |
| | | virtual pin | | |
| | | | | |
+-----+-----+ +------+-------+ +-------+------+
| | app connected or disconnected |
| | from server |
| |
event handler | app connect/disconnect event +<-----------------------------------+
(user function) | | |
+------------<-----------------------------------+ |
| | | |
| | | |
+--------->+ | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
+ + +
====================================================================================================
Additional blynk info you can find by examining such resources:
Downloads, docs, tutorials: https://blynk.io
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
====================================================================================================
"""
import blynklib
BLYNK_AUTH = 'YourAuthToken'
# initialize Blynk
blynk = blynklib.Blynk(BLYNK_AUTH)
APP_CONNECT_PRINT_MSG = '[APP_CONNECT_EVENT]'
APP_DISCONNECT_PRINT_MSG = '[APP_DISCONNECT_EVENT]'
@blynk.handle_event('internal_acon')
def app_connect_handler(*args):
print(APP_CONNECT_PRINT_MSG)
@blynk.handle_event('internal_adis')
def app_disconnect_handler(*args):
print(APP_DISCONNECT_PRINT_MSG)
###########################################################
# infinite loop that waits for event
###########################################################
while True:
blynk.run()