Commit 39c4ebff authored by Erik Asbjørn Mikkelsen Jensen's avatar Erik Asbjørn Mikkelsen Jensen
Browse files

Initial commit

parents
.idea
vis
credentials
# Pfeiffer Client 3
Upgrade of [https://gitlab.au.dk/ausa/pferiffer-client](https://gitlab.au.dk/ausa/pferiffer-client) for use with python3.
\ No newline at end of file
Line 15 in 'pfeiffer.py'
"if '0403:6001' in hwid and 'FT232R USB UART' in tag: [...]"
is justified via the terminal I/O given as an example below.
In the example, the parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4' yields
ATTRS{idVendor}=="0403"
ATTRS{idProduct}=="6001"
ATTRS{product}=="FT232R USB UART"
in lines 96, 95 and 123 of this text file respectively.
----------------------------------------------------------
user@somewhere:~> dmesg | grep ttyUSB
[151312.909912] usb 2-1.6: FTDI USB Serial Device converter now attached to ttyUSB0
[151940.438598] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[151942.488927] usb 2-1.4: FTDI USB Serial Device converter now attached to ttyUSB0
user@somewhere:~> udevadm info --name=/dev/ttyUSB0 --attribute-walk
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.0/ttyUSB0/tty/ttyUSB0':
KERNEL=="ttyUSB0"
SUBSYSTEM=="tty"
DRIVER==""
ATTR{power/async}=="disabled"
ATTR{power/control}=="auto"
ATTR{power/runtime_active_kids}=="0"
ATTR{power/runtime_active_time}=="0"
ATTR{power/runtime_enabled}=="disabled"
ATTR{power/runtime_status}=="unsupported"
ATTR{power/runtime_suspended_time}=="0"
ATTR{power/runtime_usage}=="0"
looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.0/ttyUSB0':
KERNELS=="ttyUSB0"
SUBSYSTEMS=="usb-serial"
DRIVERS=="ftdi_sio"
ATTRS{latency_timer}=="16"
ATTRS{port_number}=="0"
ATTRS{power/async}=="enabled"
ATTRS{power/control}=="auto"
ATTRS{power/runtime_active_kids}=="0"
ATTRS{power/runtime_active_time}=="0"
ATTRS{power/runtime_enabled}=="disabled"
ATTRS{power/runtime_status}=="unsupported"
ATTRS{power/runtime_suspended_time}=="0"
ATTRS{power/runtime_usage}=="0"
looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.0':
KERNELS=="2-1.4:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="ftdi_sio"
ATTRS{authorized}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bInterfaceClass}=="ff"
ATTRS{bInterfaceNumber}=="00"
ATTRS{bInterfaceProtocol}=="ff"
ATTRS{bInterfaceSubClass}=="ff"
ATTRS{bNumEndpoints}=="02"
ATTRS{interface}=="FT232R USB UART"
ATTRS{power/async}=="enabled"
ATTRS{power/runtime_active_kids}=="0"
ATTRS{power/runtime_enabled}=="enabled"
ATTRS{power/runtime_status}=="suspended"
ATTRS{power/runtime_usage}=="0"
ATTRS{supports_autosuspend}=="1"
looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4':
KERNELS=="2-1.4"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{authorized}=="1"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{bConfigurationValue}=="1"
ATTRS{bDeviceClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bMaxPacketSize0}=="8"
ATTRS{bMaxPower}=="90mA"
ATTRS{bNumConfigurations}=="1"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bcdDevice}=="0600"
ATTRS{bmAttributes}=="a0"
ATTRS{busnum}=="2"
ATTRS{configuration}==""
ATTRS{devnum}=="6"
ATTRS{devpath}=="1.4"
ATTRS{idProduct}=="6001"
ATTRS{idVendor}=="0403"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="FTDI"
ATTRS{maxchild}=="0"
ATTRS{power/active_duration}=="983004"
ATTRS{power/async}=="enabled"
ATTRS{power/autosuspend}=="2"
ATTRS{power/autosuspend_delay_ms}=="2000"
ATTRS{power/connected_duration}=="983004"
ATTRS{power/control}=="on"
ATTRS{power/level}=="on"
ATTRS{power/persist}=="1"
ATTRS{power/runtime_active_kids}=="0"
ATTRS{power/runtime_active_time}=="982816"
ATTRS{power/runtime_enabled}=="forbidden"
ATTRS{power/runtime_status}=="active"
ATTRS{power/runtime_suspended_time}=="0"
ATTRS{power/runtime_usage}=="1"
ATTRS{power/wakeup}=="disabled"
ATTRS{power/wakeup_abort_count}==""
ATTRS{power/wakeup_active}==""
ATTRS{power/wakeup_active_count}==""
ATTRS{power/wakeup_count}==""
ATTRS{power/wakeup_expire_count}==""
ATTRS{power/wakeup_last_time_ms}==""
ATTRS{power/wakeup_max_time_ms}==""
ATTRS{power/wakeup_total_time_ms}==""
ATTRS{product}=="FT232R USB UART"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="removable"
ATTRS{rx_lanes}=="1"
ATTRS{serial}=="AM00FO8X"
ATTRS{speed}=="12"
ATTRS{tx_lanes}=="1"
ATTRS{urbnum}=="17"
ATTRS{version}==" 2.00"
looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1':
KERNELS=="2-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{authorized}=="1"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{bConfigurationValue}=="1"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceProtocol}=="01"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{bMaxPower}=="0mA"
ATTRS{bNumConfigurations}=="1"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bcdDevice}=="0000"
ATTRS{bmAttributes}=="e0"
ATTRS{busnum}=="2"
ATTRS{configuration}==""
ATTRS{devnum}=="2"
ATTRS{devpath}=="1"
ATTRS{idProduct}=="0024"
ATTRS{idVendor}=="8087"
ATTRS{ltm_capable}=="no"
ATTRS{maxchild}=="8"
ATTRS{power/active_duration}=="23350380"
ATTRS{power/async}=="enabled"
ATTRS{power/autosuspend}=="0"
ATTRS{power/autosuspend_delay_ms}=="0"
ATTRS{power/connected_duration}=="152923268"
ATTRS{power/control}=="auto"
ATTRS{power/level}=="auto"
ATTRS{power/runtime_active_kids}=="1"
ATTRS{power/runtime_active_time}=="23350178"
ATTRS{power/runtime_enabled}=="enabled"
ATTRS{power/runtime_status}=="active"
ATTRS{power/runtime_suspended_time}=="129572807"
ATTRS{power/runtime_usage}=="0"
ATTRS{power/wakeup}=="disabled"
ATTRS{power/wakeup_abort_count}==""
ATTRS{power/wakeup_active}==""
ATTRS{power/wakeup_active_count}==""
ATTRS{power/wakeup_count}==""
ATTRS{power/wakeup_expire_count}==""
ATTRS{power/wakeup_last_time_ms}==""
ATTRS{power/wakeup_max_time_ms}==""
ATTRS{power/wakeup_total_time_ms}==""
ATTRS{quirks}=="0x0"
ATTRS{removable}=="fixed"
ATTRS{rx_lanes}=="1"
ATTRS{speed}=="480"
ATTRS{tx_lanes}=="1"
ATTRS{urbnum}=="130"
ATTRS{version}==" 2.00"
looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2':
KERNELS=="usb2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{authorized}=="1"
ATTRS{authorized_default}=="1"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{bConfigurationValue}=="1"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{bMaxPower}=="0mA"
ATTRS{bNumConfigurations}=="1"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bcdDevice}=="0514"
ATTRS{bmAttributes}=="e0"
ATTRS{busnum}=="2"
ATTRS{configuration}==""
ATTRS{devnum}=="1"
ATTRS{devpath}=="0"
ATTRS{idProduct}=="0002"
ATTRS{idVendor}=="1d6b"
ATTRS{interface_authorized_default}=="1"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Linux 5.14.6-2-default ehci_hcd"
ATTRS{maxchild}=="2"
ATTRS{power/active_duration}=="23350960"
ATTRS{power/async}=="enabled"
ATTRS{power/autosuspend}=="0"
ATTRS{power/autosuspend_delay_ms}=="0"
ATTRS{power/connected_duration}=="152923416"
ATTRS{power/control}=="auto"
ATTRS{power/level}=="auto"
ATTRS{power/runtime_active_kids}=="1"
ATTRS{power/runtime_active_time}=="23350933"
ATTRS{power/runtime_enabled}=="enabled"
ATTRS{power/runtime_status}=="active"
ATTRS{power/runtime_suspended_time}=="129572465"
ATTRS{power/runtime_usage}=="0"
ATTRS{power/wakeup}=="disabled"
ATTRS{power/wakeup_abort_count}==""
ATTRS{power/wakeup_active}==""
ATTRS{power/wakeup_active_count}==""
ATTRS{power/wakeup_count}==""
ATTRS{power/wakeup_expire_count}==""
ATTRS{power/wakeup_last_time_ms}==""
ATTRS{power/wakeup_max_time_ms}==""
ATTRS{power/wakeup_total_time_ms}==""
ATTRS{product}=="EHCI Host Controller"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="unknown"
ATTRS{rx_lanes}=="1"
ATTRS{serial}=="0000:00:1d.0"
ATTRS{speed}=="480"
ATTRS{tx_lanes}=="1"
ATTRS{urbnum}=="64"
ATTRS{version}==" 2.00"
looking at parent device '/devices/pci0000:00/0000:00:1d.0':
KERNELS=="0000:00:1d.0"
SUBSYSTEMS=="pci"
DRIVERS=="ehci-pci"
ATTRS{ari_enabled}=="0"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x0c0320"
ATTRS{companion}==""
ATTRS{consistent_dma_mask_bits}=="32"
ATTRS{d3cold_allowed}=="1"
ATTRS{device}=="0x1e26"
ATTRS{dma_mask_bits}=="32"
ATTRS{driver_override}=="(null)"
ATTRS{enable}=="1"
ATTRS{irq}=="23"
ATTRS{local_cpulist}=="0-7"
ATTRS{local_cpus}=="ff"
ATTRS{msi_bus}=="1"
ATTRS{numa_node}=="-1"
ATTRS{power/async}=="enabled"
ATTRS{power/control}=="on"
ATTRS{power/runtime_active_kids}=="1"
ATTRS{power/runtime_active_time}=="152924992"
ATTRS{power/runtime_enabled}=="forbidden"
ATTRS{power/runtime_status}=="active"
ATTRS{power/runtime_suspended_time}=="0"
ATTRS{power/runtime_usage}=="1"
ATTRS{power/wakeup}=="enabled"
ATTRS{power/wakeup_abort_count}=="0"
ATTRS{power/wakeup_active}=="0"
ATTRS{power/wakeup_active_count}=="0"
ATTRS{power/wakeup_count}=="0"
ATTRS{power/wakeup_expire_count}=="0"
ATTRS{power/wakeup_last_time_ms}=="0"
ATTRS{power/wakeup_max_time_ms}=="0"
ATTRS{power/wakeup_total_time_ms}=="0"
ATTRS{power_state}=="D0"
ATTRS{revision}=="0x04"
ATTRS{subsystem_device}=="0x11d6"
ATTRS{subsystem_vendor}=="0x1734"
ATTRS{uframe_periodic_max}=="100"
ATTRS{vendor}=="0x8086"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
ATTRS{power/async}=="enabled"
ATTRS{power/control}=="auto"
ATTRS{power/runtime_active_kids}=="11"
ATTRS{power/runtime_active_time}=="0"
ATTRS{power/runtime_enabled}=="disabled"
ATTRS{power/runtime_status}=="unsupported"
ATTRS{power/runtime_suspended_time}=="0"
ATTRS{power/runtime_usage}=="0"
ATTRS{waiting_for_supplier}=="0"
user@somewhere:~>
# updated by erik to python3, removing use of python venv, on 2021-10-19
import serial
import re
import time
from influxdb import InfluxDBClient
from influxdb.exceptions import InfluxDBClientError, InfluxDBServerError
from requests.exceptions import Timeout
import serial.tools.list_ports as list_ports
client = None
port = None
for p, tag, hwid in list_ports.comports():
if '0403:6001' in hwid and 'FT232R USB UART' in tag:
port = p
break
if port is None:
raise ValueError("Could not find MRC")
serial = serial.Serial(port=port, baudrate=115200, timeout=1)
ETX = chr(3) # \x03
CR = chr(13)
LF = chr(10)
ENQ = chr(5) # \x05
ACK = chr(6) # \x06
NAK = chr(21) # \x15
STATUS = ["Measurement data okay", "Underrange", "Overrange", "Sensor error", "Sensor off", "No sensor", "Identification error"]
cmd = "PR1" + CR + LF
def do_ask():
serial.write(cmd.encode())
ord(serial.read(1))
ord(serial.read(1))
ord(serial.read(1))
serial.write(ENQ.encode())
string = serial.read(13)
ord(serial.read(1))
ord(serial.read(1))
try:
result = re.search(r"(\d),(.\d\.\d\d\d\d)E(.\d\d)", string.decode())
status = int(result.group(1))
val = float(result.group(2))
exp = float(result.group(3))
v = val*10.0**exp
return v, STATUS[status]
except:
return 0, "Could not understand serial response"
while True:
try:
if client is None:
client = InfluxDBClient(host='host', port=-1, username='user', password='pass', database='database') # ask someone whom you suspect might know
while True:
v, status = do_ask()
fields = {"gauge::float": v}
client.write_points([{
'measurement': 'vacuum_is633',
'fields': fields
}])
time.sleep(5)
except Timeout:
print("Influx problem")
client = None
time.sleep(5)
import serial
import re
import time
import math
from influxdb import InfluxDBClient
from influxdb.exceptions import InfluxDBClientError, InfluxDBServerError
from requests.exceptions import Timeout
import serial.tools.list_ports as list_ports
client = None
port = None
for p, tag, hwid in list_ports.comports():
if '0403:6001' in hwid and 'FT232R USB UART' in tag:
port = p
break
if port is None:
raise ValueError("Could not find MRC")
serial = serial.Serial(port=port, baudrate=115200, timeout=1)
ETX = chr(3) # \x03
CR = chr(13)
LF = chr(10)
ENQ = chr(5) # \x05
ACK = chr(6) # \x06
NAK = chr(21) # \x15
STATUS = ["Measurement data okay", "Underrange", "Overrange", "Sensor error", "Sensor off", "No sensor", "Identification error"]
cmd = "PR1" + CR + LF
def do_ask():
serial.write(cmd)
ord(serial.read(1))
ord(serial.read(1))
ord(serial.read(1))
serial.write(ENQ)
string = serial.read(13)
ord(serial.read(1))
ord(serial.read(1))
try:
result = re.search(r"(\d),(.\d\.\d\d\d\d)E(.\d\d)",string)
status = int(result.group(1))
val = float(result.group(2))
exp = float(result.group(3))
v = val*10.0**exp
return v, STATUS[status]
except:
return 0, "Could not understand serial response"
while True:
try:
if client is None:
client = InfluxDBClient(host='host', port=-1, username='user', password='pass', database='database') # ask someone whom you suspect might know
while True:
v, status = do_ask()
print(v, status)
fields = {"gauge": v}
client.write_points([{
'measurement': 'vacuum_is633',
'fields': fields
}])
time.sleep(5)
except Timeout:
print "Influx problem"
client = None
time.sleep(5);
[Unit]
Description=Pfeiffer influx logger
After=network.service
[Service]
Type=simple
Restart=always
RestartSec=10
StartLimitIntervalSec=0
ExecStart=/usr/bin/python3 /home/is633/source/pfeiffer-client/pfeiffer.py
[Install]
WantedBy=multi-user.target
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment