- Forum
- Introductions and FAQ
- Howtos and FAQs
- Bash script to send data to Radmon from Mygeiger ver.3 PRO (serial over USB)
Bash script to send data to Radmon from Mygeiger ver.3 PRO (serial over USB)
3 years 6 months ago - 3 years 6 months 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 "http://radmon.org/radmon.php?function=submit&user=myuser&password=mypassword&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
####################################################################################
##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 "http://radmon.org/radmon.php?function=submit&user=myuser&password=mypassword&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: 3 years 6 months ago by pilovis.
The following user(s) said Thank You: mw0uzo
Please Log in or Create an account to join the conversation.
3 years 6 months ago #5735
by pilovis
Replied by pilovis on topic Bash script to send data to Radmon from Mygeiger ver.3 PRO (serial over USB)
Please Log in or Create an account to join the conversation.
3 years 5 months ago #5737
by mw0uzo
Replied by mw0uzo on topic Bash script to send data to Radmon from Mygeiger ver.3 PRO (serial over USB)
Nice! Thank you pilovis!
Please Log in or Create an account to join the conversation.
Moderators: Gamma-Man
- Forum
- Introductions and FAQ
- Howtos and FAQs
- Bash script to send data to Radmon from Mygeiger ver.3 PRO (serial over USB)
Time to create page: 0.151 seconds