Comments (5)
Hi Saul!
- What library version you are using ? ( you can get version from library headers)
I suggest to ensure that this is the latest stable one 0.2.6 - Let's add logging and see what goes on .
This example can be useful to understand how we can add additional logging
https://github.com/blynkkk/lib-python/blob/master/examples/07_tweet_and_logging.py
You will be able to get info about registered handlers and events when they appear.
Let's get these logs and then continue issue investigation
from lib-python.
Hi, thanks for the info.
I'm going to update the Library to 0.2.6 (the scripts use the 0.2.5). Then I will monitor the callback calling of scripts.
from lib-python.
Ok here we go.
Using version 0.2.6, now the onDisconnect callback is correctly called.
Discconnection problems are still there. But for now I'm solved It using systemd watchdog
If you want to go deeply on disconnect problem, I will going to show You test I did.,
First of all, using Blynk API, every minutes both scripts blynk_dht
and blynk_switch_hub
make a request like:
request = Request('http://<blynkserver>/<token>/isHardwareConnected')
So every script known if get disconnected, from Blynk server.
The API call use scripts tokens, and the ip address
of my internal Blynk server.
Also every minutes the script will send a WATCHDOG=1
to Systemd for health check.
When Blynk Server reports that one of sensor is offline the respective script will not update systemd WATCHDOG
.
Systemd configurations for the scripts are the following
For blynk_switch_hub.service giving two attempts to ping Watchdog`
WatchdogSec=120`
Restart=on-failure`
RestartSec=10
NotifyAccess=main
For blynk_dht.service giving four attempts to ping Watchdog
WatchdogSec=140 #actually this is too small
RestartSec=10
Restart=on-failure
NotifyAccess=main
Ok started the blynk_switch_hub.service
yesterday at 22:46`:
2020-04-22 22:46:20,318 : DECORATING BLYNK EVENT VPIN 100
2020-04-22 22:46:20,319 : DECORATING BLYNK EVENT VPIN 101
2020-04-22 22:46:20,320 : DECORATING BLYNK EVENT VPIN 102
2020-04-22 22:46:20,321 : DECORATING BLYNK EVENT VPIN 103
2020-04-22 22:46:20,364 : CONNECT EVENT
2020-04-22 22:46:20,366 : GETTING VPIN 100 VALUE FROM SERVER
2020-04-22 22:46:20,369 : WRITE EVENT FOR VPIN 100 VALUE 0
2020-04-22 22:46:20,370 : ENQUEUING BUTTON TYPE rf VPIN 100 VALUE 0
2020-04-22 22:46:20,371 : ENQUEUED BUTTON TYPE rf VPIN 100 VALUE 0
2020-04-22 22:46:20,372 : Updating Blynk server with new Button VPIN 100 VALUE 0
2020-04-22 22:46:22,380 : GETTING VPIN 101 VALUE FROM SERVER
2020-04-22 22:46:22,394 : WRITE EVENT FOR VPIN 101 VALUE 0
2020-04-22 22:46:22,396 : ENQUEUING BUTTON TYPE rf VPIN 101 VALUE 0
2020-04-22 22:46:22,397 : ENQUEUED BUTTON TYPE rf VPIN 101 VALUE 0
2020-04-22 22:46:22,398 : Updating Blynk server with new Button VPIN 101 VALUE 0
2020-04-22 22:46:23,852 : WRITE EVENT FOR VPIN 100 VALUE 1
2020-04-22 22:46:23,854 : ENQUEUING BUTTON TYPE rf VPIN 100 VALUE 1
2020-04-22 22:46:23,854 : ENQUEUED BUTTON TYPE rf VPIN 100 VALUE 1
2020-04-22 22:46:23,855 : Updating Blynk server with new Button VPIN 100 VALUE 1
2020-04-22 22:46:24,408 : GETTING VPIN 102 VALUE FROM SERVER
2020-04-22 22:46:24,413 : WRITE EVENT FOR VPIN 102 VALUE 0
2020-04-22 22:46:24,414 : ENQUEUING BUTTON TYPE rf VPIN 102 VALUE 0
2020-04-22 22:46:24,415 : ENQUEUED BUTTON TYPE rf VPIN 102 VALUE 0
2020-04-22 22:46:24,415 : Updating Blynk server with new Button VPIN 102 VALUE 0
2020-04-22 22:46:24,847 : WRITE EVENT FOR VPIN 100 VALUE 0
2020-04-22 22:46:24,848 : ENQUEUING BUTTON TYPE rf VPIN 100 VALUE 0
Please note the CONNECT EVENT at 2020-04-22 22:46:20,364 and the WRITE EVENT(S)
Today log file dos not report any disconnection event or any restart by Systemd Watchdog.
The blynk_dht.service
was started yesterday at 19:14`:
2020-04-22 19:14:56,980 : BLYNK Decorating READ/WRITE FOR VPIN 10
2020-04-22 19:14:56,982 : BLYNK Decorating READ/WRITE FOR VPIN 11
2020-04-22 19:14:56,983 : BLYNK OR DATABASE DISCONNECTED
2020-04-22 19:14:56,984 : Reading Sensor HW Values
2020-04-22 19:14:56,985 : READING SENSOR
2020-04-22 19:14:57,518 : GOT SENSOR DATA: Temp 23.100000381469727 Hum 52.20000076293945
2020-04-22 19:14:57,558 : ERROR: BLYNK SERVER REPORT WE ARE NOT ONLINE - NO WATCHDOG PINGING
2020-04-22 19:14:57,559 : WE ARE NOT CONNECTEDT NO TRY TO WRITE VALUES ON DB
2020-04-22 19:14:57,561 : DISCONNECTED FROM BLYNK SERVER I'M TRYING TO RECONNECT
2020-04-22 19:14:58,586 : CONNECTED TO BLYNK SERVER
2020-04-22 19:14:58,587 : SEND CURRENT VPIN 10 VALUE TO SERVER
2020-04-22 19:14:58,590 : WRITE EVENT VPIN 10 VALUE ['23.1']
2020-04-22 19:14:58,590 : NO NEED TO UPDATE SENSOR VALUES
2020-04-22 19:14:58,591 : Updating Blynk server Temperature value 23.1
2020-04-22 19:15:00,599 : SEND CURRENT VPIN 11 VALUE TO SERVER
2020-04-22 19:15:00,605 : WRITE EVENT VPIN 11 VALUE ['52.3']
2020-04-22 19:15:00,606 : NO NEED TO UPDATE SENSOR VALUES
2020-04-22 19:15:00,606 : Updating Blynk server Humidity value 52.2
2020-04-22 19:15:47,800 : READ EVENT FOR VPIN 10
2020-04-22 19:15:47,801 : NO NEED TO UPDATE SENSOR VALUES
2020-04-22 19:15:47,802 : Updating Blynk server Temperature value 23.1
Follow a description of service works:
- every minutes poll DHT in order to get Hum and Tem.
- when DHT is readed the results (h & t) are written on Influx database. InfluxDb is on the same server of BlynkServer.
- every minutes Blynk API is checked in order to check if sensor is detected from Blynk Server (if online a
WATCHDOG=1
is sent tosystemd
) - every ~45 seconds will update the Blynk server with a DHT sensors values.
this is te main routine:
while True:
if self._isConnected:
self._blynk.run()
self._timer.run()
else:
self.log.warning("BLYNK OR DATABASE DISCONNECTED")
self.updateSensorValue()
self.db = self.getInflux()
self._blynk.disconnect()
self._isConnected = self._blynk.connect(timeout=CONN_TIMEOUT)
instead this is the methods used to get new values from DHT sensor and update Blynk Server_
def sendSensorValue(self, vpin):
# Updating Real sensor values
res = self.updateSensorValue()
if not res:
return
prop = self.sensor["properties"][str(vpin)]
if prop["value"] is not None:
self.log.debug(
"Updating Blynk server {} value {}".format(
prop["name"], prop["value"])
)
self._blynk.virtual_write(vpin, prop["value"])
else:
self.log.info(
"Unable to update Blynk wrong {} value".format(prop["name"])
)
def updateSensorValue(self):
current_time = time.time()
if self._sensor_last_update is None:
self._sensor_last_update = current_time
elif self._sensor_last_update + SENSOR_UPDATE_INTERVAL > current_time:
self.log.debug("NO NEED TO UPDATE SENSOR VALUES")
return True
self._sensor_last_update = current_time
val = self.getSensorValue()
self.ping_watchdog()
if not self._isConnected:
self.log.debug("WE ARE NOT CONNECTEDT NO TRY TO WRITE VALUES ON DB")
return False
res = self.writeInflux(temp=val["Temperature"], hum=val["Humidity"])
if not res:
self._isConnected = False
return res
The first disconnetion occurs at 03:21
2020-04-23 03:21:18,955 : BLYNK SERVER REPORT WE ARE ONLINE - PINGING WATCHDOG
2020-04-23 03:21:18,957 : TRY TO WRITE SENSOR VALUES ON DB
2020-04-23 03:21:18,991 : Updating Blynk server Humidity value 51.0
2020-04-23 03:21:46,117 : READ EVENT FOR VPIN 10
...omissis...
2020-04-23 03:22:31,127 : Reading Sensor HW Values
2020-04-23 03:22:31,128 : READING SENSOR
2020-04-23 03:22:55,843 : GOT SENSOR DATA: Temp None Hum None
2020-04-23 03:22:55,844 : ERROR READING SENSOR DATA
2020-04-23 03:22:55,862 : ERROR: BLYNK SERVER REPORT WE ARE NOT ONLINE - NO WATCHDOG PINGING
** please note **: onDisconnect
event is called, but Blynk server is reachable:
2020-04-23 03:22:55,864 : TRY TO WRITE SENSOR VALUES ON DB
2020-04-23 03:22:55,891 : Unable to update Blynk wrong Temperature value
2020-04-23 03:22:55,892 : READ EVENT FOR VPIN 11
2020-04-23 03:22:55,892 : NO NEED TO UPDATE SENSOR VALUES
2020-04-23 03:22:55,893 : Unable to update Blynk wrong Humidity value
2020-04-23 03:22:55,944 : DISCONNECTED FROM BLYNK SERVER I'M TRYING TO RECONNECT
**No error was reported from InfluxDb Write call **: Blynk server is reachable from Raspberry. Here the InfluxDb call happened because we are still in updateSensorValue
.
Some seconds later on main routine at 2020-04-23 03:23:51,463 the Watchdog has killed and restarted the service.
2020-04-23 03:22:56,996 : BLYNK OR DATABASE DISCONNECTED
2020-04-23 03:22:56,997 : NO NEED TO UPDATE SENSOR VALUES
2020-04-23 03:22:57,000 : DISCONNECTED FROM BLYNK SERVER I'M TRYING TO RECONNECT
2020-04-23 03:22:58,016 : CONNECTED TO BLYNK SERVER
2020-04-23 03:22:58,017 : SEND CURRENT VPIN 10 VALUE TO SERVER
2020-04-23 03:22:58,021 : WRITE EVENT VPIN 10 VALUE ['22.0']
2020-04-23 03:22:58,022 : NO NEED TO UPDATE SENSOR VALUES
2020-04-23 03:22:58,022 : Unable to update Blynk wrong Temperature value
2020-04-23 03:23:00,029 : SEND CURRENT VPIN 11 VALUE TO SERVER
2020-04-23 03:23:00,035 : WRITE EVENT VPIN 11 VALUE ['51.0']
2020-04-23 03:23:00,036 : NO NEED TO UPDATE SENSOR VALUES
2020-04-23 03:23:00,036 : Unable to update Blynk wrong Humidity value
2020-04-23 03:23:16,199 : READ EVENT FOR VPIN 10
2020-04-23 03:23:16,200 : NO NEED TO UPDATE SENSOR VALUES
2020-04-23 03:23:16,201 : Unable to update Blynk wrong Temperature value
2020-04-23 03:23:51,463 : BLYNK Decorating READ/WRITE FOR VPIN 10
2020-04-23 03:23:51,465 : BLYNK Decorating READ/WRITE FOR VPIN 11
2020-04-23 03:23:51,473 : BLYNK OR DATABASE DISCONNECTED
2020-04-23 03:23:51,474 : Reading Sensor HW Values
From the first disconnection events during the night it randomly occurs every ten minutes.
Thank you for your support.
from lib-python.
Hi Saul! Looks like present some issue within heartbeat mechanism.
- Library init can have such additional params:
token, server='blynk-cloud.com', port=80, ssl_cert=None, heartbeat=10, rcv_buffer=1024,
log=stub_log
I suggest to check heartbeat time settings on server side if such present. This time shows in seconds how often we should send aka ping event to server. And based on this pings Server brings decision disconnect or not disconnect client. ( I think you can catch these events on your internal Blynk server just by increasing log verbosity)
Main idea check to play with heartbeat params - set it 5/15/20 and in parallel increase server logs verbosity and try to find more detailed info about disconnections.
- If 1. will give nothing. You can add additional logs to library
def is_server_alive(self):
call maybe we can have some gaps with timing ...
You can just print now/rcv_delta/ping_delta/send_delta values to see if any gap in their calculation
Anyway lets continue investigation!
from lib-python.
No reply for two months. Can be closed.
from lib-python.
Related Issues (20)
- How to use LCD with python library? HOT 2
- Catching generic button events possible? HOT 3
- TimerError. HOT 3
- How long a simple blynk.run() from examples complete? HOT 7
- Terminal is not updated HOT 2
- Update blynk timer interval HOT 2
- Update Time Input Widget HOT 1
- It is unable to send or receive data HOT 8
- Unable to import blynklib while using esp8266 HOT 2
- Joystick don't send 2nd value from blynk app HOT 1
- How can I read multiple sensor data with blynk app and python? HOT 2
- virtual_write for map widget point updates HOT 8
- Cannot authenticate to server and test fail HOT 10
- Displaying OpenWeather Data on Blynk Gauge
- Not working 👎🏻
- Invalid auth token for Blynk console 2.0 HOT 3
- "AttributeError: type object 'Blynk' has no attribute 'handle_event'"
- Blynk 2.0 auth not working HOT 1
- Blynk 2.0 auth not working #2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lib-python.