Monthly Archives: January 2014

Connecting a DS18S20 temperature sensor to RasPi

I’ve been a little reluctant to connect a DS18S20 temperature sensor to my RasPi, since there were rumors that the w1_gpio.ko kernel module exclusively requires a connection to GPIO #4, because of being hard coded. At least that’s what Lady Ada’s tutorial says about it and what one can read in several user forums. Unfortunately GPIO #4 was already occupied on my Pi. Therefore I searched through several Blogs for advice how to change the hard-coded GPIO in the kernel module. It turned out that I wasn’t the only one – so here’s the good news: In Raspbian Wheezy with Kernel 3.10.25+ it is possible to pass the desired GPIO in /boot/cmdline.txt to the kernel using the option:

bcm2708.w1_gpio_pin=<GPIO#>

To be able to read temperatures from the sensor, modprobe the wire, w1_gpio and w1_therm kernel modules. The temperature can be read from /sys/bus/w1/devices/<device_serial_number>/w1_slave.

I’m using the the sensor for outdoor temperature measurement. I soldered about 1 m wire to the sensor (TO92 housing), insulated the solder joints with heat shrink tube and embedded the sensor into an old metal ballpoint cap using epoxy glue.

WiFi trouble with smsc95xx

In the /var/log/messages file of my Raspberry Pi, which is connected through WiFi to my home WLAN, I repeatedly noticed this error message:

smsc95xx 1-1.1:1.0 eth0: unexpected urb length 0

Furthermore, I got “no route to host” messages when attempting to ssh to my  RasPi. At the same time I couldn’t connect to lighttpd. Some research with Google suggested, that there might be a problem with the USB driver. Symptoms are characterized by fluctuating transfer rates and response times as well as bad WiFi connection quality leading to delayed keyboard response or garbled input when using ssh. Fortunately, there is a  workaround:

Continue reading WiFi trouble with smsc95xx

RasPi lighttpd and server tweaks

This blog is hosted on a Raspberry Pi using the lighttpd (lighty) webserver. Since I haven’t been satisfied with the response time until a page is loaded, I applied some tweaks to increase its performance.

If you need details about your RasPi server, you can test it’s performance with Google’s online PageSpeed Insight tool. Then, follow the recommendations of the analysis results.

Most important for a good WordPress performance appears to be  CSS and Javascript concatenation/compression as well as installation of a cache plugin, such as Autoptimize and WP-Cache.com.

/boot/cmdline.txt, /etc/fstab

Although I use an “ultra” Sony Class 10 (94 MB/s) SD card, performance of the ext4 journaling file system has been an issue. To increase file system throughput, I added:

rootflags=commit=120,data=writeback

to /etc/cmdline.txt, and:

/dev/mmcblk0p2  /  ext4  defaults,noatime,nodiratime,barrier=0

to /etc/fstab. These options disable storing of access times to the file system. Using data=writeback mode extends the time from when a file is written to when it is pushed out to disk to 120 seconds. Be aware that you’ll lose all cached data on a file system crash!

/etc/sysctl.conf

To tell the system to use less IO/RAM, I placed these options into my /etc/sysctl.conf

vm.dirty_background_ratio = 20
vm.dirty_expire_centisecs = 0
vm.dirty_ratio = 80
vm.dirty_writeback_centisecs = 1200
vm.overcommit_ratio = 2
vm.laptop_mode = 5
vm.swappiness = 10

/etc/lighttpd/lighttpd.conf

Disabling keep-alive might help lighttpd if it suffers from a large number of open file descriptors. Select an event handler which takes care of notifying the server that one of the connections is ready to send or receive.

Since we want to send out a file from the webserver, it doesn’t make any sense to copy the file into the webserver just to write it back into a socket in the next step. Therefore, we enable linux-sendfile to minimize the work in the application and push the file directly into the network card.

With the help of gamin (sudo apt-get install gamin) you can use kernel events to assure that your stat cache is up to date.

server.max-keep-alive-requests = 0
server.event-handler = "linux-sysepoll"
server.network-backend = "linux-sendfile"
server.max-fds = 1024
server.stat-cache-engine = "fam"
server.max-worker = 0

After applying these tweaks, lighty responds much faster and I observed less “The site could be temporarily unavailable or too busy. Try again in a few moments.” messages.