Quaintproject

Alert Mail Raspberry Pi

27 Comments


Temperatures above 80 °C can damage your raspberry pi.

Especially if your using your pi as a webserver, webcam-stream or as a display system, in a 24 hour-operation, you may want to get warned via Email. Getting a notification from your pi is pretty simple, just use the script below:



If you have any questions about the notification system or any other Pi Topic, feel free to comment.
Cheers Alex

Advertisements

27 thoughts on “Alert Mail Raspberry Pi

  1. Oke, i see your script, and now?

    Like

  2. Haha i know, but how, must i make it a .sh script?
    Where to put it?
    Is there extra software needed?
    How must i continue,..

    Like

    • You need to give it a .py Extension. You could put in the root or home directory (I would recommend). To Run: Sudo python name-of-script.py. You may want to autostart the script to:~/.config/lxsession/LXDE/autostart

      I hope this helps you out.

      Like

    • i got a error on line 21

      root@ruudberry:~# python temp.py
      File “temp.py”, line 21
      server.login(“raspberrypi”, “qwerty123”)
      ^
      IndentationError: unindent does not match any outer indentation level
      root@ruudberry:~#

      Like

  3. i don’t have a mail program running on the raspberry yet, maybe that is the 21 error.

    Like

  4. I would recommend you to copy the script from above in a new *.py file, because I’ve made a few changes, hopefully it’s now more clearly. Make sure to have the same indentation that I have.

    If this does not help, try this:

    Another reason why you got the “Server login error”, might be caused by a wrong username, password or server. If you could tell me your email provider, I could help you editing the script for your needs. Please let me know if you have any issues.

    You don’t need to have a mail program because we are importing the smpt library. 🙂

    Like

  5. :-))))))))

    Critical warning! The actual temperature is: 45.5

    It’s working!
    (i put it for the test to 10 degrees)

    Thanks for the support!

    Best regards,
    Ruud

    Like

    • We thank you for the help to improve the article. We hope you enjoy to work with the Raspberry Pi.

      Best regards,

      Michael from quaint project.

      Like

  6. Hi Alex,

    I have changed my password, it’s a little bit longer, but now i get the following error.

    File “/root/Mailalert.py”, line 25
    server.login(“123@gmail.com”, “&(“LN3KXJWLYQL0ZQPQrrKmGFqUOneq3OMUkKEBWxHP38SKkC3egrffIfq3”)
    ^
    SyntaxError: invalid syntax

    Can you tell me how to solve this issue?

    Thanks in advance.
    Ruud

    Like

    • Hey there,
      sorry for my verrrry late reply. It seems like I’ve missed your comment. The problem is that you have a quotation mark in your password and this is normally the beginning and ending of a string. If you still want to solve it you could put it like this:

      server.login(‘123@gmail.com’, ‘&(“LN3KXJWLYQL0ZQPQrrKmGFqUOneq3OMUkKEBWxHP38SKkC3egrffIfq3’)

      These single quotes have a higher priority than the quotation mark.

      Best Alex

      Like

  7. Is it possible to have more than 10 characters for password input?

    Like

  8. Pingback: Alert temperature and e-mail | Raspberry Pi stuff

  9. Hello, I know it’s not a recent post, but how does the script work if I launch it with autostart? Will it check température as it evolves ans then stop zone the alert is done, or will it just check the temp at startup ans stop whatever is thé result of the temp?
    Just to know if it’s better to do it in @reboot with cron or every hour. Yeah i’m a noob trying to figure things 🙂
    Thank you for this script, it’s the main thing I want to monitor on the rpi.

    Like

    • Hey there,
      thanks for you comment, you’ve luck this post is still active!

      there are basically two ways how you could do it.
      1. Modify the script to run a endless While loop with the condition true. This would run the script as long as the script is not interrupted. (The temperature would be checked every loop).

      2. You could make a cronjob that runs every 30 minutes (no need to reboot) and call the script. In my opinion this method would have the benefit that you wouldn’t get a view hundred mails in a really short time.

      Right now the Script the script starts and checks if the temperature is to high -> send mail, if not it simply ends the script.

      I hope my comment helps to solve all your questions! If not, feel free to reply again.

      Alex

      Like

    • Hello, thank you! It’s a perfect answer. From my understanding of python it’s what I suspected ans what I checked after blowing on my rPi to play with the temp ans see the script had ended on the trial value :).
      So I made a cronjob every 30mn and it’s allright for my needs.
      Thanks for the answer and great website by the way, a little bit advanced for my level but that’s the way to learn :), already bookmarked.
      Roman

      Like

    • Thanks so much for your kind words! I can tell you from all of our crew members that we all were once beginners with the Raspberry Pi. If you have any topic we could cover or wich meets your interests feel free to tell us. Thanks for bookmarking!
      Alex

      Like

  10. Hi Codewarrior, I was able to get the script to work. Like it !
    Actually, I am also looking for a script that monitors several GPIO Ports and emails me when things change (NC/NO).
    I know there i a lot on the web, but there is also a lot of crap and stuff where people assume you are a top programmer and understand everything from nature. If I see something it crashes my Raspberry, or doesn’t do anything at all.

    Remarkable thing is, yours simply works !
    That’s why I use it now and was wondering if you can help me with the multiple NC/NO GPIOs monitoring.

    What it needs to do:
    – monitor a switch (open/closed) and email me about it.
    – monitor water level to prevent flooding and email me about it
    – stay “active” no cron jobs, no reboot, just like a background service.

    If you can help me or guide me to something that simply WORKS, I would appreciate it !
    Thanks!

    Like

  11. Hi, please please help me. Im very new to RasPi and I´m trying to use your script with no success. What I did is first: nano notify.py, once there I added this script:

    coding=utf-8

    import os
    import smtplib
    from email.mime.text import MIMEText
     

    At First we have to get the current CPU-Temperature with this defined function

    def getCPUtemperature():
     res = os.popen(‘vcgencmd measure_temp’).readline()
     return(res.replace(“temp=”,””).replace(“‘C\n”,””))
     

    Now we convert our value into a float number

    temp = float(getCPUtemperature())
     

    Check if the temperature is abouve 60°C (you can change this value, but it shouldn’t be above 70)

     
    if (temp >60):
     
     # Enter your smtp Server-Connection
     server = smtplib.SMTP(‘smtp.gmail.com’, 587)
     #if your using gmail: smtp.gmail.com
     server.ehlo()
     server.starttls()
     server.ehlo
     # Login
     server.login(“jolimk@gmail.com”, “MYACTUALPASSWORD”)
     
     # Now comes the Text we want to send:
     value = “URGENTE! La temperatura es: ” + getCPUtemperature()
     msg = MIMEText(value)
     # The Subject of your E-Mail
     msg[‘Subject’] = “URGENTE! Temperatura: ” + getCPUtemperature()
     # Consigner of your E-Mail
     msg[‘From’] = “Raspberry Pi”
     # recipient of your E-Mail
     msg[‘To’] = “jolimk@gmail.com”
     # Finally send the mail
     server.sendmail(“jolimk@gmail.com”, “jolimk@gmail.com”, msg.as_string())
     server.quit()
     print “Everything was working fine! Best regards http://www.quaintproject.wordpress.com

    As you can see it is in Spanish, but there is something wrong going on here. I get the following error:

    pi@retropie:~ $ sudo python notify.py
    File “notify.py”, line 5
     
    ^
    SyntaxError: invalid syntax
    pi@retropie:~$

    What is wrong here?

    PLEASE HELP ME, I NEED THIS REALLY BAD AS MY PREVIOUS RASPI BURNED. Thanks

    Like

    • Hi there,

      I’ve uploaded the script to GitHub’s Gist. The syntax error you’d faced has to do with wrong indention. (WP sometimes messes up the format). In Python it’s necessary to indent the body of a function or a if either for blank spaces or one tab.

      I hope this helps.

      Alex

      Like

    • I dont understand your reply. What can I do in order to use your script?

      Sorry but as I mentioned Im COMPLETYL NEW. Can you give me STEP by STEP instructions on how to do this from SSH or VNC remote connection?

      Thanks a lot

      Like

  12. Where is the script?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s