Micropython and Blynk 2.0 libary

@GarudaOne
I’m not at home for the moment and can’t check my code, but from a glance, try

blynk = BlynkLib.Blynk(BLYNK_AUTH, insecure=True)

Definitely, it was a point for my connection to Blynk.

And yes, Micropython for A9G is created by enthusiast for enthusiasts. So, it’s far from to be perfect. :slightly_smiling_face:

@Alegz
I also tried this insecure mode, but still the same error.

@John93
ESP32 and A9G are very different pieces of electronics with different tasks. ESP32 using WiFi connection, while A9G - GPRS. I.e. ESP32 need WiFi router to be functional, but A9G is suitable for mobile task such as automobile/bicykle GPS tracker via blynk, or to control something somewhere very far from LAN cables.

@GarudaOne
Well, will check it later, when I’ll be at home.

P.S. Just a thought. Try to involve some string exchange with Blynk - say, send any number to virtual pin. or print some string (say, every 5 seconds) to your terminal with timer. Maybe the reason is in COM port, which is in idle state while your blynk.run() loop just running itself.

P.P.S. It seems, it is common problem for Ampy - I have never used it before.

1 Like

i also put the code in main.py so it should has nothing to do with ampy. I see it disconnected immediately after connection

@GarudaOne

I see no much difference with your and my codes. Simplified code, which is running now, is:

import time
import cellular
import machine
import ntptime

import BlynkLib
from BlynkTimer import BlynkTimer 

machine.watchdog_on(30)

while cellular.is_network_registered() == False:
    time.sleep_ms(1000)
    
try:
    cellular.gprs("internet", "", "")
except Exception as e:
            print('gprs exception:\n  ' + repr(e))
            
while time.localtime()[0] == 2017: 
  try:
      ntptime.settime() 
  except Exception as e:
      print('ntp exception:\n  ' + repr(e))        
      
t = time.localtime()
print("{:02d}:{:02d}:{:02d} {:02d}-{:02d}-{}".format(t[3], t[4], t[5], t[2], t[1], t[0])) 
BLYNK_AUTH = 'XM****'

timer = BlynkTimer()

def print_me():
    t = time.localtime()
    time_now = "{:02d}:{:02d}:{:02d} {:02d}-{:02d}-{}".format(t[3], t[4], t[5], t[2], t[1], t[0])
    blynk.virtual_write(0, time_now + '\n')
    print(time_now)
    machine.watchdog_reset()

timer.set_interval(10, print_me)

blynk = BlynkLib.Blynk(BLYNK_AUTH, insecure=True)

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

while True:
    blynk.run()
    timer.run() 

Lets’s check template at blynk.cloud

My setings:


Terninal widget is connected to V0 (Terminal) in mobile application. Everything is running. As I said, the keypoint in my case was “insecure=True”.

P.S. I see some difference in results.

Your line:

Connecting to blynk.cloud:443...

My line:

Connecting to blynk.cloud:80...

I have no idea, why such difference in target ports is, but try port 80, which stands for unsecure connection, also.

1 Like

@Alegz thanks very much. It works now–stop crashing now.
I still don’t know what the cause of my code error. Anyway, I will investigate more. I just used Blynk for 3 days so many things that I still need to understand and also my first MicroPython project.

Let me try to keep it running for several days to see how it performs.

What I needs more from this device is I2C for sensors and controlling a 4 channel relay. For bigger task, i will let my ESP32 and RPi handle it.

I see a post about using A9G for mailbox controller for more than 1 year without any issue.

@Alegz Its I2C works even though it doesn’t use the standard I2C for Micropython. Strangely, it work only on port 2 among the 3 i2c ports. For your microSD case, I don’t know if it is the same an issue on github there or not.

Currently, I am keep it running to Blynk with SHT30 and 4 relays. Let’s see how if it go smoothly.
So far it reboot a few times, I have no idea why yet.

@GarudaOne According to A9G puddung board schematic, only I2C2 has pull-up resistors and marked as I2C line. I2C1 is tied to SD card, and I2C3 is marked as IO ports. I guess, it is just software restriction to use 'em as I2C, but I’m not sure :slightly_smiling_face:. Maybe it is worth to add pull-ups to other lines too, it’s subject to experiment.

@vshymanskyy , please help providing code for handling wifi disconnection , the function decorator @blynk.on(‘disconnected’) does not respond. I am working on ESP32.

@Tarun_Nigam
Hey there. try this :

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest
  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.
    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app
  Blynk library is licensed under MIT license
  This example code is in public domain.
 *************************************************************
  This example shows how to keep WiFi connection on ESP8266.
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID   "YourTemplateID"


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";


int lastConnectionAttempt = millis();
int connectionDelay = 5000; // try to reconnect every 5 seconds

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  // check WiFi connection:
  if (WiFi.status() != WL_CONNECTED)
  {
    // (optional) "offline" part of code

    // check delay:
    if (millis() - lastConnectionAttempt >= connectionDelay)
    {
      lastConnectionAttempt = millis();

      // attempt to connect to Wifi network:
      if (pass && strlen(pass))
      {
        WiFi.begin((char*)ssid, (char*)pass);
      }
      else
      {
        WiFi.begin((char*)ssid);
      }
    }
  }
  else
  {
    Blynk.run();
  }
}

@John93 Hi, Thanks for your so prompt reply, but i need the code in micro python . if you can help.

@Tarun_Nigam hi, I don’t know much about micropython so I’m sorry I can’t help you but have you tried this :

print("Connecting to WiFi network '{}'".format(WIFI_SSID))
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect(WIFI_SSID, WIFI_PASS)
while not wifi.isconnected():
    time.sleep(1)
    print('WiFi connect retry ...')
print('WiFi IP:', wifi.ifconfig()[0])

print("Connecting to Blynk server...")
blynk = blynklib.Blynk(BLYNK_AUTH)

@vshymanskyy Have tried all options, even modified the library to check status of wifi and reconnect , but not seem to be possible. I expect prompt support from Blynk team for potential customers. This is been lot of delay and my go to market time is prolonging.

Priority is C++
Micropython is just for the fun .
A very few of us use this language.
Less than 1 percent :stuck_out_tongue_winking_eye:

I did not as for Opinion friend… all languages have their pros and cons, anyways I am good with Python… :grinning:

I’m good in micro-python too guy , but as I said, 99% of the blynk user used C++
So micro-python is not a priority ATM for Blynk staff and I can understand that, not you ?

As a customer I may not understand your priorities, I suppose if that is the thought process then I is in wrong direction.

It’s not my priority , I am a end-user , lol
And as I can code in several languages , no matter for me :stuck_out_tongue_winking_eye:

The wrong direction for you personally, but you have to remember that the majority of coders who work on IoT projects started with Arduino products and using C++
This is where the dominance of C++ for this type of hardware stems from, and it’s where companies like Blynk need to focus their resources to be competitive in the field.

Pete.

1 Like