Why not make the programs in Python3?

More
2 years 3 weeks ago #6249 by oz1ewr
It is working, from a browser, but how du i implement it in a Python-schript????
oz1ewr

Please Log in or Create an account to join the conversation.

More
2 years 3 weeks ago - 2 years 3 weeks ago #6251 by whyza
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
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
Powered by Kunena Forum
Everything's free. Please support us by considering a donation. Log in first!
Solar powered Raspberry Pi 4 server stats: CPU 47% Memory 23% Swap 70% CPU temp=52.1'C Uptime 72 Days