Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Blynk.Inject with ESP32? #67

Open
EugeneRymarev opened this issue Nov 25, 2022 · 6 comments
Open

How to use Blynk.Inject with ESP32? #67

EugeneRymarev opened this issue Nov 25, 2022 · 6 comments

Comments

@EugeneRymarev
Copy link

Hello!
Where can I find an example of using Blynk.Inject with this package?

@EugeneRymarev EugeneRymarev changed the title How to use Blynk.Inject? How to use Blynk.Inject on ESP32? Nov 25, 2022
@EugeneRymarev EugeneRymarev changed the title How to use Blynk.Inject on ESP32? How to use Blynk.Inject with ESP32? Nov 25, 2022
@EugeneRymarev
Copy link
Author

@vshymanskyy, could you suggest?

@ebolisa
Copy link

ebolisa commented Dec 7, 2022

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.

@EugeneRymarev
Copy link
Author

@ebolisa, I mean the implementation of the Blynk.Inject function for connecting in the application, as in this video

@ebolisa
Copy link

ebolisa commented Dec 7, 2022

@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.

@EugeneRymarev
Copy link
Author

@ebolisa, could you show a complete example?

@ebolisa
Copy link

ebolisa commented Dec 8, 2022

@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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants