Micropython and Blynk 2.0 libary

Hi @vshymanskyy

Do you have a simple version yet?
Or an ETA?

yes, we have!
will be sharing soon

3 Likes

Hi @vshymanskyy ,
Please let me know on the support for ESP32 over micro python on new Blynk cloud. I am using older version of Blynk mpy library for my prototype , can that be tweaked for new cloud and template pls.

@vshymanskyy @PeteKnight , I am using the new Python Library on ESP32, presently have made my own wifi provisioning on ESP32 through web page & wifimanager for ESP32. However I am finding it difficult to handle disconnection of wifi. Can you please provide code for the same in python. The “Status” variable of “Connect” function does not give stable value.
Please help.

Thanks ,

giphy

1 Like

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

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

These have been working perfectly for me

I have an issue with random disconnections and ssl does not work
Will post code and terminal output soon
It connects with ssl and crashes

On the disconnect I have inserted a 5 second delay and the reconnect works 90% of the time

Currently, my personal Python library was updated to support Blynk 2.0:

There’s also an initial implementation of Blynk.Edgent Dynamic Provisioning for Raspberry Pi (for advanced users)

2 Likes

Tested it with A9G Pudding board thru GPRS connection. From the first galnce, it does work with Blynk 2.0 in my case (except of @decorators which seems to be not supported by A9G micropython version). Very useful library, thanks.

2 Likes

Could you post a test code, pls? (Don’t need the whole code. Just the part which connects to the cloud 2.0) I’m having (looks like) a memory issue with the library, here is my post.
Thanks.

Hi
I am having issues with SSL
Set your ssl to insecure. This fixed my issues
Using the examples they worked for me

Using Pycom GPY
Get random disconnects every now and again

Pycom devices have tons of ram and flash
I think 8 MB of each

I thought that applied only for the ESP8266. Thank you, it worked!

` For ESP8266, you may need to disable secure connection using:

blynk = BlynkLib.Blynk('YourAuthToken', insecure=True)`
1 Like

Hi,

I tried the python modified library with a Rpi 4 board. It works but, I’m getting disconnections even with this code in the loop:

def runLoop():
    while True:
       try:
         blynk.run()
         timer.run()
       except socket.error as e:
         if(e.errno != errno.EPIPE):
           t = time.ctime()
           logging.error(str(t) + " err in main blynk " + e)
           raise
         blynk.connect()

BTW, what do you mean by

personal Python Library?

Doesn’t Blynk HQ support it?
Thanks for updating it.

@vshymanskyy @PeteKnight

On Raspberry Pi, I get the v0.2.0 which is said to be the legacy Blynk - ie old one-
Please remain on v0.2.0 for legacy Blynk. - when pip3 installing the library:

$pip3 install blynk-library-python
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting blynk-library-python
  Downloading https://www.piwheels.org/simple/blynk-library-python/blynk_library_python-0.2.0-py3-none-any.whl
Installing collected packages: blynk-library-python
Successfully installed blynk-library-python-0.2.0

How to force pip3 to get the 2.0 library for Python ?

Have I missed something somewhere ?

@FCS , I used the code in by Main program on ESP32, how ever when I disconnect Wifi and then reconnect (Trying to emulate wifi disconnections), there is no response for above function codes. Can u help on how to handle the wifi disconnections. I suppose the Blynk library has no sync with Wifi connectivity.

Use if wifi disconnected. do something like this

DISCLAMER
Am not a programmer

@blynk.on("disconnected")
def blynk_disconnected():
    print('Blynk disconnected')
    time.sleep(5)
    Blynk.connect


If wifi.connected == true: 
    Blynk.run
else:
    wifi.connect

@Alegz how is your testing with Micropython A9G?

I got it working partially in MicroPython. However, after I insert SIM, it stop working.

I read several posts in A9G Micropython, it looks like very unstable.

Thanks

@GarudaOne Currently I’m paused my experiments with A9G because I can’t get SD card work - I never seen it mounted. As for Blynk via A9G GSM - it does work. What version of MicroPython do you use? I’m work with pulkin + uPyCraft as IDE.

@Alegz I use the one by pulkin as you. I don’t know why it suddenly stop working when I insert the sim card. If I remove the SIM, i can run python script in that A9 chip normally. However, the SIM card seems t work as I can make a call to that sim from another phone.

I want to use this A9 chip for simple task(1-read i2c sensors data and 2-control relays). Due to its low cost in compared with TTGO T-Call, it is a good choice.

@GarudaOne

Try this code first:

import time
import cellular
import machine
import ntptime

machine.watchdog_on(30)
print("registering in GSM network...")
time.sleep_ms(200) #need only for serial output to be printed

while cellular.is_network_registered() == False:
    time.sleep_ms(1000)
    print("connecting...")
    time.sleep_ms(200) #need only for serial output to be printed

print("connected to GSM network")
time.sleep_ms(200) #need only for serial output to be printed

print("get GPRS connection...")
time.sleep_ms(200) #need only for serial output to be printed 
try:
    cellular.gprs("internet", "", "")
except Exception as e:
            print('gprs exception:\n  ' + repr(e))
            time.sleep_ms(200) #need only for serial output to be printed


print("get UTC...") 
time.sleep_ms(200) #need only for serial output to be printed
while time.localtime()[0] == 2017: #2017 is year in A9G module by default at start
  try:
      ntptime.settime() 
  except Exception as e:
      print('ntp exception:\n  ' + repr(e))        
      time.sleep_ms(1000)
t = time.localtime()
print("{:02d}:{:02d}:{:02d} {:02d}-{:02d}-{}".format(t[3], t[4], t[5], t[2], t[1], t[0])) #print formatted time
time.sleep_ms(200) #need only for serial output to be printed
print("Boot done!")

Just a short test of the network. If everything is fine, you will get UTC time at your IDE serial connection input. If not - you can see where the problem is.

I’m expect, something wrong with your string:

cellular.gprs("internet", "", "") # edit this string according to your GSM network rules ("AP", "user", "password")

In the worst case your GSM operator does not support 2G devices anymore as legacy ones.

1 Like

@Alegz
@GarudaOne

I use the Pycom GPY it is more expensive but is fully certified to be used in a product you can sell without having to get the radio part certified

PYCOM has well documented examples and just works. Global LTE cat-m support
I use it in a product im about to start selling and got my device certified for $800

It runs for 5 hours with an oled screen GPIO rs232 from a 1000ma lipo

They just work, easy to flash devices from MS VS with their own PYMAKr plugin