Happy Towel Day, froods. DON’T PANIC! Coding period has already started and I’m a bit behind my schedule. Here’s a basic task list that I’ll follow. Task list: Get https://github.com/gnebehay/OpenTLD this up and running on your machine Learn how it … Continue reading
So, my GSoC 2012 package arrived today. Got a pen, diary (tablet as they say), Google prepaid card (with $505 balance.. woohoo) and a cool GSoC sticker. I was hoping to get a GSoC t-shirt. Anyway, the package has arrived, … Continue reading
It’s been a year since I started using Linux. The first problem that I faced was my Wireless Firmware was missing. I never bothered to do anything about it until now. My brother installed a router at my place and … Continue reading
OpenCV 2.3.1 python bindings have ctypes and no longer support swig bindings. OpenCV 2.3.1 python bindings are quite stable and much faster than OpenCV 2.1 swig bindings. Although OpenCV 2.3.1 has many new features, it still supports some of OpenCV … Continue reading
I have an HP laptop. And if you have ever used an HP laptop, you must understand my situation. HP heats up a lot. There’s no proper ventilation and heat sink. Despite of using a cooling pad, sometimes my laptop’s core temperature reaches critical temperature value and shuts down. I think it’s quite harmful. To avoid such situation, I always wanted something to measure the core temperature. One of my friends suggested me to use lm-sensors. It’s not bad but it gives me temperature value only when do
It’s kind of irritating to do it constantly to check whether temperature is within range or not.
I wanted to make a python script which would check temperature every minute and warn me if it goes beyond acceptable limit. os.system() would never work. So, I kept looking for something which would give me temperature data. I found this page. https://bitbucket.org/tlynn/trypy/src/7796d8f4a8c1/munin-hddtemp.py
It uses hddtemp. hddtemp sends data via socket 7643(default) to localhost(default).
So, here’s how I have worked it out.
import socket import time import os port = 7634 host = 'localhost' temp = 45 os.system("notify-send "+"'checking hdd temp'") s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host,port)) while True: try: data = s.recv(4096) temp = int(data.split('|')) if temp > 90: notify_string = "'Critical Temp over 90 C." os.system('notify-send '+notify_string) time.sleep(60) time.sleep(90) except KeyboardInterrupt: s.close() break
hddtempis a requirement. While configuring hddtemp, set it’s port to 7634, which is default, or you can set it to anything you want. change it accordingly. And add it to the daemon. So that it starts at boot.
P.S. Screwed this sem’s GPA.
I can’t believe it that I never came across popen2. I feel so stupid now. Had I known earlier about popen2, I would have used it in many of my scripts. Anyway, better late than never.
So I found out about popen2. It’s a good way to pipe the output of the command. Now, I can easily access the temperature without hddtemp. I pipe the output of lm-sensors to get temperature value.
import popen2 files = popen2.popen2("sensors") r = files.readlines() temp = int(r.split()[-4][1:3]) # unable to split using "\" print temp
Read more about popen2 http://docs.python.org/library/popen2.html
P.S. I am so embarrassed. How could I not know about popen !
@JabbaLaci just told me that popen2 has been deprecated since python 2.6 and suggested me to use subprocess. And also that there are some problems with output of hddtemp. I have changed it.
import subprocess process = subprocess.Popen(["sensors"],shell=False,stdout=subprocess.PIPE) data = process.communicate() # returns tuple temp = int(data.split()[1:3]) print temp
Read more about subprocess and Popen http://docs.python.org/library/subprocess.html
P.S. TIL about TIL and subprocess with pipe.
I assume that you have installed OpenCV on your Linux machine. If you are having any problems installing OpenCV 2.3.1 you can view my previous post or http://www.marcolancini.it/other/opencv_install_231.php I would recommend you to go through OpenCV documentation. C/C++ Python C … Continue reading
After screwing up my Ubuntu see previous post and also my Arch Linux, I installed Ubuntu 11.10 and upgraded to 12.04. Ubuntu 12.04 LTS – Precise Pangolin Install OpenCV 2.3.1 sudo apt-get install libopencv-* sudo apt-get isntall python-opencv sudo … Continue reading