Tag Archives: howto

DIY MQTT smart plug with MicroPython…

I’ve been playing around with MicroPython and Home Assistant. MicroPython is a ‘bare-metal’-Python flavor that you can use to program ICs. Home Assistant is a home automation and home control software written in Python 3. It can be hosted on a Raspberry Pi. It enables you to connect a vast amount of different devices: lights, switches, sensors, locks etc.

This is a raw guide on how to make your own smart plug and connecting it to MQTT which is then connected to Home Assistant.

You will need a relay board (single relay), a NodeMCU board, a power adapter for 5V, a case, a button, some wire and a 1k resistor.

Connect the devices according to this schema (WARNING: Don’t do this if you’re not comfortable handling mains power!). Don’t forget earthing (it’s not on the diagram):
circuit diagram

Flash the MicroPython firmware to the NodeMCU board. Put the ‘relay_mqtt.py‘ file on it as main.py. That way it will be run when the device boots up. Adjust the code to connect to your network and MQTT server first.

You can download the code here.

My device looks like this:

See the Home Assistant documentation for how to integrate the MQTT part with Home Assistant.

The nice thing is: you can press the button to switch the device. The status of the device will update via MQTT and Home Assistant gets a correct status update. You can of course switch the device from within Home Assistant as well.

Happy hacking!

Flattr this!

HOWTO setup your very own Jabber server…

XMPP (aka Jabber) in combination with OTR is a secure way to chat with others. There are some public servers available, but their popularity centralizes the infrastructure and leaves single points of failure. A recent example is Chaos Computer Club’s Jabber server (jabber.ccc.de) which was down for some days between Christmas and New Years 2014/2015, as a consequence of a DOS attack.

I’ve been setting up a Jabber server of my own on my Raspberry Pi. Here is how you can too:
Continue reading HOWTO setup your very own Jabber server…

Flattr this!

Hetzner Root Server Networking Configuration…

I’ve been setting up a new server at hetzner.de.
I ran into problems when configuring the network. The server is running Debian (wheezy).

hetzner network info
note the last line: “The additional route to the gateway is now no longer necessary.” not only that: it will not work.

The basic configuration looked like this:

## /etc/network/interfaces example Hetzner root server
# Loopback-Adapter
auto lo
iface lo inet loopback
# LAN interface
auto eth0
iface eth0 inet static
# Main IP address of the server
# Netmask (/32) independent from the
# real subnet size (e.g. /27)
# explicit host route to the gateway

This should work, as mentioned in the Hetzner DokuWiki.

I added DNS servers at the end (use your DNS servers here or pick an open DNS server)

dns-nameservers X.X.X.X Y.Y.Y.Y

at the end since I’ve resolvconf installed.
eth0 did not come up correctly.

When trying ‘ifdown eth0; ifup eth0’ I kept getting:
ifdown: interface eth0 not configured
RTNETLINK answers: File exists
Failed to bring up eth0.

This error would show up at boot time or when trying to start eth0 by hand.
The setup would look fine otherwise, IP was correct network seemed to work, but the DNS-servers were not added correctly. Weird!

‘ifdown –force eth0; ifup eth0’ worked. Server went off for a second but came back. with DNS-servers setup correctly. Interesting!

I started to comment out lines from /etc/network/interfaces.
Et voilá!

It turns out: It is deadly to try to configure ‘gateway’ in /etc/network/interfaces!

Finally I used this:

## /etc/network/interfaces working Hetzner root server
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
# next line optional
## never EVER use the next line! you have been warned!
## gateway
dns-nameservers X.X.X.X Y.Y.Y.Y

I hope this post will save others some time to fix this issue with their setup.

Flattr this!

Adding SSL to transmission’s web interface…

If you’re using transmission’s web interface to manage your torrent downloads, and you are doing this remotely (from outside your LAN), you might want to add some privacy.

As previously posted there are ways to use magnet links with transmission’s web interface. This webinterface works well when you are on your local network aka LAN and don’t have to fear prying eyes.
The moment you’re using the transdroid android app or your laptop in a coffee shop the commands and responses of your transmission daemon at home can be read by anyone.

Luckily the transdroid android app offers an SSL option. All you have to do is configure a proxy on your transmission daemon machine.

Here is how:
Install nginx (a lightweight http/https server):
apt-get install nginx
Continue reading Adding SSL to transmission’s web interface…

Flattr this!

miniature time-lapse with fake tilt shift (howto)…

i recently came across some videos that took my breath. tilt shift time-lapse videos. they produce kind of a miniature look combined with a stop motion and time lapse feature that was just nice.

of course i wanted to make one 🙂

here is how: Continue reading miniature time-lapse with fake tilt shift (howto)…

Flattr this!

How to make time-lapse videos on a motorcycle…

a few weeks ago i got my hands on a motorcylce camera stand (thx Patrick). one that was actually made for a motorbike and not a modified tankbag with rubber wraps. please don’t ever use those and please do never put a camera into your helmet as some youtube idiots present.

the camera i used is my canon ixus 750. since the lense on this camera is rather low i had to improve the camera stand. i added some aluminum ducts to make it higher and to make the camera see the street. about 7 centimeters were enough.

since i was not able to get the CHDK timelapse to work i shot video. to generate a timelapse i used ffmpeg to extract images out of the video and to unite them to a timelapse video.
using this tutorial and the man pages i was able to come up with this:

# sample usage: ./timelapsify.sh input.avi output.mp4
mkdir ffmpeg_temp
ffmpeg -i $1 -r 1.4 -f image2 ffmpeg_temp/%05d.png
ffmpeg -i ffmpeg_temp/%05d.png -sameq $2
rm -rf ./ffmpeg_temp

note that it is important for ffmpeg to have the images you use to generate the timelapse video in order and sequenced. if you decide to delete some images you have to rename them and must not leave gaps.
also you may have to vary the rate (i used: 1.4) acording to the speed of your input video and the speed of the output video you want to have.

one step i did between extracting and generating the timelapse was sending it through imagemagick to blend the speedometer. using info from this mailing list:

#usage: pixelate_circle.sh IN.file OUT.file center_x_coord center_y_coord border_x_coord border_y_coord
convert $1 \( -clone 0 -scale 10% -scale 1000% \) \
\( -clone 0 -gamma 0 -fill white \
-draw "circle ${3},${4},${5},${6}"\
\) -composite $2

of course this has to be done for every image 😉

and here is the resulting video:

Flattr this!