FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
lib-python/examples/10_rtc_sync.py at master · markom84/lib-python · GitHub
markom84
lib-python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
lib-python
/
examples
/
10_rtc_sync.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
77 lines (64 loc) · 4.18 KB
Breadcrumbs
lib-python
/
examples
/
10_rtc_sync.py
Copy path
File metadata and controls
77 lines (64 loc) · 4.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"""
[RTC EXAMPLE] ========================================================================================================
Environment prepare:
In your Blynk App project:
- add "RTC" widget,
- set required TimeZone,
- Run the App (green triangle in the upper right corner).
- define your auth token for current example and run it
This started program on connect will send rtc_sync call to server.
RTC reply will be captured by "internal_rtc" handler
UTC time with required timezone correction will be printed
Schema:
=====================================================================================================================
+-----------+ +--------------+ +--------------+
| | | | | |
| blynk lib | | blynk server | | blynk app |
| | | | | |
| | | | | |
+-----+-----+ +------+-------+ +-------+------+
| | |
connect handler | | |
+-------+ | |
| | | |
| | rtc sync | |
+------>------------------------------------->+ rtc widget present in app? |
| +----------------------------------->+
| | |
| | yes rtc widget found |
| rtc with timezone correction +<-----------------------------------+
internal_rtc | | |
handler +--------<------------------------------------+ |
| | | |
| | | |
+------>+ | |
| | |
| | |
+ + +
=====================================================================================================================
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
from
datetime
import
datetime
BLYNK_AUTH
=
'YourAuthToken'
blynk
=
blynklib
.
Blynk
(
BLYNK_AUTH
)
@
blynk
.
handle_event
(
"connect"
)
def
connect_handler
():
blynk
.
internal
(
"rtc"
,
"sync"
)
print
(
"RTC sync request was sent"
)
@
blynk
.
handle_event
(
'internal_rtc'
)
def
rtc_handler
(
rtc_data_list
):
hr_rtc_value
=
datetime
.
utcfromtimestamp
(
int
(
rtc_data_list
[
0
])).
strftime
(
'%Y-%m-%d %H:%M:%S'
)
print
(
'Raw RTC value from server: {}'
.
format
(
rtc_data_list
[
0
]))
print
(
'Human readable RTC value: {}'
.
format
(
hr_rtc_value
))
###########################################################
# infinite loop that waits for event
###########################################################
while
True
:
blynk
.
run
()
Back
|
FazBrowse Home
|
New Git URL