Saturday, December 2, 2017

PostgreSQL Installation and Cheatsheat

I always seem to forget some small details when installing PostgreSQL so a nice cheatsheet is very good to have. Following applies to Ubuntu Xenial 16.04 and PostgreSQL 9.5

Installation:

Installation is the easy part. Lets install postgis at the same time. You don't need postgis if you wnn't work with spatial data.
# apt-get install postgresql postgis
PostgreSQL by default works with UID authentication. To become administrator, all we have to do is to switch to postgres user and then run psql
# su - postgres
$ psql
Lets create a user named masauser. You have to be logged in as postgres user.
$ createuser --pwprompt masauser
$ createdb -O masauser masadb
Remember dropuser and dropdb commands do the reverse and delete a user and database.

If you want to change the password of the user you can use \password if you are changing the current user's password. Otherwise use this:
ALTER USER masauser WITH PASSWORD 'masapassword';
Note that this will be stored in executing user's history!

Enabling Extensions:

To be able to use postgis, you need to connect to the database you want to use postgis. Then execute CREATE EXTENSION postgis;

To enable UUID support execute the following CREATE EXTENSION "uuid-ossp";

To be able to use trigram support, you need to connect to the database you want to use trigram. Then execute CREATE EXTENSION pg_trgm;

Logging in:

Normally you can login simply by writing psql masadb masauser but you may need to add the -W option if psql does not ask password. psql masadb masauser -W

If you want to login to correct database which uses password authentication, you can export the necessary information in login. The important part is PGHOST otherwise PostgreSQL will not use the password.

export PGHOST=localhost
export PGDATABASE=masadb
export PGUSER=masauser
export PGPASSWORD=masapassword

Useful Hints:

It is quite useful to enable timing when running queries. You can easily see efficiency of your queries when timing is enabled. This is enabled by timing

Create table and fill it with random data:

CREATE TABLE users (
    first_name text,
    last_name varchar(255)
)

INSERT INTO users (
    first_name,last_name
)
SELECT md5(random()::text), md5(random()::text) FROM
          (SELECT * FROM generate_series(1,1000000) AS id) AS x;


Backups:

Dump database with compression you should login as postgres user first:

$ pg_dump masadb | bzip2 > masa.sql.bz2
$ bzip2 -c -d masa.sql.bz2 | psql masadb

Saturday, November 11, 2017

Golf MK4 Variant Seat Height Adjuster Replacement

I have recently had a problem that the seat would lift up easily, but it was really difficult to make it go down. I figure the clicking mechanism connected to the adjustment handle was damaged and replaced it.

It was cheap enough to buy from AliExpress another unit. Although the seller said it was brand new, I believe it was a used unit.

The left and right seats should have different part numbers. This car is a left-hand drive model, therefore the mechanism was on left side. It has height adjustment only at driver's seat. The article/part number for the mechanism is 1J0 881 053 D ( 1J0881053D )

This probably applies to few other MK4 models and a very easy to change item.

First you have to remove the handle. Unfortunately I did not take picture of this process. It is in place with 2 torx screws. You can use a very thin screwdriver (and I mean a really thin precision electronics screwdriver) or a carpet knife to patiently pry the caps out. I read that some people drill them and replace with new ones. This is not necessary if you have thin enough tools.

The second part to remove is the seat back level adjustment knob. I also read that many people break it when removing. However there is an easy way to remove it. If you look from behind the seat, you can see the tabs holding the adjustment knob. You only need to lightly pry the tabs one at a time and pull the adjuster out from other side. There are 3 tabs. You will need to patiently turn the knob a little bit for each tab and make sure to not press them back in.

Here is a photo from how it looks like from behind. I marked where the tab is with the red arrow:
But in case if you break this part, you can get a new one from AliExpress for few euros only! The part number is 33D 881 671 . Below is a photo from how it looks like inside. You can clearly see the 3 tabs in the photo:
Next is to remove the screw from the front of the seat and also the screw under the seat distance adjustment handle and remove the handle. The front middle screws are philips screws but the handle screw is again same size torx screw. Unfortunately I have removed the screw already when I took the photo below:

Below is a photo from under the seat. While this is no use for us, I marked one of the plastic tabs holding the side of the cover. there is an identical one on the other side and you need to unlatch it when removing it.
 
Now you will need to bend the left side a little bit down, because just under the middle screw we just removed, there is another screw hidden under the plastic. Below you can see the hidden screw place on the most left also the normal visible front middle screw metal thread piece. We need to remove the hidden screw before removing the side cover.

One thing else to remove is that near the middle is a hidden plastic tab. I didnt realize this was there and I could still remove the plastic cover. But I recommend first removing the tab. You can see it in the photo below. It is just pushed into the hole and you can remove it by pulling out.

I also marked the various plastic tabs holding the part in place. You should take care to not break them.

Now all the screws and handles are removed. You should start taking the part out from the front first towards the back. I managed to get it out by wiggling up and down mostly. It requires medium amount of force and careful flexing of some tabs. Especially one tab on the upper side needed a little bit flexing to get the whole thing out.

In the above picture, you can also see the nuts holding the adjustment mechanism. It is in place with only 3 nuts (I think they were 10mm nuts). Before removing them, if possible, I recommend lifting the seat up to highest position. This is because the seat incorporates a very strong spring to help lifting the seat up. So if you remove the mechanism when the seat is down, the seat may jump with the force of the spring. When the seat is all the way up, at least for me, the seat just stayed in place.

So, after removing those 3 nuts. I simply wiggled out the adjustment part and inserted the replacement one in place. Then I had to turn it a little bit to align the holes to match.

The assembly is simply the reverse of removal. Take extra care to not break the plastic.s

Symfony Console Cheatsheet

Here are some useful console commands:

Automatically generate getter/setter methods in entities:
$ php bin/console doctrine:generate:entities AppBundle

Automatically generate getter/setter methods for specific table:
$ php bin/console doctrine:generate:entities AppBundle:"TABLE_NAME"

This functionality is deprecated and will result in following message. However maker bundle does not seem to work without config file with symfony 3.4

 NOTE: The doctrine:generate:entities command has been deprecated.
       To read more about the differences between anemic and rich models go here http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html#adding-behavior-to-entities.
       If you wish to generate your entities, use make:entity --regenerate from MakerBundle instead.



Create an entity and repository:
$ php bin/console generate:doctrine:entity --no-interaction --entity=AppBundle:Store/Product

Create/Update tables based on entities. Can use --dump-sql instead of --force to see the proposed commands.
$ php bin/console doctrine:schema:update --force

Thursday, October 5, 2017

Encrypted Storage Disk On Ubuntu

I decided to install a USB disk with encryption. There were many tutorials about encrypted partitions. I thought it is neater to simply encrypt the whole disk.

I used an old USB3 HDD which I had laying around. It was actually rather simple. My USB drive appeared as /dev/sdd It is possible to zerofill the drive before doing this. However I did not have sensitive data in the drive previously so I am not worried about people recovering random stuff from there . So I saved some time by skipping that step. You have to run the commands below as root user or use sudo

# apt-get install cryptsetup

The commands below will create an encrypted filesystem using the whole /dev/sdd disk. You won't be able to create partitions in it. But you can use that one encrypted filesystem inside it.

# cryptsetup -v luksFormat /dev/sdd
# cryptsetup luksOpen /dev/sdd usbdrive
# mkfs -t ext4 /dev/mapper/usbdrive

After mounting it to /mnt we can access it like any other disk.

# mount /dev/mapper/usbdrive /mnt

Here is how you close/lock it again. You should umount it first

# umount /mnt
# cryptsetup luksClose usbdrive

Monday, October 2, 2017

LightDM and 4K / HiDPI displays

I have recently acquired a 4K display and the fonts were tiny on it. I did a quick Internet search and found several questions from people having the same problem.

Most suggestions were involving around changing the font DPI. But this has undesirable effects, such as fonts being so much larger than other elements. I opted in to change scaling/resolution. To be honest from few meters away, I can't tell the difference between FullHD and 4K anyway.

The solution was setting the scaling with xrandr. To be able to apply the settings at startup, one should use the greeter-setup-script and session-setup-script options in lightdm. Below is how my /etc/lightdm/lightdm.conf file looks like

[SeatDefaults]
user-session=xfce
greeter-show-manual-login=true
greeter-setup-script=/etc/profile.d/lightdm.sh
session-setup-script=/etc/profile.d/lightdm.sh
 
Inside the /etc/profile.d/lightdm.sh file (this file needs to have executable permissions for lightdm to be able to execute it). You have to change HDMI-0 with the name of your display output. Unfortunately making too large scaling causes jagged edges. I had good quality with 0.5. The alternative line works much better.

#!/bin/sh
if [ ! -z "$DISPLAY" ]; then
  # Scale the display
  #/usr/bin/xrandr --output HDMI-0 --scale 0.5x0.5
  # Alternative method, this may give better results
  /usr/bin/xrandr --output HDMI-0 --scale-from 1920x1080
fi

There was one problem with this. I use KODI and it does not seem to care about the scaling. Therefore it didnt fit to screen. In my system KODI has it's own user. I created a .profile file under this user with the following information to rescale the display when KODI starts.

#!/usr/bin/env bash
/usr/bin/xrandr --output HDMI-0 --scale 1x1

If anything goes wrong. You should check your file permissions.

Sunday, September 10, 2017

Cheap Wireless Microphone Systems

In the past, we had little choice but to use units from Shure, Sennheiser, AKG etc. if we wanted to use a wireless microphone system. Today these companies make very advanced wireless systems, even digital and encrypted systems. The cost of these sysems can go up to 6000€ for a 2 channel system. Although you can get cheaper models from same manufacturers, usually these models have restrictions on number of channels which can be used etc. These high prices are not surprising, since these companies have to divert most of their profits towards advertising and distribution. If a product is found in every store and its name is mentioned everywhere, people tend to associate with it easier. It is normal behavior to be weary of a product which you never heard of.

But... can we meet in the middle and get reasonable amount of features for a reasonable price? I will focus on units which can be found at AliExpress site. Today, it is possible to even find cheap units with digital transmission and rudimentary encryption at AliExpress.

While no doubt that you may get the best audio quality with a 6000€ unit (3000€/channel). Do you need to pay that amount if you can get a 300€ unit (75€/channel) which does the task you require?

In the final unit I chose, I couldn't find any audio artifacts while in operation. I showed the unit to few musician friends and they seem to think that it sounds fine also. This is never the less not a very scientific method, but if you can't hear the difference I am not sure if it is worth paying so much.

Unit Selection Highlights

There are so many models and brands, they all promise to be the best. How to choose?

Frequency Range

First of all, you must filter your choices by frequency. Most units sold on AliExpress have frequency settings which are totally unacceptable. The used frequencies are not in the free range in Europe, North America or even in China. I have discussed this issue with some sellers and learned that we can blame India for this. Apparently Indians want it this way, although I found out that those frequencies are not even the allocated wireless microphone frequencies in India. Never the less, you must complain to unit producer if you find a nice unit you want is in wrong frequency. This way, eventually they may start producing units in legal frequencies.

For example, currently in Finland the following frequency ranges are available for microphones:
174–230 MHz (TV-VHF) No licence required as from 1 January 2017
470–694 MHz (TV-UHF) No licence required as from 1 January 2017
823-832 MHz No licence required
863-865 MHz No licence required
1785–1804.8 MHz (UHF) No licence required

One important thing to mention is that it is not enough to operate a device in this range. Another restriction is that the user must NOT be able to set the device to any frequency outside these ranges. Otherwise device would require license or may be illegal to operate.

So, we already filtered out a bunch of systems.

User Manuals

I found out that user manuals give so much better feel of a system than just looking at its photos. This may not be same feeling for you. Also most sellers seem to say "it is easy to use, no need for manual". But the features and capabilities of the system give me an understanding of how much attention to detail was given and how advanced the system is. One other thing is that on AliExpress most sellers copy/paste specifications of systems. You get to the bottom of it by receiving manuals. Another thing is that the sellers tell whatever to sell you the device. Manuals usually give more truthful information about the operation of the device.

Beltpacks 3.5mm or Mini-XLR or With Volume Control

This mostly interests beltpacks. There seem to be two different types of beltpack connectors used in these systems.3.5mm screw locking or mini-xlr. While the mini-xlr may seem more advanced, all the chinese units use only pins 1 and 3 in these units. In addition, some units have the mini-xlr port connected upside down! meaning you get signal in pin 1 and ground in pin 3. If you choose an XLR beltpack system then you would need to make sure to ask the seller that the pins are not reversed. Otherwise this may effect microphone performance.

On the other hand, Chinese sellers will NOT recommend you 3.5mm units if you want to use instruments with them. The reason is not because these units do not work well with instruments, but it is simply difficult to produce cables for instruments with these units. The chinese 3.5mm screw lock solder plugs are very difficult to work with due to small soldering area on the connector.

The 3.5mm version beltpacks use mono jacks. While some headsets come with stereo plugs, only the tip and sleeve are used. One nice feature is that these 3.5mm units often come with volume control so one can reduce the volume. But then, I didn't have any occasion where very high volume was a problem, even when a guitar with pre-amp was connected. It feels like they seem to have some sort of auto gain control. So far, I did not find a good use for the volume setting.

If you stick to headset/lavalier microphones then the 3.5mm would be quite reasonable choice. But if you want to use instruments such as electric guitar, then you would need to produce your own cables. For example the sennheiser cables would NOT work because their guitar cable uses ring/sleeve for transmission.

Digital or Analog

The digital units of course would have superior resistance to interference but I tried two units and they seem to have some problems. One super cheap two-channel unit had some background noise. I can't tell if it was my unit which was faulty. Because some other buyers seem to be perfectly happy with the unit. I did not make further tests with this unit, I should have tried to figure out what was wrong with it but ran out of time.. I am putting photo of the unit I had below for two reasons. 1- To not generalize a perhaps local problem. Not all digital units may have this problem. 2- You may put comment if you have this unit .

UPDATE: I have bought another of this unit from a different seller and the new one was ever slightly different inside. I believe they had a revision update and fix the issue. One must ask seller to test the unit before shipping.
Inside looks like this


I also got a one channel digital transmission unit. As a matter of fact, the beltpacks of these units have exactly same hardware but they work in different frequencies. In this unit the problem was some sort of strange shift in the frequency at first. When I tested with a guitar, it changed the frequency a very small amount (tested with an Android app from my phone). But I found out that this is because of a squeal avoidance function (not sure how this change in frequency is going to help). Below is the photo of the unit. Otherwise it works pretty well.

Inside looks like this. Surprisingly little space is used in it!


Using Instruments

Normally the more expensive units provide a different cable connection for instruments due to difference in impedances between for example microphones and electric guitars. However, in my tests I had no problems whatsoever when using the same microphone input. There was no distortion in the audio. I tested both guitars with pre-amp and without. Your mileage may vary if you are using instruments but with units which has volume controls, you can always lower volume if you encounter distortion. The problem is that the volume of a high impedance instrument will be too high for a low impedance input. But in all cases the units seem to adapt to it perfectly.

Unit "Without" Faults (IMHO)

I myself settled on a 3.5mm beltpack unit eventually. Bought from a company called boyue international on AliExpress. They have a web page also called BolyMic. One of the reasons was this unit had an amazing manual, volume control on beltpack, radio transmission power control, automatic best frequency finding, transmitter battery status could be seen on receiver. I felt the XLR units were somewhat not ready for prime time.
 
The picture below is not to scale
In either case, the unit looks amazing in the rack. I also liked the cool magnification effect on the handheld display glass. The microphones are metal and very heavy. Range seems fine, so far I could not find a place where it won't reach far enough but then I did not test to the distance that seller claims which is 150M.

They could have gotten away with using only 2 antennas. Also, the unit is a diversity unit, but I believe it is not the so called "true diversity" which do combine signals from antennas. It gets little bit warm, but not more than my laptop so I guess that can be considered normal. One last thing is that the handheld does NOT have volume control, there is an error in the manual in that area. There is no MUTE button on transmitters, but unit mutes channels automatically if you turn off the transmitter. These are the areas where unit can be improved in my opinion.

Below are photos from the insides of the beltpack and the handheld (last picture) microphone



Also some pictures from inside the receiver



Now the manual pages for your information
























Car Door Laser Logo Projectors Modding

It is possible to buy courtesy light replacements with logo projection from AliExpress for less than 10€. While some of them mention the word "laser", they are actually based on high power Cree LEDs.

If you are buying these lights, I highly recommend opening them up and have a look inside. In my case the LED module was not glued to the heatsink. I had to use adhesive heatsink paste to glue the LED onto the heatsink. The glue I used was sold as "Thermal Conductive Heatsink Plaster". You can see the plaster under the led module in the picture above.

I also found out that the LED driver is set to give out 500mA constant current and this roughly equals to 5W in this case. This is simply too much power and causes LED to get too hot and burn out. When I was working in the car, I left the door open for a long period and this caused Cree LED to burn out. The LED driver is a pretty small module and the current output can be changed by replacing a SMD resistor. I didn't have SMD resistors so I found a replacement module which gives about 300mA output. This module sold as MR16 3W LED Driver. Of course the brightness went down about 20% but the LED module is not getting too hot anymore (at least it will take much longer time for it to get to a critical temperature)

In addition, I didn't like the fact that these replacement courtesy lights only point downwards and they do not have the red light warning for incoming cars. So I have embedded two red leds in parallel to the Cree LEDs. You will need to figure out which size resistors you need or use special LEDs if you do this. I found out some strange LEDs which could be wired directly to 12V. They work reasonably well in this setup because Cree LED's input floats getween 3V - 5V.
One last thing to mention is that usually these items come with no real connectors. Only some models of them are with real connectors. While you can just slide the provided pins into the connector of the car. They will simply get out in time and it does not look safe at all. I have found out some connectors which were exactly same as on my original courtesy lights on AliExpress and crimped them.

Here is what the end result looks like, powered from portable lead acid battery.

Tuesday, July 25, 2017

Bosch / Siemens Dishwasher - Fix No Heat / Random Stops

I have recently came across a 7 year old dishwasher which was on sale because it did not heat and sometimes did not start the program or did not finish it properly. The washer had the model number SN44T580SK/23 however this problem appears to be common for many similar machines. The machine was checked by Siemens service and a repair quote of about 500€ was given for change of main control unit of the machine.

When we ran the machine in different programs, we found out that m ost of the time the quick wash program was working properly. Few times it game the E.02 error on display. Apparently E02 error is listed as "Running without heating" and cause is "Working relay of heating is defective" and repair advice is "Change power module". However the module itself is quoted over 250€ at Siemens parts site.

First thing to check is if the element is in working condition. This can be done simply using an ohm meter. The instructions are as shown in the picture below.



The control module in questionw as EPG60110 with part number 9000376770. Unfortunately, I read that these modules are programmed to the machine model so you need to find a module removed from exactly same model machine or it wont function even if all the part numbers match.

I removed the module from its plastic housing after removing all the connections. It is a very simple operation. It was in perfect condition (it looked like it was manufactured very recently) and there were no cracked solder joints etc. Below is a picture of the module from top:

The problem resistors are located on the lower side near the large tabs where the heater cables are connected. Below is a close up.
The problem relay model was HF7FD 012-1ZPTF(576) . There are 2 relays because the heating element consists of 2 parts. Perhaps quick wash uses both relays to heat up the water faster and therefore it was working more often (assuming one of the relay was working better).

What we did was to go to the local electronics store and buy a replacement relay. The replacement we found was RELPOL RM50-3011-85-1012 (unit cost ~3€). It is not a perfect match but the best available in such short time. You may want to go with an 12A or 16A resistive load relay if you can find it in a size which is suitable. I have to remind here that The HF7FD model was a 6-pin switch however you can replace it with a 5-pin version of a similar switch. There is only about 2mm space on top of the relay. The original HF7FD relay was of size (Depth x Width x Height) 16 x 22 x 16.4 mm. You may be able to fit another with a maximum height of 18mm. But I didn't try this and since the RELPOL switch was smaller, this was no problem at all. Picture below shows the dimensions of the HF7FD relay.
I used a manual solder vacuum pump to remove the solder from the original relays. It was very easy to vacuum the solder since the board has rather large holes compared to legs of the relay. The pump could pull out the solder easily.

After removal, simply cleaned the holes on the board with electronics cleaner and then soldered the RELPOL RM50 to same places leaving 6th hole empty. I am not exactly sure why the relay needed 6th pin actually. It seemed rather redundant.

For now, the machine works perfectly. No doubt the relays will fail again, but at least now we know how to easily fix it.