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.
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.
