Mail alerts and logging, a python script to handle temperv14, R-Pi in mind.

Discussion in 'Modding and Hacking - Consoles and Electronics' started by -=FamilyGuy=-, Feb 26, 2014.

  1. -=FamilyGuy=-

    -=FamilyGuy=- Site Supporter 2049

    Joined:
    Mar 3, 2007
    Messages:
    3,034
    Likes Received:
    891
    Hi ladies and gents,

    I happen to do some stuff except messing with Dreamcast and that includes discussing in the chatbox of this very website. In one of those fruitful conversation, Cyantist had an issue where he wanted to log a usb thermometer and send mail alerts if the reading was too hot. Insidiously, this conversation had planted the seed of curiosity in my head and, having recently started to do a lot of python scripts, I started to think how I'd do this. Soon enough I was coding a proof of concept, and now I got a fairly usable code.

    ASSEMbler showed interest in this, and I though that it'd be nice to share on here (with his consent) as it should be adaptable to a lot of cases of mail alerts that you guys might be interested in, e.g. raid tower with tons of drives getting hot, low on space, dropped drive, etc.

    So the script is designed to be used with this affordable thermometer: http://goo.gl/Ufj0UN
    It's design under linux with a raspberry pi in mind, but it should be portable to other os as long a the temperv14 command line executable and python are available.

    Without further blahblah here's the files (also attached to this post): https://www.mediafire.com/?fv3ol79f89ahwc6

    libtemperv14.py is a library providing functions to log, do checks and send mail alerts.

    check_temperv14.py is the actual script that uses libtemperv14 to log the thermometer to a file, check the temperature and send a mail alert is it's too hot/cold. There's also a delta variable that sets the minimum amount of time between two alerts, so if you log every minutes and the temperature rises, you won't get spammed. E-Mail credentials, delta and temperature threshold/scale and lot of variables should be defined in this script at the beginning.

    temperv14 is a python scripts that emulates/mimics the actual thermometer, as I don't own it ...

    The idea here is to schedule the execution of check_temperv14.py regularly, using cron per example, to log the temperature (one file per day) and eventually send alerts. Note that you should probably modify the command variable in the script to "temperv14" instead of "./temperv14" if the real executable is in your path or /bin folder.

    Cyantist tested the script with the real thermometer and a Raspberry Pi and it works fine!

    The relevant infos is in the documentation of the scripts (open with text editor), I didn't put it here because this post is already long enough.

    Keep in mind I'm not a programmer, but a scientist, and those people are known to produced horrible code (self-taught and stuff). Though I try to be clear and elegant when possible in my coding.


    If you got any questions, me or Cyantist should be able to respond.

    Any comments are welcome!

    Cheers!

    FG


    PS: Please don't quote that enormous post.
     

    Attached Files:

    Last edited: Feb 26, 2014
    BLUamnEsiac likes this.
  2. Cyantist

    Cyantist Site Supporter 2012,2013,2014,2015

    Joined:
    Oct 28, 2008
    Messages:
    4,158
    Likes Received:
    20
    There is a full tutorial for using the temper device with the raspberry pi [or any linux box full stop] which can be found here: http://dev-random.net/temperature-measuring-using-linux-and-raspberry-pi/

    where that guide finishes, this takes off. tbh, the script you wrote is actually really simple to understand. the only reason we even remotely had issues with it is because im an idiot and had zero experience with programming, let alone python

    If when you run the temper command you get "Could not set configuration 1", this is linked to permissions, a quick fix being to change the ./temperv14 in check_temperv14.py and libtemperv14 to sudo temperv14. [but only if you have placed the temperv14 file in /usr/bin/] :)

    Any issues, leave a comment or shoot a message!

    My raspberry pi I used is now sat over in our computer room happily using cron to run the python script every half hour without trouble. I can even ssh into it if needs be.
     
    Last edited: Feb 27, 2014
  3. -=FamilyGuy=-

    -=FamilyGuy=- Site Supporter 2049

    Joined:
    Mar 3, 2007
    Messages:
    3,034
    Likes Received:
    891
    BTW you could log much more often than that. The resources used are minimal, and even one log every minute wouldn't make a logfile bigger than 200kB at the end of the day. Plus, using the *delta* variable, you would not get spammed if the temperature rises too much. This way you'd get an alert in a minute of the temperature getting too hot, but you won't receive a message every minute, only every *delta* minutes.
     
    Last edited: Feb 27, 2014
  4. Cyantist

    Cyantist Site Supporter 2012,2013,2014,2015

    Joined:
    Oct 28, 2008
    Messages:
    4,158
    Likes Received:
    20
    When summer rolls around we're definitely going to up how often it runs. That room is quite hot (fluctuating from 27 degrees down to 20 with the window wide open all day and all night [its not on ground floor, dont worry lol] and the cold air coming in.
     
sonicdude10
Draft saved Draft deleted
Insert every image as a...
  1.  0%

Share This Page