Blynk App Shows My Device (Python Blynk 2.0 on Windows PC) Is Offline

My project was to shutdown my PC by using a voice assistant. This is a Russian voice assistant called Alisa (by Yandex) - it’s like Alexa (by Amazon). To do so I found a guide, but it’s in Russian. Anyways you can find it here, because my project isn’t actually mine.

The thing is that you use Blynk and Python. I did everything as it is described in the guide on my old PC with the old version of Blynk on iOS. And it worked. Now I have a new PC and there is a new Blynk app on iOS.

I will try to describe what I’ve done since the guide is in Russian. Please note that I’m completely noob in this kind of things and did everything according to the guide.

  • I downloaded the latest Python and installed it on my Windows 11 (yes, I did the %PATH% thing). Also I downloaded some libs. I used these commands:
    • python -m pip install --upgrade pip
    • pip install blynklib
    • pip install pyautogui.
  • I created blynk_2.0 folder in C:/Program Files/ where I placed some files. Here is the descriptions from the guide what these files do:
    • blynk.py - the main body of the script.
    • config.py - configuration file.
    • install_libs.bat is a script for installing python libraries from the chapter “Installing Python”.
    • nircmd.exe - command-line extension utility.
    • start.bat is a batch file for running the script in normal mode.
    • start_hide.bat is a batch file for running the script in hidden mode.
    • close_script.bat is a batch file for closing a script that works in hidden mode.
  • If you want to see the code of the scripts, you can download these files here.
  • I registered myself in the new Blynk app on iOS 15.2.1.
  • In the app I had to improvise and try to understand it by myself, because in the guide the legacy app was used. So I did this, step by step: Add new device > Quickstart device > OK. I’m ready! > Hardware: ESP32, Connection type: Wi-Fi. And here I need to stop. When I did it on my old PC, I remember that originally the guide said to use NodeMCU. Now the guide was a little bit changed and now it says that it doesn’t matter what device and connection type to select. Well, it seems logic even for a noob like me. But still in the new app there is no NodeMCU.
  • After I did this I received an e-mail. I figured out where is my auth token.
  • Back to PC. I edited the scripts. In blynk.py I pasted my auth token in BLYNK_AUTH = "myToken". The same I did in config.py. In config.py I also changed the curpath to curpath = "С:\\Program Files\\blynk_2.0" (yes, it should have double slash). The same changes with directories I did in strt.bat and strt_hide.bat.
  • In config.py I also changed third virtual pin to V3=[0,"shutdown /s /f"], so it runs CMD and this command and my PC shuts down.
  • Back to Blynk app. I edited the template. I deleted all pre-installed buttons and added just one button. In Datastream I chose Button Image (v3) so the button triggers that v3 pin on my PC. Some cosmetic changes were also done.
  • Finally I ran strt.bat as an Administrator. The appeared CMD just showed me Blynk logo and… nothing. No errors, no further info. Just a _ pycache _ folder was created in …/blynk_2.0/ folder.

And here is the problem. In the app my device is offline. The button doesn’t work. I tried to trigger the virtual pin via webhook https: . //blynk-cloud . com/my_token/update/V3?value=1, but it also didn’t work. Actually this guide leads to this webhook that I should connect via some workarounds to the voice assistant. But to do so I need Blynk working.

I tried to explain everything as detailed as I can. I double checked the tokens, actually I recreated them six times. I even connected to the same local network, even if it is not necessary. So the question is, how to make it work? If the solution need additional information, I’ll try to provide it. Thank you.

That is the server url and the webhook syntax for Blynk Legacy.
The Blynk IoT server is different, and the syntax is different.
The documentation is here…
https://docs.blynk.io/en/blynk.cloud/https-api-overview

Also, I think you’ll need to ensure that you are using this Python library file:

with the server name of blynk.cloud at line 212

Pete.

1 Like

Thank you for your help.

I get the library file via Command Prompt by pip install blynklib, so I think it should be the correct one. At least I can’t understand how to ensure.

Nevertheless I’ve read the new syntax and did this:
https://blynk.cloud/external/api/update?token=MYTOKEN&v3=100
This URL I pasted in online service for testing APIs and… the response is “Invalid token”. I can’t understand why is it invalid if I just copied and pasted it from Blynk Example Browser from the field Auth Token.

So I tried to do it via Blynk.Console in browser on my PC. I created a new template. I chose ESP32 and Wi-Fi. I created a new device using this template and in Device Info I copied the token. I paste it in blynk.py, config.py and in this URL and nothing works. The device is still offline and the API response says that the token is incorrect. I just can’t understand why is it incorrect.

You should read this

Oh… I edited my URL to https://fra1.blynk.cloud/external/api/update?token=MYTOKEN&v3=100 and response was 200 (OK). Anyway, device is still offline and I think I found how to solve it.

As it was mentioned above at line 212 in blynklib.py there should be written blynk.cloud. Maybe I need to edit it to fra1.blynk.cloud? If yes, where can I find this file?

Try searching your PC for the file.

Pete.

Well, I found it. Also the content of my blynklib.py differed from that what you sent, soI just pasted the correct code. Also I changed blynk.cloud to fra1.blynk.cloud. And we have a progress. But there is another problem appeared, which actually doesn’t relate to the topic. After running strt.bat in CMD I see this:
Connecting to fra1.blynk.cloud:443...
Traceback (most recent call last):
File "C:\blynk_2_0\blynk.py", line 62, in <module>
@ blynk.handle_event('write V0') #данный пин используем для управления общей громкостью ПК
AttributeError: 'Blynk' object has no attribute 'handle_event'

What’s wrong now? It looks like syntax error. But there were no such issues on my old PC considering that the files provided in the guide were not changed.

Looks like the syntax might have changed.
You should read the “Usage Example” section here…

Pete.

Ok then, thanks for your help. Seems like an end for me, because I understand absolutely nothing in it.

I’ve been playing around with this on my Win10 machine, using Python 2.7 and I think I have it working.

Step 1 (you’ve already done this)
Ensure that the blynklib.py file contains the correct code.
In my case that file lives at:
C:\Python27\Lib\site-packages
The correct contents is in this file:

Step 2
Edit the C:\blynk_2_0.blynk.py file as follows…

Each virtual pin handler needs to change from this format…

@blynk.handle_event('write V1')                           <<< Changed
def write_virtual_pin_handler(pin, value):                <<< Changed
    valuepin = str(value)[2:3]                            <<< Changed
    pinname = config.V1
    if valuepin == "1":
        workwithpin(pinname)
    elif valuepin == "0":
        print ("Выключено")
    else:
        ctypes.windll.user32.MessageBoxW(0, "Формат данного виртуального пина указан неверно в приложении Blynk.", "Blynk Controller by Xottabb14", 0)

to this format…

@blynk.on("V3")
def write_virtual_pin_handler(value):
    valuepin = str(value)[3:4]
    pinname = config.V1
    if valuepin == "1":
        workwithpin(pinname)
    elif valuepin == "0":
        print ("Выключено")
    else:
        ctypes.windll.user32.MessageBoxW(0, "Формат данного виртуального пина указан неверно в приложении Blynk.", "Blynk Controller by Xottabb14", 0)

As you’ll see, the first three lines of each virtual pin handler block of code is changed.
If you do some careful search and replacement you can make the changes without the need to manually edit all 50 of them :grinning:

Pete.

1 Like