Micropython and Blynk 2.0 libary

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

@FCS Pycom CATM1 is 75$. A9 is 5$ and TTGO T-CALL SIM800L is 15$. So it depends on what end product you are working on but for my kind of project, it’s not feasible.

use C++ , why so dedicated to use python.

@oxox
I don’t think Blynk arduino library support A9G GPRS module. That’s why we need to migrate the module to MicroPython

Ok, now I can get it to connect to Blynk. Somehow, It got “timeout waiting for first EOF” error after connected to Blynk. I use this library GitHub - vshymanskyy/blynk-library-python: Blynk library for Python. Works with Python 2, Python 3

Here’s the error log:

registering in GSM network...
connected to GSM network2
get GPRS connection...
get UTC...
04:22:38 31-08-2021
Connecting to Blynk...
Connecting to blynk.cloud:443...
Connecting to blynk.cloud:443...
Blynk ready. Ping: 252 ms
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/bin/ampy", line 11, in <module>
    load_entry_point('adafruit-ampy==1.1.0', 'console_scripts', 'ampy')()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/chamroeun/Library/Python/3.8/lib/python/site-packages/ampy/cli.py", line 338, in run
    output = board_files.run(local_file, not no_output, not no_output)
  File "/Users/chamroeun/Library/Python/3.8/lib/python/site-packages/ampy/files.py", line 309, in run
    self._pyboard.execfile(filename, stream_output=True)
  File "/Users/chamroeun/Library/Python/3.8/lib/python/site-packages/ampy/pyboard.py", line 285, in execfile
    return self.exec_(pyfile, stream_output=stream_output)
  File "/Users/chamroeun/Library/Python/3.8/lib/python/site-packages/ampy/pyboard.py", line 277, in exec_
    ret, ret_err = self.exec_raw(command, data_consumer=data_consumer)
  File "/Users/chamroeun/Library/Python/3.8/lib/python/site-packages/ampy/pyboard.py", line 266, in exec_raw
    return self.follow(timeout, data_consumer)
  File "/Users/chamroeun/Library/Python/3.8/lib/python/site-packages/ampy/pyboard.py", line 230, in follow
    raise PyboardError('timeout waiting for first EOF reception')
ampy.pyboard.PyboardError: timeout waiting for first EOF reception

And here’s my code:

import time
import cellular
import machine
import ntptime
import BlynkLib
from BlynkTimer import BlynkTimer
#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 network2")
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("smart", "", "")
except Exception as e:
            print('gprs exception:\n  ' + repr(e))
            time.sleep_ms(200) #need only for serial output to be printed

BLYNK_AUTH = 'mya'
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("Connecting to Blynk...")
# 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()

You can use any board you want with portable router. No libraries or coding needed.

@John93 How to make Blynk support A9 GPRS(GitHub - Ai-Thinker-Open/GPRS_C_SDK: Ai-Thinker A9/A9G GPRS (with GPS(A9G)) module C development S) without porting A9 to MicroPython first? That would be great if it’s possible as MicroPython for A9G still have many bugs.

I’ve never used this board before, but I’m using esp32 and it a great choice, you should try it.

Can you tell me what are you trying to do ?
Give more information about your project please.