Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
John93-Blynk authored Oct 4, 2022
1 parent 45a5f1f commit 96cf67c
Show file tree
Hide file tree
Showing 15 changed files with 903 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/01_virtual_write.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
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'

# initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

tmr_start_time = time.time()
while True:
blynk.run()

t = time.time()
if t - tmr_start_time > 1:
print("1 sec elapsed, sending data to the server...")
blynk.virtual_write(0, "time:" + str(t))
tmr_start_time += 1
38 changes: 38 additions & 0 deletions examples/02_on_virtual_change.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
This example shows how to perform custom actions
using data from the widget.
In your Blynk App project:
Add a Slider widget,
bind it to Virtual Pin V3.
Run the App (green triangle in the upper right corner)
It will automagically call v3_write_handler.
In the handler, you can use args[0] to get current slider value.
"""

import BlynkLib

BLYNK_AUTH = 'YourAuthToken'

# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

# Register virtual pin handler
@blynk.on("V3")
def v3_write_handler(value):
print('Current slider value: {}'.format(value[0]))

while True:
blynk.run()
33 changes: 33 additions & 0 deletions examples/03_sync_virtual.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
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)

@blynk.on("V*")
def blynk_handle_vpins(pin, value):
print("V{} value: {}".format(pin, value))

@blynk.on("connected")
def blynk_connected():
# You can also use blynk.sync_virtual(pin)
# to sync a specific virtual pin
print("Updating V1,V2,V3 values from the server...")
blynk.sync_virtual(1,2,3)

while True:
blynk.run()
51 changes: 51 additions & 0 deletions examples/04_timer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
This example shows how to run functions after certain intervals
It will automagically call hello_word once after 2 seconds, and print_me
every 5 seconds
You should only need one BlynkTimer instance for a project,
as you can add multiple functions to it
"""

import BlynkLib
from BlynkTimer import BlynkTimer

BLYNK_AUTH = 'YourAuthToken'

# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

# Create BlynkTimer Instance
timer = BlynkTimer()


# Will only run once after 2 seconds
def hello_world():
print("Hello World!")


# Will Print Every 5 Seconds
def print_me():
print("Thanks!")


# Add Timers
timer.set_timeout(2, hello_world)
timer.set_interval(5, print_me)


while True:
blynk.run()
timer.run()
46 changes: 46 additions & 0 deletions examples/05_utc_and_timezone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
This example shows how to get UTC time and Timezone info
"""

import BlynkLib
import time

BLYNK_AUTH = 'YourAuthToken'

# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

@blynk.on("connected")
def blynk_connected(ping):
print('Blynk ready. Ping:', ping, 'ms')
blynk.send_internal("utc", "time")
blynk.send_internal("utc", "tz_name")

@blynk.on("disconnected")
def blynk_disconnected():
print('Blynk disconnected')

@blynk.on("internal:utc")
def on_utc(value):
if value[0] == "time":
ts = int(value[1])//1000
# on embedded systems, you may need to subtract time difference between 1970 and 2000
#ts -= 946684800
tm = time.gmtime(ts)
print("UTC time: ", time.asctime(tm))
elif value[0] == "tz_name":
print("Timezone: ", value[1])

while True:
blynk.run()
43 changes: 43 additions & 0 deletions examples/06_widget_terminal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
This example shows how to add a custom terminal widget.
In your Blynk App project:
Add a Terminal widget, bind it to Virtual Pin V3.
Run the App (green triangle in the upper right corner).
"""

import BlynkLib

BLYNK_AUTH = 'YourAuthToken'

# initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

@blynk.on("V3")
def v3_write_handler(value):
# execute the command echo it back
blynk.virtual_write(3, 'Command: ' + value + '\n')
blynk.virtual_write(3, 'Result: ')
try:
blynk.virtual_write(3, str(eval(value)))
except:
try:
exec(value)
except Exception as e:
blynk.virtual_write(3, 'Exception:\n ' + repr(e))
finally:
blynk.virtual_write(3, '\n')

while True:
blynk.run()
49 changes: 49 additions & 0 deletions examples/07_other_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
This example shows how to use advanced functions of Blynk library:
- insecure connection
- debug logging
- custom server
- changing heartbeat
- connected/disconnected events
- generic virtual pin events
"""

from __future__ import print_function
import BlynkLib

BLYNK_AUTH = 'YourAuthToken'

# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH,
insecure=True, # disable SSL/TLS
server='blynk.cloud', # set server address
port=80, # set server port
heartbeat=30, # set heartbeat to 30 secs
log=print # use print function for debug logging
)

@blynk.on("connected")
def blynk_connected(ping):
print('Blynk ready. Ping:', ping, 'ms')

@blynk.on("disconnected")
def blynk_disconnected():
print('Blynk disconnected')

@blynk.on("V*")
def blynk_handle_vpins(pin, value):
print("V{} value: {}".format(pin, value))

while True:
blynk.run()
Loading

0 comments on commit 96cf67c

Please sign in to comment.