LostPhoenix
Member
- Joined
- May 20, 2014
- Messages
- 10
- Reaction score
- 4
Hello everyone,
I recently setup a BrewPi using FuzzyWuzzy's post, and have been pretty happy with it. However, I was worried about if one of the relays failed. So I wrote a simple bash script to email me if the fermentation temp gets too high far the set point. I thought some of you might be interested in it.
First thing we need to do is setup the rPi to send emails. I decided to use SMTP Mail.
First connect to your rPi via SSH.
Loading Packages
This will take a few minutes. Answer Y to any prompts.
Setting up Default SMTP Settings
Make the following changes to the fields. If you can't find one of the fields add it to the bottom. I use GMail for this. If you don't use gmail you may need a different STMP address.
When you are finished, press control+o to save. Then control+x to close nano.
Let's test to make sure this is setup properly
In the terminal type paste this
This should take a few seconds to execute, but you should get the email pretty much instantly if you're sending to a gmail account.
Great! Email Works, let's setup alerts
Let's use nano again to setup the Bash Script we're going to use.
Now we will paste the contents of my bash script into nano.
Once again press control+O to save, and control+X to close.
Almost done! Now we just need make the script executable and setup the cronjob!
Don't forget to make the script executable!
Lastly, Setup the cronjob!
I have my script checking every 15 minutes. If you want to have yours check more frequently just adjust the */15 to */Number_of_Minutes_between_checks
First let's open crontab
Scroll down to the very bottom and add this line
Press control+O to save, and control+X to close.
crontab should report
Congrats! You will now receive email alerts if your wort gets beyond the temp threshold!
If there are any other circumstances you might want an alter for please let me know. I am new to the fermentation chamber game, and would be happy to update the script.
I recently setup a BrewPi using FuzzyWuzzy's post, and have been pretty happy with it. However, I was worried about if one of the relays failed. So I wrote a simple bash script to email me if the fermentation temp gets too high far the set point. I thought some of you might be interested in it.
First thing we need to do is setup the rPi to send emails. I decided to use SMTP Mail.
First connect to your rPi via SSH.
Loading Packages
Code:
sudo apt-get install ssmtp
sudo apt-get install mailutils
sudo apt-get install mpack
This will take a few minutes. Answer Y to any prompts.
Setting up Default SMTP Settings
Code:
sudo nano /etc/ssmtp/ssmtp.conf
Make the following changes to the fields. If you can't find one of the fields add it to the bottom. I use GMail for this. If you don't use gmail you may need a different STMP address.
Code:
[email protected]
AuthPass=userpass
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
When you are finished, press control+o to save. Then control+x to close nano.
Let's test to make sure this is setup properly
In the terminal type paste this
Code:
echo "sample text" | mail -s "Subject" [email protected]
This should take a few seconds to execute, but you should get the email pretty much instantly if you're sending to a gmail account.
Great! Email Works, let's setup alerts
Let's use nano again to setup the Bash Script we're going to use.
Code:
nano /home/pi/brewCheck.sh
Now we will paste the contents of my bash script into nano.
Code:
#!/bin/bash
#Config
[email protected] #Set to your email address
AlertAt=3.5 #Threshold for alert. Difference in degree of wort from set temp before alert
function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/\042'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}
curl --data "messageType=refreshControlVariables&message=" http://127.0.0.1/socketmessage.php
Diff=$(curl --data "messageType=getControlVariables" http://127.0.0.1/socketmessage.php | jsonValue beerDiff 1)
if [[ $Diff > $AlertAt ]]; then
echo "BrewPi Needs Help; BeerDiff is $Diff" | mail -s "BrewPi Needs Help" $YourEmail
fi
Once again press control+O to save, and control+X to close.
Almost done! Now we just need make the script executable and setup the cronjob!
Don't forget to make the script executable!
Code:
chmod +x brewCheck.sh
Lastly, Setup the cronjob!
I have my script checking every 15 minutes. If you want to have yours check more frequently just adjust the */15 to */Number_of_Minutes_between_checks
First let's open crontab
Code:
crontab -e
Scroll down to the very bottom and add this line
Code:
*/15 * * * * /home/pi/brewCheck.sh >/dev/null 2>&1
Press control+O to save, and control+X to close.
crontab should report
Code:
crontab: installing new crontab
Congrats! You will now receive email alerts if your wort gets beyond the temp threshold!
If there are any other circumstances you might want an alter for please let me know. I am new to the fermentation chamber game, and would be happy to update the script.