Also, if you add
if not blynk.connected(): return
To the timer callback function that toggles the button widget, the program will at least not crash
Also, if you add
if not blynk.connected(): return
To the timer callback function that toggles the button widget, the program will at least not crash
Do you guys realise that you can no longer use SSL with the Blynk cloud servers?
Pete.
@PeteKnight apparently you can if you connect without authenticating the certificate (as it has expired)
I jsut did and the authentication failed
Sounds like something that changed during the last year+ when I stopped using Blynk altogether Darn, forgot to RTFM
So @Gunner now that you can connect with verification set to NONE, can you try the local server again?
Pete.
Set the socket timeout back to 0.05 and replace the line:
response = BlynkMessage.ReadSocketMessage(self.__recv_bytes)
in the __authenticate method with:
for attempt in range(20):
try:
response = BlynkMessage.ReadSocketMessage(self.__recv_bytes)
break
except BlynkTimeoutError:
pass
Don’t forget to check the indentation
This will keep the timeout at 0.05 seconds and loop up to 20 times waiting for an authentication response from the Blynk server
THanks for that, that would be due to the certificate expiring earlier this year
Validity
Not Before: Mar 17 11:58:07 2016 GMT
Not After : Mar 16 11:58:07 2021 GMT
But connecting with no certification required and no checking for host name allows the world to keep on going
So does that only impact devices connecting to the cloud using SSL or the mobile phone app as well?
OK, I think I go this done.
And I think I found the function… but where to add?
# Called every 30 seconds to request the server to send the push or release the button widget in the dashboard
@timer.register(interval=30, run_once=False)
def toggle_door_button():
"""Toggle the current value (in blynkapp['widgets']['button']['value']) between 1 and 0 and then write that value to the dashboard"""
global blynkapp
blynkapp['widgets']['button']['value'] = int(blynkapp['widgets']['button']['value']) + 1
if blynkapp['widgets']['button']['value'] >= 2: blynkapp['widgets']['button']['value'] = 0
blynk.virtual_write('{}-{}'.format(blynkapp['id'], blynkapp['widgets']['button']['device']),
blynkapp['widgets']['button']['pin'], blynkapp['widgets']['button']['value'])
Right under the “global blynkapp” line
As a Python neophyte I have no idea what “lead cap” is… but I can almost understand the word “Global”
So, like this?..
global blynkapp
if not blynk.connected(): return
Yes, exactly like that
The function gets called everytime the timer triggers (from memory every 3 seconds after the program starts)
In the function
global blynkapp
States that tehre is a variable called blynkapp that happens to be a global variable
The line I asked you to add calls the blynk class created earlier and asks it to return the result of connected() which is true when authentication is complete and false otherwise
So in this case, everytime the timer triggers, if we are not connected the function will do nothing (just return)
My Blynk Server hates me…
2021-06-14 01:36:27,672 [INFO] Authenticating user: <REDACTED>@gmail.com
2021-06-14 01:36:27,688 [DEBUG] Sending BlynkLoginMessage - BlynkCommand(Login) ID(1): ['<REDACTED>@gmail.com', 'ZvA1i+O1MUmo+TkxqztW5VlQiFBKvfPvWQhQdCDPGhQ=', 'Python App', '0.2.6_app', 'Blynk']
2021-06-14 01:36:27,750 [DEBUG] Received BlynkMessage - BlynkCommand(Response) ID(1): [3]
2021-06-14 01:36:27,813 [ERROR] Auth stage failed: User not registered
Too many servers… OK this time I tried my original one on the RPi (last time was my .ddns.net)
2021-06-14 01:39:43,308 [INFO] Connecting to 10.10.3.13:9443
2021-06-14 01:39:43,324 [INFO] Using SSL socket...
2021-06-14 01:39:43,558 [INFO] Connection to Blynk server established
2021-06-14 01:39:43,574 [DEBUG] Request(auth details)
2021-06-14 01:39:43,574 [INFO] Authenticating user: <REDACTED>@gmail.com
2021-06-14 01:39:43,574 [DEBUG] Sending BlynkLoginMessage - BlynkCommand(Login) ID(1): ['<REDACTED>@gmail.com', 'ZvA1i+O1MUmo+TkxqztW5VlQiFBKvfPvWQhQdCDPGhQ=', 'Python App', '0.2.6_app', 'Blynk']
2021-06-14 01:39:43,605 [DEBUG] Received BlynkMessage - BlynkCommand(Response) ID(1): [200]
2021-06-14 01:39:43,621 [INFO] User successfully authenticated
2021-06-14 01:39:43,621 [DEBUG] Event(connect) -> ()
2021-06-14 01:39:43,621 [INFO] Requesting user profile/dashboards
2021-06-14 01:39:43,621 [DEBUG] Sending BlynkMessage - BlynkCommand(Load Profile) ID(2): []
2021-06-14 01:39:43,636 [DEBUG] Recording message awaiting reply BlynkMessage - BlynkCommand(Load Profile) ID(2): []
2021-06-14 01:39:44,324 [ERROR] Message length error: Received 16377 bytes, expected 18547
2021-06-14 01:39:44,402 [WARNING] Unhandled Event(disconnect) -> ()
At least you now have gotten to the authentication stage, the app is sending the login message and the Blynk server is responsing with (1) which equals the Blynk Command Response and the response code 3 which equals User not registered, so that username is not registered as a valid user on the Blynk server you are connecting to
I run my Blynk server on a real server, not a Raspberry Pi, perhaps the Pi is too slow to send the data and the message is not being read all in real time
Try again to increase the Timeout, perhaps from 0.05 to 0.10 and see if that helps
I’ll add to this, the library reads the first 7 bytes from the server. If there is NO data at all, it assumes there is no message at present and so just returns and tries again later
If seven bytes is read, it parses the header, figures out how many more bytes to read and then grabs those as well, all in one go. If it doesn’t get all those bytes in one hit then it fails with the error you saw
Well… I am not a real programmer, so it fits
Well, I adjusted the SOCK_TIMEOUT a bit (it is an old RPi3 ) between 0.05 and 1 but still the same error.
I am wondering if I missed a step, as even at 1 seconds the loop is immediate, not the expected “20 times waiting for an authentication” … or am I mixing two issues /patches here (look at me, trying to think but nothing happens )
2021-06-14 01:57:44,776 [INFO] User successfully authenticated
2021-06-14 01:57:44,776 [DEBUG] Event(connect) -> ()
2021-06-14 01:57:44,776 [INFO] Requesting user profile/dashboards
2021-06-14 01:57:44,791 [DEBUG] Sending BlynkMessage - BlynkCommand(Load Profile) ID(2): []
2021-06-14 01:57:44,791 [DEBUG] Recording message awaiting reply BlynkMessage - BlynkCommand(Load Profile) ID(2): []
2021-06-14 01:57:44,869 [ERROR] Message length error: Received 16377 bytes, expected 18704
2021-06-14 01:57:44,932 [WARNING] Unhandled Event(disconnect) -> ()