-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy path04_email.py
77 lines (63 loc) · 4.56 KB
/
04_email.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
"""
[EMAIL ON CONNECT EXAMPLE] ==========================================================================================
Environment prepare:
In your Blynk App project:
- add "Email" widget,
- Run the App (green triangle in the upper right corner).
- define for current example your target email.
- define your auth token for current example and run it
This started program will operate with "connect_handler".
Within handler after short sleep delay email send operation will be performed.
Schema:
=====================================================================================================================
+-----------+ +--------------+ +--------------+ +-------+
| | | | | | | |
| blynk lib | | blynk server | | blynk app | | email |
| | | virtual pin | | | | box |
| | | | | | | |
+-----+-----+ +------+-------+ +-------+------+ +---+----
| connect request | | |
+------------------------------------>+ | |
connect handler | | | |
(user function) | connected successfully | | |
+-----------<------------------------------------+ | |
| | | | |
| | send email | email widget present? | |
+--------->------------------------------------->+ (is user allowed to send emails) | |
| +----------------------------------->+ |
| | | |
| | email sending allowed | |
| +<-----------------------------------+ |
| | | |
| | | |
| | send email to defined address | |
| +----------------------------------------------------->+
| | | |
| | | |
+ + + +
=====================================================================================================================
Additional info about blynk 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
import time
BLYNK_AUTH = 'YourAuthToken'
TARGET_EMAIL = 'YourTargetEmail'
blynk = blynklib.Blynk(BLYNK_AUTH)
EMAIL_PRINT_MSG = "[EMAIL WAS SENT to '{}']".format(TARGET_EMAIL)
@blynk.handle_event("connect")
def connect_handler():
print('Sleeping 2 sec before sending email...')
time.sleep(2)
blynk.email(TARGET_EMAIL, 'BLYNK-HW-TEST-EMAIL', 'Connected!')
print(EMAIL_PRINT_MSG)
###########################################################
# infinite loop that waits for event
###########################################################
while True:
blynk.run()