Linux BASH script for sending to radmon.org

More
10 years 3 weeks ago #63 by OM1AMJ
Because I had some trouble connecting GKnet to geiger counter (probably long cable), so I chose another solution.
I use a router Asus WL-500GP with OpenWrt as APRS iGate, but there is small internal memory and I could not install Python.
Therefore I have created a simple BASH script.
Arduino geiger is connected to the router via a USB-TTL converter CP210X.

Note:
DTR pin must be disconnected (otherwise it may be reset geiger)!!!
In geiger sketch must be set RADLOGGER = true (CPM output only) and LOGGING_PERIOD = 60 (or other value, minimum 30s).
In the BASH script is not setting for interval.
When geiger counter sends a value, the value is immediately sent to radmon.org.



BASH script (/root/radmon_send):
#!/bin/bash

stty -F /dev/ttyUSB0 9600
while read -r line < /dev/ttyUSB0
do

if (( $line > 0 )); then
echo CPM = $line
user="XXXXX"
password="YYYYY"
exec=`wget -O /dev/null "http://radmon.org/radmon.php?function=submit&user=$user&password=$password&value=$line&unit=CPM"`

else
echo CPM = 0

fi
done

And here is the init script (/etc/init.d/radmon_send):
#!/bin/sh /etc/rc.common

START=99
RADMON_SEND_BIN="/root/radmon_send"

start() {
	$RADMON_SEND_BIN > /dev/null
	}

stop() {
	killall radmon_send
}

Finally run command /etc/init.d/radmon_send enable (to start automatically after restart), and reboot.
The following user(s) said Thank You: mw0uzo, Hakunin, nijiwar

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

More
10 years 3 weeks ago #64 by OM1AMJ
I combined the code for the alarm email and BASH code for sending to radmon.org.
Email is sent immediately if the value is exceeded. ;)


BASH script on the router with openwrt (/root/radmon_send):
#!/bin/bash

stty -F /dev/ttyUSB0 9600
while read -r line < /dev/ttyUSB0
do

alarm=60

if (( $alarm > $line )); then
echo CPM = $line
user="XXXXX"
password="YYYYY"
exec=`wget -O /dev/null "http://radmon.org/radmon.php?function=submit&user=$user&password=$password&value=$line&unit=CPM"`

else
echo ALARM!!! CPM = $line
user="XXXXX"
password="YYYYY"
exec=`wget -O /dev/null "http://radmon.org/radmon.php?function=submit&user=$user&password=$password&value=$line&unit=CPM"`
exec=`wget --user=AAAAAA --password=BBBBBB -O /dev/null "http://xxxxx.xxx/geiger_email.php?cpm=$line"`
fi
done


PHP script on webhosting ( http://xxxxx.xxx/geiger_email.php ):
<?php

$cpm = $_GET["cpm"];

//$usvh = round($cpm/122, 4);   //convert CPM to uSv/h (122 is for SI-29BG tube), change to your GM tube
$usvh = round($cpm/175.43, 4);   //convert CPM to uSv/h (175.43 is for SBM-20 tube), change to your GM tube

require_once "Mail.php";

$from = "XXXXX - Radiation alarm <xxxxx@xxxxx.xxx>";   //email sender
$to = "yyyyy <yyyyy@yyyyy.yyy>";   //email recipient
$subject = gmdate("H:i:s e", time())." - $usvh uSvh ($cpm CPM)";   //email subject
$body = gmdate("H:i:s e", time())." - $usvh uSvh ($cpm CPM)";   //email content
$host = "ssl://smtp.xxxxx.xxx";   //mail server host
$port = "465";   //mail server port
$username = "xxxxx";   //username
$password = "yyyyy";   //password
$headers = array ('From' => $from,
'Date' => date('r', time()),
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");}

else {
echo "Background radiation is high!!! Alarm email successfully sent.";
echo "<br />\n";
echo "<br />\n";
echo gmdate("Y-m-d H:i:s e", time());
echo " <br />\n";
echo "$cpm CPM";
echo " <br />\n";
echo "$usvh uSv/h";
}

?>

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

More
10 years 3 weeks ago #70 by mw0uzo
Added a link to this thread on the main Download page :)
The following user(s) said Thank You: OM1AMJ

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

More
10 years 3 weeks ago - 10 years 3 weeks ago #120 by OM1AMJ
Because Radlog does not work on Linux, so I wrote another simple BASH script for basic settings.
I want to thank Daniel (mw0uzo) for a list of commands. ;)

First, you need to edit script radmon_config.
In variables is necessary to uncomment the line conversionfactor for your GM tube.
In the options set experiment_mode to "yes" if you want turn off warnings and alerts.
In the options set set_coordinates to "yes" if you want set coordinates, otherwise sets the center of city (defined in location).
Save config.
Run command ./radmon_config which sends the settings to the server.


BASH script (radmon_config):
#!/bin/bash

######################################################################## Variables ########################################################################
user="XXXXXX"   ## Username
password="YYYYYY"   ## Password
description="Geiger counter with SBM-20 tube"   ## Device, tube, etc...
location="Bratislava, Slovakia"   ## City, country
latitude="48.152133"   ## Latitude DD.dddddd
longitude="17.111706"   ## Longitude DD.dddddd
conversionfactor="0.0057"   ## GM tube conversion factor for SBM-20
# conversionfactor="0.0081"   ## GM tube conversion factor for SI-29BG
# conversionfactor="0.0021"   ## GM tube conversion factor for SBM-19
# conversionfactor="0.0031"   ## GM tube conversion factor for SI-180G
# conversionfactor="0.0117"   ## GM tube conversion factor for SBT-9
# conversionfactor="0.0050"   ## GM tube conversion factor for SBT-11
# conversionfactor="0.0081"   ## GM tube conversion factor for J305 / M4011
# conversionfactor="0.0081"   ## GM tube conversion factor for LND-712
# conversionfactor="0.0024"   ## GM tube conversion factor for LND-7317
# conversionfactor="0.0000"   ## GM tube conversion factor for other
warning="50"   ## Warning level in CPM
alert="100"   ## Alert level in CPM


######################################################################### Options #########################################################################
set_coordinates="yes"   ## Coordinates - "yes" sets coordinates, otherwise sets the center of city (defined in location)
experiment_mode="no"   ## Experiment mode - "yes" turn off warnings and alerts


#####################################################################  Send settings  #####################################################################
exec=`wget -O /dev/null "http://radmon.org/radmon.php?function=updatelocation&user=$user&password=$password&location=$location"` 

if [[ "$set_coordinates" = "yes" ]]; then
exec=`wget -O /dev/null "http://radmon.org/radmon.php?function=setlatitudelongitude&user=$user&password=$password&latitude=$latitude&longitude=$longitude"`
fi

exec=`wget -O /dev/null "http://radmon.org/radmon.php?function=updatedescription&user=$user&password=$password&description=$description"`

exec=`wget -O /dev/null "http://radmon.org/radmon.php?function=setconversionfactor&user=$user&password=$password&value=$conversionfactor"`

exec=`wget -O /dev/null "http://radmon.org/radmon.php?function=setwarnalert&user=$user&password=$password&warn=$warning&alert=$alert"`

if [[ "$experiment_mode" = "yes" ]]; then
exec=`wget -O /dev/null "http://radmon.org/radmon.php?function=setalertsdisabled&user=$user&password=$password"`
else
exec=`wget -O /dev/null "http://radmon.org/radmon.php?function=setalertsenabled&user=$user&password=$password"`
fi
Last edit: 10 years 3 weeks ago by OM1AMJ.
The following user(s) said Thank You: mw0uzo, Vinkx, GandalfDerGraue

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

More
10 years 1 week ago #178 by lp
Hi

I was checking the Arduino Yun model (
) , and I wonder if I could use it to send data from the serial port of my MyGeiger counter to radmon.org. Should not be difficult, what do you think guys ?

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

More
10 years 1 week ago #182 by mw0uzo
Those boards look really interesting! Post your development :cheer:

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

Moderators: Gamma-Man
Time to create page: 0.248 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 34% Memory 23% Swap 69% CPU temp=49.6'C Uptime 72 Days