#!/bin/env python
# Read a crude temperature from an Owon B41T+, and compensate it for fixed bias.
# Written August, 2024 by Andrew Robinson of Scappoose.
# Version 0.99.0
# This code is released under the GNU public license, 3.0
# https://www.gnu.org/licenses/gpl-3.0.en.html
import sys
from subprocess import Popen, PIPE
import math
if len(sys.argv) != 2 :
print( "Command format is: %s meter_name", sys.argv[0], file=sys.stderr )
quit(1)
meterID=sys.argv[1]
alias,mac,Tc,To,Tz,Tb="","",0,0,0,0
f=open( "calibration_owon.txt", 'r' )
for calibration in f:
alias, mac, Tc, To, Tz, Tb = calibration.split()
if (alias==meterID or mac.upper()==meterID.upper() ):
break
else:
print( "MeterID %s not found in calibration_owon.txt", meterID )
quit(1)
Tc,To,Tz,Tb=float(Tc),float(To),float(Tz),float(Tb)
f.close()
f=open( "thermlog_"+alias+".dat",'w' )
print( "Thermal data log\n",file=f)
f.flush()
lastval,jitterval,count=0,0,0
with Popen(["stdbuf","-oL","owon_multi_cli","-a",mac,"-t","bt41"], stdout=PIPE) as p:
while True:
text=p.stdout.read1().decode("utf-8")
sample=text.split(' ')
if (sample[2]!='Deg'):
print("Meter is in wrong mode")
quit()
time,val,units,x =sample
val=float(val)
count+=1
if (count<100) and (( val == lastval ) or ( val == jitterval )): continue
count=0
if ( abs(val-lastval)>1.5 ):
lastval=(val+lastval)/2. # Block spurious jumps
jitterval=lastval
continue
jitterval=lastval
lastval=val
print( time,(" %6.2f"%(val-To))," ",units,x.strip(), file=f )
print( "\r\t%6.1f %s%s\t"%( val-To, units, x.strip()), end="" )
f.flush()
|