I’ve got to talk with the 1-Wire folks about why I needed to reverse the characters, but the procedure calculates the gallons per minute flow from the pulse counter outputs.
This turned out to be easier than I thought it would be. I used text funnels to reverse character pairs, as it was only filtering an 8 character string.
pcHex=pcHexResponse[7,8]+pcHexResponse[5,6]+pcHexResponse[3,4]+pcHexResponse[1,2] has the same output as the chunkfilter.
And here’s the whole procedure for context.
Thanks,
Jeff
//Procedure reads log file from pulsecounters.sh, parses data and converts it for gpm readings
call .callingProcedureName
onerror onErrorCode
fileglobal previousTimeStampShell,currentTimeStampShell,loopTimeShell,
currentPulseCounter,pcHexResponse,pcHexResponseFiltered,pcHex,
pcCounter1,pcCounter2,pcCounter3,pcCounter4,
lastpcCounter1,lastpcCounter2,lastpcCounter3,lastpcCounter4,
solarGPCount,solarWPCount,tankPCount,boilerLoopPCount,
solarGHZ,solarLoopHZ,tankHZ,boilerLoopHZ,
logShell,pulseCountersLogShell,chunkNumber,firstRound
define lastpcCounter1,0
define lastpcCounter2,0
define lastpcCounter3,0
define lastpcCounter4,0
define loopTimeShell,10
logShell=""
debug
retryloopaction “logShell=replace(fileload(folder(resourcesPath),"pulsecounters.text"),lf(),cr())”,{sendoneemail "","jhdean@mac.com","ALERT Error loading pulsecounters.text. Check network connection for pulsecounters.",logShell rtn},4
if logShell≠""
pulseCountersLogShell=arrayfirst(arraystrip(arrayfilter(logShell,¶,{?(import() beginswith "A5",import(),"")}),¶),¶)
currentTimeStampShell=val(striptonum(arraystrip(arrayfilter(logShell,¶,{?(import() beginswith "time",import(),"")}),¶))) //PARSE FROM SHELL LOG WHICH USES A MILLISECOND TIMESTAMP. MILLISECONDS SINCE THE EPOCH
define previousTimeStampShell,currentTimeStampShell
if currentTimeStampShell>previousTimeStampShell
loopTimeShell=(currentTimeStampShell-previousTimeStampShell)/1000 // DIFFERENCE IN SECONDS BETWEEN POLL TIMES FROM pulse_counters.text FILE
previousTimeStampShell=currentTimeStampShell
if pulseCountersLogShell[7,10]≠"9000" //FAMILY CODE FOR OW-DI08
rtn //TRY AGAIN, MAY HAVE BEEN READING FROM WRONG DEVICE
endif
chunkNumber=4 //FIRST PULSECOUNTER1 IS CHUNK 5, 1ST FOUR PULSECOUNTERS ARE LAST 32 BYTS OF PAGE 1
local counter
counter=1
loop
pcHex=""
pcHexResponse=chunkarray(pulseCountersLogShell["9",-1],chunkNumber+counter,8) //SAMPLE FROM pulsecounters.text: A5200090000001FFFF000000000000B7000000341A00000000000000000000000000000126
pcHex=pcHexResponse[7,8]+pcHexResponse[5,6]+pcHexResponse[3,4]+pcHexResponse[1,2] // chunkfilter 2,pcHexResponse,pcHexResponseFiltered,assign(import()+pcHex,"pcHex") //REVERSE ORDER OF BYTES
executelocal {pcCounter}+str(counter)+{=radix("hex",pcHex)} //CONVERT TO DECIMAL NUMBER REPRESENTING COUNTER VALUE
counter=counter+1
while counter<5
solarLoopHZ=(pcCounter1-lastpcCounter1)/loopTimeShell
boilerLoopHZ=(pcCounter2-lastpcCounter2)/loopTimeShell
tankHZ=(pcCounter3-lastpcCounter3)/loopTimeShell
solarGHZ=(pcCounter4-lastpcCounter4)/loopTimeShell
debug
SolarGGPM=(0.744*solarGHZ-0.2)*0.264172 //CONVERSION FROM CLARK SOLUTIONS VORTEX FLOW SENSOR DATA SHEET, MAY NEED TO ADJUST FOR GLYCOL 40-50% //Q= 0.744*f-0.2
SolarLoopGPM=(0.744*solarLoopHZ-0.2)*0.264172
TankGPM=(0.744*tankHZ-0.2)*0.264172
BoilerLoopGPM=(0.744*boilerLoopHZ-0.2)*0.264172
SolarGGPM=?(SolarGGPM=-0.05,0.00,?(SolarGGPM>40,1.99,SolarGGPM))
SolarLoopGPM=?(SolarLoopGPM=-0.05,0.00,?(SolarLoopGPM>40,1.99,SolarLoopGPM))
TankGPM=?(TankGPM=-0.05,0.00,?(TankGPM>40,1.99,TankGPM))
BoilerLoopGPM=?(BoilerLoopGPM=-0.05,0.00,?(BoilerLoopGPM>40,1.99,BoilerLoopGPM))
lastpcCounter1=pcCounter1
lastpcCounter2=pcCounter2
lastpcCounter3=pcCounter3
lastpcCounter4=pcCounter4
CyclePeriodGPM=loopTimeShell/60 //CONVERT SECONDS TO MINUTES
rtn //DONE, BACK TO Live
else
previousTimeStampShell=currentTimeStampShell
endif
firstRound=firstRound+1
endif
rtn
RestartPulsecounters.sh: //NOT BEING USED
rtn
//[--Restart Terminal.app to restart pulsecounters.sh script--]
;message "restart T gpmshell."
call .Terminal ;,"restart" ;,"Pulsecounters.app"
restorecurrentproc
//PULSE COUNTER RESET curltimeout oneWireWrite,"http://"+"192.168.50.89"+"/devices.htm?rom="+"2D0010000025E27E"+"&variable=DiscreteIO1PulseCounterReset"+"&value="+"1"