blynk-library-python
blynk-library-python copied to clipboard
How to use Blynk.Inject with ESP32?
Hello! Where can I find an example of using Blynk.Inject with this package?
@vshymanskyy, could you suggest?
could you suggest?
I used wifimgr.py. Modified the html/py code to collect credentials by storing them in wifi.dat and then, used them in my main code.
@ebolisa, I mean the implementation of the Blynk.Inject function for connecting in the application, as in this video
@ebolisa, I mean the implementation of the Blynk.Inject function for connecting in the application, as in this video
I undestood you. wifimgr.py puts your device in AP mode like shown in the video. Then you introduce your router and Blynk credentials. At reboot, your device will automatically connect to Blynk. At least, that's the way I do it.
@ebolisa, could you show a complete example?
@ebolisa, could you show a complete example?
First make wifimgr.py work without Blynk. Then modify its html code to accept the blynk token. Modify its py code so it can be read.
Then in boot.py:
try:
wlan = wifimgr.get_connection()
BLYNK_AUTH = wifimgr.get_profiles()[2]
print('** Wifi connection established **')
if wlan is None:
print("Could not initialize the network connection.")
while True:
pass # you shall not pass :D
except Exception:
print('Wifi connection error...')
umachine.reset()
in main.py:
# Initialize Blynk
try:
# blynk = BlynkLib.Blynk(BLYNK_AUTH) # faster
# or....
blynk = BlynkLib.Blynk(BLYNK_AUTH,
insecure=True, # disable SSL/TLS
server='lon1.blynk.cloud', # lon1 fra1.blynk.cloud or blynk.cloud
port=80, # set server port
heartbeat=30, # set heartbeat to 30 secs
log=dprint # use print function for debug logging
)
except OSError as e:
umachine.restart()
@blynk.on("connected")
def blynk_connected(ping):
print('Blynk ready. Ping:', ping, 'ms')
blynk.sync_virtual()
@blynk.on("disconnected")
def blynk_disconnected():
print('Blynk disconnected')
utime.sleep(5)
umachine.reset()