Why not make the programs in Python3?
2 years 3 weeks ago #6249
by oz1ewr
Replied by oz1ewr on topic Why not make the programs in Python3?
It is working, from a browser, but how du i implement it in a Python-schript????
oz1ewr
oz1ewr
Please Log in or Create an account to join the conversation.
2 years 3 weeks ago - 2 years 3 weeks ago #6251
by whyza
Replied by whyza on topic Why not make the programs in Python3?
While I am no scripting guru, I use the following bash script to collect serial data from a MightyOhm Geiger counter and submit to radmon.org via a Raspberry Pi4
The MightyOhm Geiger displays serial data in the following format
CPS, 3, CPM, 16, uSv/hr, 0.09, SLOW
Change USERNAME, PASSWORD and serial port AMA1 to suit.
#!/bin/bash
#cleanup any orphaned files
rm /tmp/cpm 2>/dev/null
rm /tmp/cpmavg 2>/dev/null
count=0
printf "Initial Counter: %d\n" $count
while true
do
while [ $count -lt 60 ]
do
#Extract the 4th field from the serial data to get CPM value
stty -F /dev/ttyAMA1 9600
read -r CPM < /dev/ttyAMA1
upload=$(echo "$CPM" | cut -d, -f 4)
echo "$upload" >> /tmp/cpm
printf "Read serial port CPM: %d\n" $upload
let count++
printf "#Seconds Counter: %d\n" $count
done
#calculate the 60 second average and submit to radmon
count=0; total=0; for i in $( awk '{ print $1; }' /tmp/cpm );do total=$(echo $total+$i | bc ); ((count++)); done; echo "scale=0; $total / $count" | bc > /tmp/cpmavg
read -r up < /tmp/cpmavg
printf "Attempting Upload of Average: %d\n" $up
exec=`wget -q -O /dev/null "http://radmon.org/radmon.php?function=submit&user=USERNAME&password=PASSWORD&value=$up&unit=CPM"`
rm /tmp/cpm
count=0
done
The MightyOhm Geiger displays serial data in the following format
CPS, 3, CPM, 16, uSv/hr, 0.09, SLOW
Change USERNAME, PASSWORD and serial port AMA1 to suit.
#!/bin/bash
#cleanup any orphaned files
rm /tmp/cpm 2>/dev/null
rm /tmp/cpmavg 2>/dev/null
count=0
printf "Initial Counter: %d\n" $count
while true
do
while [ $count -lt 60 ]
do
#Extract the 4th field from the serial data to get CPM value
stty -F /dev/ttyAMA1 9600
read -r CPM < /dev/ttyAMA1
upload=$(echo "$CPM" | cut -d, -f 4)
echo "$upload" >> /tmp/cpm
printf "Read serial port CPM: %d\n" $upload
let count++
printf "#Seconds Counter: %d\n" $count
done
#calculate the 60 second average and submit to radmon
count=0; total=0; for i in $( awk '{ print $1; }' /tmp/cpm );do total=$(echo $total+$i | bc ); ((count++)); done; echo "scale=0; $total / $count" | bc > /tmp/cpmavg
read -r up < /tmp/cpmavg
printf "Attempting Upload of Average: %d\n" $up
exec=`wget -q -O /dev/null "http://radmon.org/radmon.php?function=submit&user=USERNAME&password=PASSWORD&value=$up&unit=CPM"`
rm /tmp/cpm
count=0
done
Last edit: 2 years 3 weeks ago by whyza.
Please Log in or Create an account to join the conversation.
Moderators: Gamma-Man
Time to create page: 0.885 seconds