1.9 KB

The fuck is this

This shit is a qt lil Pyth0n implementation ov reading ein DS18B20 temperature sens0r, the values of which get stored in a MySQL database somewhere. =]]]

It will run 5 samples (with a required 1 second delay between em) and get the average of that to store in the DB. It also supports multiple sensors but it will only store the first average. xd


You prolly need to install a few Pythinz modules cuz they may not be available by default:

  • ConfigParser
  • MySQLdb


Copy muhconf.ini.example to muhconf.ini and fire up een editor. All the options are self-explanatory or explained in there so git to reading fam. The config file must be kept in the same dir as the skrip.

Then simply slam a new entry in your crontab to make it run periodically (the skrip is set up to read/store once, then quit). You should be able to run it as any non-root user, since the sysfs path belonging to the sensor data (e.g. /sys/bus/w1/devices/28-02155265b0ff/w1_slave) should be world-readable. My cr0n looks leik dis:
*/2 * * * * kill -9 $(ps aux | grep '[p]ython.*' | grep -v '/bin/sh' | awk '{ print $2 }') >/dev/null 2>&1 ; /usr/bin/python /home/hecks/temp_sensor/

As you can see I have it set to run every 2 minutes, faster is not really necessary and would only clutter the DB. The kill part is in case a previous instance is hanging on something for some reason, and should usually fail (hence the redirections to /dev/null ;]). To me this only really happens when my internetz connection is being gay and takes 2+ minutes to set up a usable MySQL connection. This logic is not present in the code itself because of the "set up to read/store once, then quit" reasoning. ;];];];] It would be p hard to account for anyways, since the TCP handshake has been completed and there are packets flowing, just many get dropped and have to be resent.

ez pz ;]