Bash script to send data to Radmon from Mygeiger ver.3 PRO (serial over USB)

More
4 months 5 days ago - 4 months 5 days ago #5734 by pilovis
#!/bin/bash
####################################################################################
##serial port setup
#stty -F /dev/ttyUSB0 speed 9600 cs8 -parenb -cstopb
## continuously print values in a file
#(stty raw; cat > /tmp/received.txt) < /dev/ttyUSB0
## continuously print values in console
#echo | (stty raw; cat) < /dev/ttyUSB0
## print one value in console
#/usr/bin/head -n1 /dev/ttyUSB0
###################################################################################
## by pilovis 2109 Italy - www.vinchio.org
###################################################################################
# main loop (infinite)
while true
do
# CPM reading loop (60 seconds)
while true
do
# populate a tmp file with CPM data received from USB serial connection, one read per line
cat /dev/ttyUSB0 > /tmp/received.txt
# send reading loop to background and go further
done &
# count 60 seconds and then stop the CPM reading loop and the serial data reading / file writing
pid=$!
/bin/sleep 60 && kill -TERM $pid; killall cat
/bin/sleep 1
# calculate the mean value of the readings and insert the integer value rounded to the CPM variable
cpm=$(/usr/bin/awk '{ total += $1; count++ } END { print total/count }' /tmp/received.txt | /usr/bin/awk '{printf("%.f\n",$0)}')
# insert CPM value in a tmp file, updated every minute
/bin/echo $cpm > /tmp/cpm.txt
# calculate uSv/h value from CPM and put it in a tmp file, updated every minute
/bin/sed 's/$/ * .0057/' /tmp/cpm.txt | /usr/bin/bc | /usr/bin/awk '{printf("%.2f\n", $1)}' > /tmp/usvh.txt
# send CPM data to radmon.org
/usr/bin/curl -s "radmon.org/radmon.php?function=submit&us...&value=$cpm&unit=CPM"
# change myuser & mypass in the above line with your radmon login data
/bin/sleep 7
# OPTIONAL: notify alarm if CPM is above the alarm level
alarm=75 # alarm level
if [ $cpm -gt $alarm ];
then
/bin/echo "Alarm CPM = "$cpm > /dev/null 2>&1;
# put your alarm on script here
#/bin/echo 1 > /sys/class/gpio/gpio1/value # switch on GPIO1
else
/bin/echo "everything is normal" > /dev/null 2>&1;
# put your alarm off script here
#/bin/echo 0 > /sys/class/gpio/gpio1/value # switch off GPIO1
fi;
# wait 10 seconds and then restart main loop
/bin/sleep 10
done
Last edit: 4 months 5 days ago by pilovis.
The following user(s) said Thank You: mw0uzo

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

More
4 months 5 days ago #5735 by pilovis

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

More
4 months 3 days ago #5737 by mw0uzo

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

Time to create page: 0.156 seconds
Powered by Kunena Forum
Solar powered Raspberry Pi 4 server stats: CPU 66% Memory 15% Swap 14% CPU temp=62.3'C Uptime 47 Days