Oct 2, 2017

Steps to Install Redis server

Few steps necessary to build and install Redis on a server. There are no pre-built packages available for you to apt-get install it. So you have to grab the source, compile and install the generated binaries. Fortunately it all goes pretty smooth.
$ wget
$ tar xzf redis-4.0.2.tar.gz
$ cd redis-4.0.2
$ make
$ make test

# install compiled binaries to /ur/lib/bin
$ sudo make install

# setup redis-server as daemon
$ cd utils
$ sudo ./

# setup redis-server to autostart
$ sudo update-rc.d redis_6379 defaults

That ought to do it!

Sep 14, 2017

Volvo Door Mirror Mismatched Folding

One of the problems that I encountered with the S80 is that when I unlocked the car and pressed the button to unfold the door mirrors, they would be out of sync with each other. That is one would open and at the same time the other would close. You can open the closed mirror manually, but when you press the button to fold then mirrors, one would close and the the other would remain open.

After some research online, I figured out the problem -- the mirror's folded/open position is stored in memory and the car uses this position to instruct the mirror motors on what action to perform (fold/unfold) when you press the button to unfold the mirrors again. Now if you're in a hurry and happen to switch off the vehicle before the mirror folding operation could be completed, storing of the mirror position in memory cannot be completed accurately.

The solution to the problem turns out to be very simple.
  1. Turn off the car.
  2. Locate the fuse box in the passenger compartment. Locate fuses for left and right door power windows and mirrors. For 2004 S80 these are fuses 35 & 36 respectively. Here is the list of fuses in this fuse box. It looks like this:
  3. Remove the left door fuse (fuse number 35).
  4. Manually push the left door mirror position to be in sync with the right door mirror position.
  5. Start the car.
  6. Turn off the car
  7. Replace the fuse you removed in step 2.
  8. Start the car again and now press the door mirror button. If it was the left mirror whose position was wrongly recorded in memory, everything should be fine.
  9. If the mirrors are still out of sync with each other, repeat steps 2-7 with right door fuse (fuse number 36) and manually bringing the right door mirror to be in sync with the left door mirror position.
This technique should work for all Volvo cars with electric door mirrors. Of course you do need consult your vehicle's manual for the right fuse to remove.

How to Integrate Sphinx with a Django Project for Automatic Documentation Generation

A few points on integrating Sphinx with a Django redistributable project for generating documentation embedded in the source files.
  1. Project directory structure should look like this:

  2. Install sphinx and sphinx-autobuild using pip.
  3. Run sphinx-quickstart from the docs folder. Provide default answers for all prompts.
  4. Edit docs/ such that the redistributable package and the demo project's apps are importable from the docs folder. At the top of the file:
  5. import os
    import sys
    import django
    sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
    sys.path.append(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'demo'))
  6. Setup sphinx such that it can safely import the Django source file referred to in any RST files for autodoc. For this you need to setup the DJANGO_SETTINGS_MODULE environment variable to demo project's settings. Also need to initialize Django's AppRegistry with a call to django.setup().
  7. os.environ['DJANGO_SETTINGS_MODULE'] = 'demo.settings'
    import django
  8. Embed the package version in the redistributable folder's file as __version__ = "x.y" and then import this version into This will make the package version and documentation version concurrent.
  9. import redistributable
    version = redistributable.__version__
    release = redistributable.__version__
  10. Build the documentation issuing make html from the docs folder. 

Mar 12, 2017

Volvo Engine Service Required Message

Image result for volvo S80 orange warning light

This is a message that my Volvo (S80 2004 2.0T) started showing yesterday. The message was accompanied with a yellow/orange warning light, (image on the right) in the car dash.

This freaked me out when it first appeared as I was worried that the car could shutdown anytime while on the move. But apparently the color of the light, yellow, is an indicator that the issue is not major and therefore such a shutdown is not an immediate possibility. On the other hand, if the color of the indicator is red, then it is indeed cause for concern and the best option is to stop the car and seek professional help immediately.

In the past whenever I had issues with my car, my first reaction is to reach out to my mechanic for help. But with the Volvo, what I have learned is that with the amount of electronics and computer control that is embedded into it, it's best to first to research online, narrow down the possible causes to a select few and then approach the mechanic appraising him of your research results. And sometimes you might even be able to fix the issue yourself (like I did with the out of sync door mirror folding issue). Perhaps it's because my mechanic is not very familiar with Volvo that this is necessary. He's more of a VW/Audi guy having worked in their official dealership for many years before venturing out on his own. Unfortunately right now I don't have the time to find a Volvo specialist and this guy's place is close to where I live. More importantly I've found him to be trustworthy.

Anyway with that approach in mind, I started my research yesterday and here are some of my findings. I thought it's best to record them here for my own reference, should this happen again.

Internal Error Codes

While messages on the console provide a driver friendly generic message, internally the computer associates error codes with each problem and stores it. As many things can go wrong with something like an engine, Volvo displays the generic message 'ENGINE SYSTEM SERVICE REQUIRED' in the messages console, but stores a more discrete error code internally. While the official OBDII reader can obviously read this code, there is an easier way.

According to this post, with the doors closed and engine running, holding down the READ button at the end of the left stalk (used for indicators) along with the trip meter button for 10 seconds should show this code on the messages console, along with a beep.

I searched the web for a list of possible error codes and their description, but unfortunately I have not been able to find one.

Possible Causes for the Message

So far my research yielded many threads where others have encountered a similar problem and going through these, I have narrowed down the list of problems to a few:

Cruise Control

Somehow the cruise control stops functioning along with this message and I have the same symptom. One owner fixed this by changing the brake diaphragm position sensor and it was fixed.
The post linked above also relates the problem to the cruise control. I remember my car's cruise control stopped working two weeks ago on a trip to Taoyuan. So to be investigated.

Here's another thread that describes this problem and how he fixed it.

And this thread explains how to fix the brake pedal position sensor, without buying a new one.

Random Misfire

One owner attributed the problem to this. And I have been experiencing this on and off, but only when I start the car.

This owner pulled all the coils and spark plugs and found two spark plugs were not screwed in tight, which could have meant some compression loss and possibly a random misfire. He cleaned all the plugs and coil connections and also removed all the crumbing plastic sleeve on the wiring to the coils and wrapped all those wires with electrical tape, though he did not see any other damage to the wires, then installed new plastic sleeve. This seems to have fixed the problem as the message did not appear again after resetting it using the same method to reset the service indicator message.

Oil Sticking to the Oil Level Sensor

An owner reports this message due the following issue as thus:

"I've found that if I open my oil cap and then start the car, the message goes away. Of course I didn't have any OBDI codes or lights on, just the engine system service required message. I've done this twice now and it worked. I use lucas oil stabilizer with full synthetic, and I think sometimes the oil sticks to the oil level sensor and gives a false reading that the oil level is too high. Could be wrong but it works for me."

Another owner explains this as thus:

"Sounds related to the vacuum system and when you pull the oil cap off that makes a difference. I have a vacuum\booster issue that disables cruise as well, haven't bothered to fix it.

If you're using non-premium gas theres a chance that over time you will scorch your exhaust valves and seats as the motor adjusts ignition advance to cope with the faster flame propagation. Result is that your valves spend more time exposed to the flames from the exiting gas. Believe it or not, this is the most common issue with OBD cars that request higher octane fuels. Detonation and so on not really an issue unless you have a defective knock sensor. Scorched valve seats though are much more common.
I dont think your fuel choice is related to the code you saw though."

Mass Air Flow Sensor

A post in another forum alludes this problems to faulty or improperly seated Manual Air Flow (MAF) sensor. Apparently the owner got the message when using the car after it rained non-stop for a week, thereby causing the MAF to report air flow issues. And at another time, the MAF was not properly seated after cleaning which also caused the message to appear.

UPDATE: The problem was due to faulty brake pedal position sensor, which automatically turns off the cruise control system as a safety measure (makes sense). This can be replaced or even repaired. The carbon rods inside this sensor become dirty which affects their sensitivity. Taking it out and cleaning it and putting it back can solve the problem. This thread discusses this further.

Volvo Service Reminder Message

This is a message that appears on my Volvo S80 after driving for a period of time. Interestingly, this message appears even though I have not driven the car for the recommended service interval - 7500 miles, or about 12000km.

Did some research and it turns out that this message is displayed as a function of hours the engine has been running, duration since last service and distance covered.  Essentially, this light will come on at 7,500 mile (12,000 km) intervals, after 750 hours of driving or after 12 months, whichever occurs first, to remind the driver that the service interval has been exceeded.

The light will stay on for 2 minutes after start until reset.

Here's how to reset this message without using a professional interface equipment:
  1. Put the key in and turn it to ignition position I
  2. Press and hold in the reset button for the trip odometer
  3. Turn the key to ignition position II. Note! Turn the key to position II within 2 seconds.
  4. Hold the reset button for the trip meter pressed in until the original value has been reset. Note: For all vehicles from the 2003 model year a general yellow lamp will light when the reset button must be released.
  5. Release the reset button for the trip odometer within 4 seconds. The instrument gives an audible signal when resetting has succeeded
  6. If the trip meter is already reset the reset button should be held in for a minimum of 10 seconds and a maximum of 14 seconds. If the reset button for the trip odometer is not released within 4 seconds, the service reminder indicator (SRI) is not reset.

Feb 9, 2017

Django template tag to retrieve template filename

One useful Django template tag is to retrieve the template filename from inside the template. Unfortunately, Django built in tags do not provide one for this. However, you can write a simple tag to accomplish this.

Here's are two tags, that return either the base filename or the full filename.

from django import template

register = template.Library()

def basefilename(context):
    '''Returns filename minus the extension'''
    return context.template_name.split('.')[0]

def fullfilename(context):
    '''Returns full filename with the extension'''
    return context.template_name

To be complete, tthere should be another tag that returns the filename with its entire path. But I haven't figured out how to do this -- at least from within the confines of the template tag framework.