[vz-users] Sensor für Gaszähler verliert Pulse

Tilman Glötzner tilman_1 at gloetzner.net
Mi Okt 5 21:23:44 CEST 2022


Hallo

wie bereits vor kurzen geschrieben, verwende ich einen Kompaßsensor zum 
Detektieren des Magnetes im Gaszähler. Das Zählen der Impulse übernimmt 
ein C-Programm, das die gezählten Impulse über einen Socket zur 
Verfügung stellt. Das unten gezeigte Python-Script holt die gezählten 
Impulse ab und übergibt sie an den Volkszähler, der sie in die Datenbank 
schreibt. Dabei gehen Impulse verloren.

Ich habe nun festgestellt, dass das Pythonscript regelmäßig läuft (siehe 
log in /var/log/syslog). Die Zählerstände landen aber nicht alle in der 
Datenbank.

Woran kann das liegen bzw. wie kann ich das Debuggen?


Danke und Gruß

Tilman


================database  ==============

MariaDB [volkszaehler]> select FROM_UNIXTIME(timestamp/1000),timestamp 
as UNIX,value from data where channel_id = 22 AND 
FROM_UNIXTIME(timestamp/1000) > '2022-10-05 19:45:00';
+-------------------------------+---------------+-------+
| FROM_UNIXTIME(timestamp/1000) | UNIX          | value |
+-------------------------------+---------------+-------+
| 2022-10-05 19:49:40.0000      | 1664992180000 |     0 |
| 2022-10-05 19:50:41.0000      | 1664992241000 |     2 |
| 2022-10-05 19:52:48.0000      | 1664992368000 |     3 |
| 2022-10-05 19:57:54.0000      | 1664992674000 |     2 |
| 2022-10-05 19:58:55.0000      | 1664992735000 |     1 |
| 2022-10-05 20:00:58.0000      | 1664992858000 |     2 |
| 2022-10-05 20:04:02.0000      | 1664993042000 |     1 |
| 2022-10-05 20:05:03.0000      | 1664993103000 |     2 |
| 2022-10-05 20:06:04.0000      | 1664993164000 |     1 |
| 2022-10-05 20:07:05.0000      | 1664993225000 |     0 |
| 2022-10-05 20:19:21.0000      | 1664993961000 |     0 |
| 2022-10-05 20:31:45.0000      | 1664994705000 |     0 |
| 2022-10-05 20:44:01.0000      | 1664995441000 |     0 |
| 2022-10-05 20:56:15.0000      | 1664996175000 |     0 |
+-------------------------------+---------------+-------+

================/var/log/syslog ==============

ct  5 19:50:41 logger /countingmeter.py: 1664992241: Counter = 2; 
TotalCounter = 69
Oct  5 19:51:43 logger /countingmeter.py: 1664992303: Counter = 2; 
TotalCounter = 71
Oct  5 19:52:48 logger /countingmeter.py: 1664992368: Counter = 3; 
TotalCounter = 74
Oct  5 19:53:49 logger /countingmeter.py: 1664992429: Counter = 3; 
TotalCounter = 77
Oct  5 19:54:51 logger /countingmeter.py: 1664992491: Counter = 3; 
TotalCounter = 80
Oct  5 19:55:52 logger /countingmeter.py: 1664992552: Counter = 3; 
TotalCounter = 83
Oct  5 19:56:53 logger /countingmeter.py: 1664992613: Counter = 3; 
TotalCounter = 86
Oct  5 19:57:54 logger /countingmeter.py: 1664992674: Counter = 2; 
TotalCounter = 88
Oct  5 19:58:55 logger /countingmeter.py: 1664992735: Counter = 1; 
TotalCounter = 89
Oct  5 19:59:57 logger /countingmeter.py: 1664992797: Counter = 1; 
TotalCounter = 90
Oct  5 20:00:01 logger CRON[30553]: (root) CMD (flock -n 
/tmp/flock-vz_aggregate.lock php /var/www/volkszaehler.org/bin/aggregate run
  -m delta -l minute >/dev/null)
Oct  5 20:00:58 logger /countingmeter.py: 1664992858: Counter = 2; 
TotalCounter = 92
Oct  5 20:01:01 logger CRON[30939]: (root) CMD (php 
/var/www/volkszaehler.org/bin/aggregate run -m delta -l hour >/dev/null)
Oct  5 20:01:59 logger /countingmeter.py: 1664992919: Counter = 2; 
TotalCounter = 94
Oct  5 20:03:01 logger /countingmeter.py: 1664992981: Counter = 2; 
TotalCounter = 96
Oct  5 20:04:02 logger /countingmeter.py: 1664993042: Counter = 1; 
TotalCounter = 97
Oct  5 20:05:03 logger /countingmeter.py: 1664993103: Counter = 2; 
TotalCounter = 99
Oct  5 20:06:04 logger /countingmeter.py: 1664993164: Counter = 1; 
TotalCounter = 100

============= /etc/vzlogger.conf ===========

.....

{
         // gas counter via i2c daemon and python script
          "enabled": true,
          "allowskip": true,
          "protocol": "exec",
          "command": "countingmeter.py",
          "format": "$t: $i = $v",
          "interval": 60,
          "channels": [{
              "uuid": "3e66af30-3efc-11ed-9625-9f6024cb27ed",
              "identifier": "Counter",
              "api": "volkszaehler",
              "middleware": "http://localhost/middleware.php",
              "aggmode": "sum",
              "duplicates": 720
           }]
         }

============= python script ===========

#!/usr/bin/python3
import datetime
import socket
import json
import syslog

HOST = "127.0.0.1"  # The server's hostname or IP address
PORT = 8888   # The port used by the server

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect(("127.0.0.1", 8888))
string = (s.recv(1024).decode('utf-8'))
#print (string)

data = json.loads(string)
now = str(int( datetime.datetime.now().timestamp() ))

print(now + ': Counter = ' + str(data["counter"]))
print(now + ': TotalCounter = ' + str(data["total"]))
if data["counter"] != 0:
     message = now + ': Counter = ' + str(data["counter"]) + '; 
TotalCounter = ' + str(data["total"])
     syslog.syslog(syslog.LOG_DEBUG, message)



Mehr Informationen über die Mailingliste volkszaehler-users