Serial Volt/Amp meter

Moderator: Mattk

pinto
Junior Boarder
Junior Boarder
Posts: 23
Joined: Thu Apr 14, 2011 7:33 pm
Contact:

Re: Serial Volt/Amp meter

Post by pinto » Wed Jun 13, 2012 10:18 pm

GNU grep 2.6.3

So, different grep, sorry
I have a working script here on debian squeeze, with multiplication included, but it seems I can't help you because the differences in our systems.
Just in case someone wants to try:

Code: Select all

#! /bin/sh
#
while :
do
WhatWeRead=$(grep -m 1 V /dev/ttyUSB0)

# Format reading
volt=`echo $WhatWeRead | cut -c -7`
amp=`echo $WhatWeRead | cut -c 10-16`
watt=`echo $WhatWeRead | cut  -c 19-25`
wattH=`echo $WhatWeRead | cut -c 28-34`
echo data20 $(printf "%0.0f" $(echo "$volt*100"|bc))"\n"data21 $(printf "%0.0f" $(echo "$amp*100"|bc))"\n"data22 $(printf "%0.0f" $(echo "$watt*100"|bc))"\n"data23 $(printf "%0.0f" $(echo "$wattH*100"|bc));
sync
sleep 30
done
Sorry again :cry:

pterodyne
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: Tue May 01, 2012 7:46 pm

Re: Serial Volt/Amp meter

Post by pterodyne » Wed Jun 13, 2012 10:39 pm

used ipkg install grep to get a different version, now it supports -m


New lines aren't working though

root@sioweather:/home/meteohub$ sh load.sh
data20 13.3\ndata21 2.0\ndata22 26.4\ndata23 514.0

pterodyne
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: Tue May 01, 2012 7:46 pm

Re: Serial Volt/Amp meter

Post by pterodyne » Wed Jun 13, 2012 10:55 pm

Ok, I think it will work now as this is what I did:

Code: Select all

#! /bin/sh
#
while :
do
WhatWeRead=$(grep -m 1 V /dev/ttyUSB0)

# Format reading
volt=`echo $WhatWeRead | cut -c -7`
amp=`echo $WhatWeRead | cut -c 10-16`
watt=`echo $WhatWeRead | cut  -c 19-25`
wattH=`echo $WhatWeRead | cut -c 28-34`
echo data20 $(printf "%0.1f" $(echo "$volt"))"
"data21 $(printf "%0.1f" $(echo "$amp"))"
"data22 $(printf "%0.1f" $(echo "$watt"))"
"data23 $(printf "%0.1f" $(echo "$wattH"));
sync
sleep 30
done
with the output of:

Code: Select all

root@sioweather:/home/meteohub$ sh load.sh
data20 12.8
data21 2.1
data22 26.5
data23 514.0

pterodyne
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: Tue May 01, 2012 7:46 pm

Re: Serial Volt/Amp meter

Post by pterodyne » Wed Jun 13, 2012 11:02 pm

Alright so that works!

One last thing:

Actual Sensors are /100 in your syntax, how would I *100 so the values come out right on the sensors?
Type # ID Name Last Signal Sensor Data
unknown 20 1 sec 0.13
unknown 21 1 sec 0.02
unknown 22 1 sec 0.26
unknown 23 1 sec 5.14
Station 2 (Plug-in): Charge Monitor
Type # ID Name Last Signal Sensor Data
unknown 24 1 sec -0.21
unknown 25 1 sec -0.05
unknown 26 1 sec 1.13
unknown 27 1 sec 6.29

pinto
Junior Boarder
Junior Boarder
Posts: 23
Joined: Thu Apr 14, 2011 7:33 pm
Contact:

Re: Serial Volt/Amp meter

Post by pinto » Wed Jun 13, 2012 11:08 pm

Code: Select all

echo data20 $(printf "%0.0f" $(echo "$volt*100"|bc))"\n"data21 $(printf "%0.0f" $(echo "$amp*100"|bc))"\n"data22 $(printf "%0.0f" $(echo "$watt*100"|bc))"\n"data23 $(printf "%0.0f" $(echo "$wattH*100"|bc));
that is, IF you have "bc" installed.

pterodyne
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: Tue May 01, 2012 7:46 pm

Re: Serial Volt/Amp meter

Post by pterodyne » Thu Jun 14, 2012 12:11 am

Thanks pinto! Up and running now...

Final script for posterity:

Code: Select all

#! /bin/sh
#
while :
do
WhatWeRead=$(grep -m 1 V /dev/ttyUSB0)

# Format reading
volt=`echo $WhatWeRead | cut -c -7`
amp=`echo $WhatWeRead | cut -c 10-16`
watt=`echo $WhatWeRead | cut  -c 19-25`
wattH=`echo $WhatWeRead | cut -c 28-34`
echo data20 $(printf "%0.1f" $(echo "$volt*100"|bc))"
"data21 $(printf "%0.1f" $(echo "$amp*100"|bc))"
"data22 $(printf "%0.1f" $(echo "$watt*100"|bc))"
"data23 $(printf "%0.1f" $(echo "$wattH*100"|bc));
sync
sleep 30
done
Not sure about the "/n" that Pinto had originally, but just hard returns in the script seemed to work fine for me.

Post Reply