Categorie archief: Projects

WebPi: Web server and reverse proxy

For WebPi, the computer that would become responsible for the connection between my local area network and the world wide internet, an RPi3 was chosen. The idea was to install a renowned web server software package on it, Apache.

The first step is installing the operating system, Raspbian. Since the machine would run without console, the light version should be sufficient. Any missing packages can be added anyhow. At the time of writing, the latest version is Stretch. That proved not to be fully stable yet for the subsequent steps, so I chose the previous version Jessie (2017-04-10). Installation runs smoothly and after changing the host name, allowing SSH and setting the time zone the machine is ready for use. Important issue is here to set a new password for the standard user, pi, otherwise the vulnerability of the web site and subsequently the whole local area network will be at stake.

There are quite a few descriptions available on the internet to install Apache, I chose the one that was clearly aimed at the kind of RPi I was using: “How to Make a Raspberry Pi Webserver” by Alok Naushad. It is intended for RPi2 but appears to work as well for the RPi3 with Jessie Lite. All steps were followed until setting a static IP-address. In my router, a Fritz!Box 7581, there is no need for that, as it has a primitive DNS for the connections within the LAN, e.g. . This will keep track of a correct IP-address. The router also has the option to fix the IP address to the MAC address of the device but that appeared unreliable. Furthermore, my internet provider already has a host name on the world wide web set for me so there is also no need for that step. Although this host name is a bit clumsy as it contains the whole IP-address it can be used. In practice, the user should not need to use this host name but it will be used for a dynamic link to the web site(s).

An important issue is the security of the web site as it provides the access from the world outside to the local area network. Again, there are many descriptions – right and wrong – that describe how to do this. One that, in my humble opinion, is very well written and stands out for clarity is the answer written by Thomas Ward in response to problems associated with this issue. It clearly describes how to set ownership of the various folders as are accessible from outside.

The second step involves setting up the Apache web server so that it will pass on html-information from the various other RPis in the local area network, such as control of the central heating system, solar heaters, etc. to the outside world without compromising  the machines or the network. Of course the web site of Apache has a description, albeit a bit brief. A better description was by LeaseWeb Labs, but actually a combination of various examples finally gave the hint. The essence is to set up the reverse proxy virtual host configuration in “/etc/apache2/sites-available/yourwebsite-proxy.conf”. Mine essentially looks like

<VirtualHost *:80>
DocumentRoot /var/www/html
ProxyPreserveHost On
ProxyRequests off
ProxyPass /pi1
ProxyPassReverse /pi1
ProxyPass /pi2/
ProxyPassReverse /pi2/

From the web, the machines are now available as etc. The ServerName is the one provided by my provider. the other names come from the router and host name settings. There are two examples, one where a port is different, 8083, from the standard 80 and one where the html-information is in another directory. One remark though: it is possible to replace the host names by their IP-addresses; this is extremely helpful while testing.

Finally, there are free services that test the security of the web site. I tried ScanMyServer and it gave 60%; most problems are associated with the older version of Apache but there is no more recent version available for RPi or one has to do the compiling and further processing oneself. For the time being good enough.


Programming 433 MHz remote control key fobs

Remote control key fobs are typically  used for garage doors and the like. Also car door opening systems use them. The protocol of these devices seems to be relatively standard. When pushing one of the buttons, series of radio frequency (rf) pulses are sent that are subsequently received by the door opening equipment. These  compare the received code sequence with the internally stored code and when equal open or close the door. This principle is also used for controlling lighting, transmitting weather station information, etc.

This little report is on so-called key fob’s as displayed above. These are currently abundantly available on the web. They have the advantage that they have a mechanism by which they can be programmed from another key fob. The procedure is relatively simple but requires some persistence: eventually it will work:

  • Push the A and B buttons simultaneously. The LED goes on and after some time it starts to blink fast. This indicates that the key fob is erased and the buttons can be released.
  • Now, upon pushing any of the buttons the LED only blinks once very short. This indicates no code is transmitted.
  • Let us call this “empty” key fob number 1. The key fob from which we wish to copy is number 2.
  • We will now copy the code of button X, either A, B, C or D, from key fob 2 onto key fob 1 button Y (A, B, C, or D).
  • Push button X on key fob 2, its LED will burn continuously to indicate it is transmitting the code sequences.
  • Push button Y on key fob 1, its LED gives an initial short blink and then remains off.
  • Bring the two key fobs, while keeping the buttons pushed, together, usually front to front but other positions may also work, until the LED on key 1 will start to blink. Then the buttons may be released.
  • Push now button Y on key fob 1 and the LED should shine continuously to indicate that it is transmitting a code. If everything went well this code also activates the door that was controlled by key fob 2.
  • This can be repeated for all four buttons. Identical codes for two different buttons can also be programmed, the key will not complain.

Important to note is that similarly looking key fobs may have different, albeit similar, protocols. Follow the seller’s instructions where necessary.

One may also purchase a control unit that contains two relays that can be controlled from two buttons of an above described key fob. These units also need to be programmed, although they do come with pre-programmed key fobs. The unit has a DIP-selector that sets the control mode. Here we use that a single button switches both on and off. The unit has two LED’s that are next to the relays and indicate the status of the relay: on or off. Close to the control button there is another LED. It blinks upon receipt of a coded rf signal from a key fob.

If one wishes to operate with different codes than encoded from the factory, one proceeds as follows

  • The codes are erased by pushing the button until the LED starts blinking.
  • Now, the keys cannot switch the relays anymore although the LED may blink to indicate that a code has been received.
  • Pushing the button on the unit once brings the unit into programming mode, the LED goes on.
  • Push on the key fob first the button that is to control relay A. The LED will blink to indicate reception. Release the button. The LED remains on.
  • Push now on the key fob the button that is to control relay B. The LED will blink to indicate reception and go off.
  • The unit is now programmed. Pushing the two buttons will now activate relays A and B.
  • Note, that pushing twice the same button will only program relay A!

It may be interesting, to use a completely different code with the key fobs and the unit. Such is described for a Raspberry Pi by an instructable written by george7378. Below an example of a trace of a button code.

The rf signal is on during the “high” time, typically about 0.5 ms, and off during the “low” signal, about 1 ms. These sequences are repeated with an interval of about 10 ms so that hundreds of code sequences are sent by pushing the button for a second or so. The code can be easily read, a short high followed by a long low is interpreted as a binary 1 whereas a long high followed by a short low is a binary 0. The binary code sequence thus consists of 25 bits, here 1111 0000 0101 0110 0101 1110 1. There are 225 = 33,554,432 different codes possible with these 25 bits.

With the little Python program described by the above mentioned instructable it is relatively simple to enter ones own code. Using a 17,2 cm antenna on the 433 MHz transmitter makes coding the key fobs quite a lot simpler. Especially if one makes the number of sequence repetitions large, i.e. change NUM_ATTEMPTS from 10 to 100.

There are many different codes possible already with this 25 bit sequence, but if one imagines that the number of bits, the “high” time, the “low” time and the repetition time can all be varied at will one sees why there usually is not too much interference between units and key fobs of various origin. There will be limits on the timing and codes used, but a lot of variation remains for a given set.

A few remarks on the programs described in instructable.

  • It uses the same GPIO port for sending and receiving. I found it easier to have different ones so that both units can be connected simultaneously.
  • Using on the first line the code

    and making it executable by for instance

    chmod +x

    allows one to simpler call the program as

    ./ a_on

    and repeat its operation.

  • Rather than using, the program to read the code sequence from key fobs, I prefer to use my Logic 4 Digital+Analog Logic Analyzer from Saleae. It gives much more freedom in analyzing the data.

RPi Zero: combined power and ethernet connection

The Raspberry Pi Zero (RPi-0) is a wonderfully small PC-board with a lot of  functionality but without an internet connection, either wireless or ethernet. For many stand-alone applications, such as a surveillance camera, a power connection and an internet connection are sufficient. Of course one could use a wireless connection (WiFi) but these are not that reliable and often temporarily drop connection. Therefore an ethernet connection is preferred. The wiring to the RPi-0 would then involve two items: power cable through one micro-USB port and the internet connection using the other micro-USB port. Both a WiFi-connection or an ethernet connection require a relatively bulky piece of hardware: the beauty of a tiny processor with camera is lost!

But in many applications, USB-cables are used both for power and communication. So, if one uses a standard micro-USB (B male) to a standard male USB A cable all further gadgets can be in another place, for instance in house. Cable lengths can be 3 meters and maybe more! At the other side one has to split to ethernet and power or to USB and power. For the latter, splitter cables are available. For the first I used a standard ethernet to USB converter and added a power cable and a female USB A connector, see above. The latter connects through the cable to the RPi-0 and the other to a power supply. For the power connection I could also use a USB connector but that would be confusing.

The USB to ethernet converter needs some rewiring, see below. The USB cable has been removed and replaced by a cable with the USB female connection. The wire colors are not always following convention, so testing the cable with a multimeter is advised.  The power cable was connected in parallel, the connector is a standard power cable as used on the better wall plug power supplies. Note that at least 2 Amperes are required to run the RPi-0 reliably.

The cabling is already in use with a home-made surveillance camera and runs uninterrupted for over a month now.

Doorgangsmelder serredeur

Het was al gemeld bij de vervanging van de deurbel dat er ook een doorgangsmelder bij de serredeur nodig was. Het heeft even geduurd, maar die is er nu ook. Op de bel in de werkkamer klinkt nu een gong als aan de voordeur wordt gebeld en klinkt gefluit van vogeltjes als er iemand door de serredeur gaat. Ook gaat de flitser af maar die zie ik alleen als het schemert of donker is.

Er zijn verschillende vormen van doorgangsmelders in omloop maar voor de toepassing bij de serredeur wilde ik liefst zo min mogelijk bedrading. Dat sluit de meeste zelfbouwpakketten uit, want die bestaan uit een losse zender en ontvanger. Ik heb nog wel wat geëxperimenteerd met spiegeltjes en reflectoren maar dat werd niet echt een  bevredigende oplossing. Een veel elegantere oplossing zou een van de reflectielichtsluizen van Contrinex zijn, zoals de LRS-1180-304. Met een schakelafstand tot 2 meter zou de breedte van de deur makkelijk te overbruggen zijn. Alleen de prijs stond me wat tegen. Toen ben ik wat gaan zoeken op en op en daar vond ik wat ik zocht tegen een redelijker prijs, ongeveer 25 euro. Ik kon zelfs een exemplaar bemachtigen met nog een kabel er aan uit een sloopproject. Als ik wat meer geduld had geoefend dan had ik nog wel goedkoper uit kunnen zijn.

De drukknopzender van KlikaanKlikuit zoals ik die ook voor de voordeurbel gebruikte kon hier goed op worden aangesloten. In feite kon ik met een kleine voeding van 12 Volt (300 mA) zowel de reflectielichtsluis als de zender voeden. Ook de bedrading is relatief simpel. Alle voedingsaansluitingen worden gekoppeld zoals gewoon. De schakeluitgang van de reflectielichtsluis – een pnp-transistor naar de +12 Volt – kan direct aan de schakelingang van de drukknopzender worden verbonden.

2016-11-19-13-56-43-2Een houten sigarendoosje past wel in de kast naast de serredeur en daar heb ik dus het zaakje gemonteerd. Op bovenstaande foto zie je duidelijk rechtsboven de reflectielichtsluis, rechts de aansluiting op de netvoeding en rechtsonder de printplaat van de drukknopzender. Het kastje van de drukknopzender was iets te groot, dus die heb ik er uit gelaten. Een klein stukje dubbelzijdig plakband  voorkomt dat het doosje per ongeluk kan verschuiven. Dekseltje dicht en het geheel kan zijn werk doen.

Water pressure sensor for Raspberry Pi

A pressure sensor is a necessary part of any pressurized liquid system such as a solar boiler, the central heating system in a house and even a car. In all these systems it serves as a monitor on the well being of the system, in particular whether the liquid is still inside or whether there is a leak. Typically, it comes in the form of a pressure gauge somewhere attached to the tubing of the system. Only very recently are there electronic readings and this is usually for a central heating system. But solar boilers are also useful to monitor, just because they are more exposed to extreme weather conditions, and so the idea was already for a long time to install such a device.

But which one to take? The simplest form of such a sensor is a switch that opens when the pressure is above a given minimal value. These are found in the more normal cars, only fancy cars have a more involved one that actually gives a value for the pressure. Whether oil or (cooling) water pressure sensor, both are of the membrane kind because that gives the most rugged form. They are typically provided by VDO but sometimes cheaper look-a-likes are also available. They are frequently offered at a significant discount at Ebay. The membrane separates a pre-pressurized compartment from the compartment of which the pressure has to be taken. The membrane in-between deforms with the pressure difference and this is recorded by means of a strain gauge attached to the membrane. Typically the resistance of the strain gauge varies about 20 Ω per Bar.

Such resistance values are fine for car-applications. The moving coil meter that is usually attached to it through battery power will have a relatively high current to control its position and hence it remains relatively insensitive to vibrations. But for electronic applications it is not so easy as it means high currents that are not available from the RPi or the like of credit card computers. This calls for a special solution that took some while to be found.

First the selection of the pressure sensor itself. The solar boilers do not have a lot of water in them, 5 – 10 liters typically. The solar boiler also contains a pressure vat, a pre-pressurized compartment in contact through a membrane with the system liquid. The vat does not need to be big for a solar boiler, 8 liter is the smallest I could find though. It is pre-pressurized at 0.5 Bar. The bigger ones are at 1 Bar. The function of the vat is to compensate for the volume changes of the water during heating and cooling. To do so, the pressure should go at 1 Bar for the 0.5 Bar pre-pressurized vat. It then has the range from 0.5 Bar up and down to vary the position (and shape) of the membrane while heating or cooling. So, the set value at 20 ° C is 1 Bar and during operation and during outside temperature variations it may vary between 0.5 and 1.5 Bar. The latter are extreme values but possible. The maximum pressure in the system is set by a valve at 2.5 Bar. This will only be reached for instance when the pressure vat malfunctions (leaking membrane). Summing up: a pressure sensor is needed from 0 – 2.5 Bar with a good accuracy around 1 Bar.

Other conditions on the pressure sensor? Most have one of the two strain gauge contacts grounded. This is a good idea for cars where the instrument mass can serve as conductor: it saves wiring. For a microcomputer connection it is not so smart, so try to get one with free contacts (massless) to achieve galvanic isolation. The one that would be preferred (and available) is a VDO 360-081-032-NNNC that can be obtained with various couplings depending on the threading used in your system (different values for NNN). They are not cheap, of the order of 50-100 euro, but they are not expected to break down easily. If they do, there is a guarantee. A word aside on nomenclature: one will find pressure sensors under all kinds of names (Druckgeber, sender, Druckabnemer, etc.) neither of which is particularly appropriate so be prepared to select broad keywords to locate a decently priced item.

How to interface them. Because of the low currents available and the low resistance values offered by the strain gauge, one needs an analog-to-digital converter (ADC) that is capable of converting a small voltage, say 250 mV, to a minimally 8 digit number for accuracy. Interestingly, this is what the DS2438  Smart Battery Monitor by Maxim Integrated delivers. It has two ADC inputs, one for the higher battery voltages and one for the battery current measured across a small resistor (necessarily to avoid excessive loss due to the measurement itself). The chip has 1-wire interface that combines with temperature sensors of the type DS18B20, also from Maxim Integrated. The required electronic circuitry is minimal and in actual fact only requires either a current source or a (relatively) large resistor in series with the strain gauge. In the latter case some a-linearity is introduced that, as it is monotonic, can be corrected for. Using the simplest scheme with a resistor R from the strain gauge to the supply voltage of 3.3 Volt, the resistance Rg of the strain gauge is derived from the convertage voltage V as

Rg = (V / 3.3)*R

and with the calibration curves given for the pressure sensors one can then compute the pressure.

Where the temperature sensors DS18B20 are well provided with software drivers, the DS2438 unfortunately is not. The Python software that exists for the Raspberry Pi is just crappy. So I made a little C-program to take the value from the pressure transducer. Those interested can approach the author for a copy. When using programmed I/O, which is the simplest to implement, the data loss is something to worry about. But since taking a sample is so fast, there is no problem to repeat the reading procedure a few times until a sample has been successfully read. A more reliable procedure uses a UART (serial interfacing circuit) but then requires a little more hardware.

The pressure and temperature sensors are installed for a few weeks now and perform satisfactorily. I will install another one with my other solar heater system soon.

Lantaarnpaal bij bouleveldje

Midden tussen de huizenblokken waarvan onze woning deel uitmaakt ligt een speelveldje met wat attributen voor kinderen. Ook voor volwassenen is er het een en ander: twee banken en een tafel maar ook een heus jeu-de-boules-veldje.  Niet dat er veel gespeeld wordt. Voor zover ik weet eigenlijk alleen de dag volgend op het jaarlijkse buurtfeest.

IMG_20160609_120235Maar natuurlijk zouden de buurtgenoten wel vaker willen spelen, maar meestal is het dan al donker en de lantaarn bij het veldje is wat ver weg. Althans, dat was de klacht zo’n 10 jaar geleden.
Lees verder Lantaarnpaal bij bouleveldje

Deurbel vervangen

Het zal is wel in een keer goed gaan! Omdat ik slecht hoor – zeker als ik in mijn werkkamer op de eerste etage of de hobbiekamer op de tweede verdieping zit – is het nodig om mij te waarschuwen als iemand aan de deur is of als er iemand via de serredeur naar binnen loopt. Daarvoor hadden we van de firma Heidemann wat spullen: een elektronische gong voor op de eerste etage, een belknop-zender bij de voordeur en een bewegingsmelder bij de serredeur. Aanvankelijk voldeed dat prima maar af en toe – en de laatste tijd in toenemende mate – kwam er vals alarm van de detectoren.
Lees verder Deurbel vervangen

RPi repair: SD card slot

The Raspberry Pi uses as disk memory an SD card and for that purpose  has an on board SD card slot. The component is badly designed and breaks down easily as many an RPi owner has found out. It is a pity that the card holder is not more robust but on the other hand, the overall cost of the board had to be kept at a minimum.

2016-05-14 09.08.59

Anyway, the slot breaks down easily which gives rize to irratic behaviour. Lots of ideas have been posted to repair it and these range from glueing a piece of credit card on top of the card holder to replacing it by a micro SD card holder. None seemed satisfactory to me and I looked for a more robust solution.

It turns out that almost the same card holder is made by Würth Elektronik under the type name  WR-CRD. The advantage of this model is that it uses metal to force the card into position and not plastic as was the case with the previous one. The card holder is almost the same because, where the original has two switches the replacement only has the one for detecting the presence of the card. Carefully desoldering the broken card holder and – with slight bending of the contacts of the new card holder to the soldering pads before soldering will have an immediate positive result. It turns out that the other switch for detecting write-block is not necessary: the contacts can be left free (on the photo the top two small soldering pads).

This card holder now already is in function for half a year without problems. I assume it will last “forever”,  i.e. as long as the RPi itself!

Note added after repairing the second RPi. There are two issues to take care of: (1) the orientation pins on the back side – made out of plastic – should be removed so that the socket mounts flatly and (2) only the connections to the switch needs to be bent slightly to avoid short circuiting across the soldering pads.


LircPi : nieuw apparaat bedienen met een stokoude afstandsbediening


The project got started after a friend remarked that he could not find  vhs-players of a particular model and brand anymore. Before, I have helped him getting such machines going again, but given their age it is not surprising that more and more of them gave up. He needed these players for his partner who is not really capable or learning how to work with other remotes. Lees verder LircPi : nieuw apparaat bedienen met een stokoude afstandsbediening

LED lamp driver with remote control

Most spotlamps to build into a ceiling are ridiculously high, 8 cm or more. The reason is that most of them are still to fit halogen lamps that require a special mirror and produce a lot of heat. LED lamps should not have this problem because they spread light better and because they are so efficient as to not produce a lot of heat. But most lamps are still high, even if these contain LEDs, probably because companies need to get rid of parts/machines first before they renovate Lees verder LED lamp driver with remote control