Objective: To control the brightness of a virtual LED with a virtual variable resistor (ie the Slider widget).
Details :
• Hardware model + communication type: Raspberry Pi 4 Model B, wifi
• Smartphone OS (iOS or Android) + version: iOS 15
• Blynk server or local server: local server
• Blynk Library version: v.0.2.0 (Volodymyr Shymanskyy’s library)
The code isn’t mine, it’s just that I got an example, followed its steps and yet, it only shows the blynk logo. I’m using Thonny Python IDE.
Now, I’m coding on the RPi itself. When I saved and applied the widgets, using the blynk console, it says that my device is offline after I ran the example. Also, Quickstart gives me code in C++, not Python which is what I need for an RPi. How do I get my device online? And how do I upload the code to the RPi that I’m using to code?
Environment prepare:
In your Blynk App project:
- add "Slider" widget,
- bind it to Virtual Pin V4,
- set values range 0-255
- add "LED" widget and assign Virtual Pin V4 to it
- Run the App (green triangle in the upper right corner).
- define your auth token for current example and run it
import blynklib
BLYNK_AUTH = 'AUTH_TOKEN'
# initialize Blynk
blynk = blynklib.Blynk(BLYNK_AUTH)
WRITE_EVENT_PRINT_MSG = "[WRITE_VIRTUAL_PIN_EVENT] Pin: V{} Value: '{}'"
# register handler for virtual pin V4 write event
@blynk.handle_event('write V4')
def write_virtual_pin_handler(pin, value):
print(WRITE_EVENT_PRINT_MSG.format(pin, value))
###########################################################
# infinite loop that waits for event
###########################################################
while True:
blynk.run()