Device Offline (Micropython) (New Blynk)

You mean I should use Arduino?

When you say “Arduino” do you mean the Arduino IDE as opposed to VS Code?

It’s possible to use a variety of different development environments with the C++ library, it doesn’t have to be the Arduino IDE.

The C++ libraries for Blynk are certainly much better developed and feature-rich, and there are many more coding examples compared to the uPython and NodeJS libraries. It obviously depends on where your programming language skills lie, and the hardware that you’re using.

Pete.

1 Like

Okay Pete, I’ll try using the C++ library. However, i was able to get my device online but still it’s not working as expected.

Micropython is making me sick now…

In this case, try blynk edgent

What’s that @John93

Blynk Edgent is a way to automatically provision the device with WiFi credentials rather than hard-coding them into the sketch.
The Edgent example sketch also has Blynk.Air OTA built-in to allow you to upload a new sketch to the device without the need to physically access the device and plug it in to your PC with a serial cable. In fact, you can ship new firmware to your device regardless of where it is in the world.

The Edgent example sketch is somewhat more complex than the standard WiFi sketch though, and you have to take care to use the correct board settings for your device, or edit the Settings.h file to ensure that you don’t have any conflicts between the onboard LED and Reset pin that the Edgent sketch is using for the provisioning process and any pins that you may be using for your own purposes.

Pete.

1 Like

Thanks for the info Pete.

Just wanted to let you know that I teach Physical Computing to kids in my neighborhood and this time my project is an IoT project. A simple LED lamp controller. It has an LED panel consisting of 2 types of LED arrays - White and Yellow LEDs

The Blynk app is used to control the brightness levels of each LED array. I am using two horizontal slider widgets for that purpose.

The major reason why I am choosing Blynk Python library over the C++ library because kids find Python easier to learn and implement as compared to C/C++.

I would like your recommendation here. What should I do here? Go with Micropython library or C++ library?

I just don’t want the kids to get overwhelmed by this project. I want to make them feel that they too can create cool stuff on their own.

FYI,
My device is online and I am able to adjust the brightness of the individual panels. But again, I’d like to highlight that it’s not working as expected.

When I reset my esp32 board. The white light is always on even before the board is connected to a network, and i have to again adjust the slider which is already at 0 brightness to some other level, say 125 and then back to 0 in order to turn off the white lead array.

My white light is connected to esp32 GPIO 13 and yellow light to GPIO 12.

What you are describing with having to ‘dirty’ the slider value to get the current setting to be applied is common to any version of the Blynk library.
The Blynk server doesn’t automatically send the latest widget values on connection/reconnection. The values are only sent when they change, or when they are requested.

C++ has a callback function called BLYNK_CONNECTED() which is triggered whenever the device connects/reconnects to the server.
You can place commands within this function to force the server to send the latest values for the virtual pins you’re interested in, the Blynk.syncVirtual(vPin) command is what you’d use in C++

I know absolutely nothing about uPython, and have no interesting in learning it, so I don’t know if similar commands exist within that library.

As far as the white LED being on before the network connection is established - this is probably the default state of the pin you’re using. In C++ a virtualWrite(physical_pin,value) command immediately after the pinMode() command for that physical pin is normally all that’s required to put it in the desired state while the connection process runs.
Once again, I have no idea what the corresponding uPython commands are for this are.

It’s entirely up to you and the preferences/capabilities of the kids you teach.

The only mainstream library for Blynk is the C++ one, and you’ll probably find that 99.9% of users and the examples that they post are using C++
The other libraries are what I consider to be ‘hobby’ projects and are useful for hardware that doesn’t have C++ capabilities.

I also think that as the Arduino hardware is now totally ubiquitous and C++ is the default language adopted by Arduino.cc then learning those skills are probably not a bad idea.
I guess that if I were looking to build a career as a software developer then I’d maybe say that Python is a useful skill to have, and could make you stand out from the kids that have grown-up on Arduino C++ and nothing else, but TBH it’s difficult to predict what will be tomorrow’s ‘soup of the day’ as far as the preferred language is concerned.

Pete.

1 Like

Yes, you are right. We never know what’s coming.

I just feel that Arduino C++ is not actually C++. It is very modular and strips away so many important details of how Blynk is actually working under the hood. The networking concepts, callbacks, etc.

Anyways, I won’t bore you with all this.

Just wanted to thank you for your support throughout this little project of mine.

From the point of view of kids getting started in programming it’s a rather academic difference, and is mostly about getting the code to run effectively on microprocessors.

Yes, but so do all the other Blynk libraries. If you want to get quick results with minimal user coding then you libraries. If you want to dig into those libraries and learn more at a later date then you can, but for kids they will generally be looking for quick feedback for a minimal amount of effort - which is what you get when you use libraries to do all of the heavy lifting.

Anyway, I’ll mark this topic as solved as it seems to have run its course.

Pete.

If you still want to test with mpython, try the following connection string. Also, use your local server which name can be found on your dashboard, mine is ‘fra1.blynk.cloud’.

try:
#         blynk = BlynkLib.Blynk(BLYNK_AUTH, insecure=True)
        blynk = BlynkLib.Blynk(BLYNK_AUTH,
        insecure=True,          # disable SSL/TLS
        server='fra1.blynk.cloud', # fra1.blynk.cloud or blynk.cloud
        port=80,                # set server port
        heartbeat=30,           # set heartbeat to 30 secs
        log=print              # use print function for debug logging
        )
except OSError as e:
    utime.sleep(3)
    restart_and_reconnect(e)

Thanks for the code snippet Emilio. However, I only want a secure connection with Blynk.

@vcr3at3 here is an example of the “connected” handler, works like a charm:

#--------------------------------------------------------------------------------
# Sync server settings with edge device
#--------------------------------------------------------------------------------
@blynk.handle_event ("connected")
#def AutoSync(ping):
def AutoSync():
    # You can also use blynk.sync_virtual(pin)
    # to sync a specific virtual pin
	print("Updating Output 1 Setting")
	blynk.sync_virtual(9)
#	print("Updating V1,V2,V3 values from the server...")
#	blynk.sync_virtual(1,2,3)							# Sync multiple PIN's

Thankyou for this snippet. This literally works like a charm.

Though I don’t know much about OOP concepts but is it possible to create my own library using simple API calls using the instructions given in the new Blynk documentation?