WIZ550web interacting with professional homeautomation KNX bus

Prerequisite – Why KNX

I’ve been renewing a part of my house and as I always wanted to have some home automation – the decision was set. It was not easy and I was quite long considering what to take. There were so many wireless and wired solutions available. I did not want to go for wireless – at least not as primary system. I already used some remote controlled plugs – but I’m sick of changing empty batteries. Sometimes messages got lost, so I had to press the buttons twice. So the decision was set to take some bus system. There are a couple of vendors that provide actuators and sensors. There are also some free implementations available, like Freebus, which directly couple to the bus – so you can build your own devices.

For me there were some criteria important: reliable function of basics, no battery changes, interaction with my Fhem home server possible. The reliability was most important for me. Basic functions like switching light on and off, should always work. A worst case scenario, which I was thinking of, was: I’m in a bright house in the evening on the way to bed, and then the home server got messed up by some update or reconfiguration and I cannot switch my bedroom light on, and the other part of the house off! So my decision was, all the parts for basic functions have to be “off the shelf”. All the additonal functions (automatic light switching, automatic blind control, etc) don’t need the same level of reliability (Even i did not require that in the beginning, I reached a quite high level in the end). Even I like to hack or build stuff on my own – I want to have the possiblity to just “buy” spare parts if something breaks.

I thought this would be a good base. KNX is based on the EIB (European Installation Bus) and uses usually Green wires similar to telephone cables 2 x 2 x 0.8 mm2. Two of the wires are used for the bus communication and can also power devices with 29V. The other pair can be used for an auxiliary power source in case your device needs more power, or the bus communication is disturbing.

So finally my home got (at least partially) touch panels in the rooms for light, blind and heating control as KNX sensors. The lamps are controlled by KNX actuators directly from the mains distribution.

Based on that system I’m now able to implement fancy home automation stuff.

automated light – motion sensors control with server

My wife often complains that I do not shut the light off. But when I want to return soon, I let it on. So I decided to go for an automated solution with motion detectors- thanks to KNX it’s an easy task. You just set the actuator to stairway mode with. In that mode the light will go automatically off after, e.g., 90 seconds. As I have dimming actuators it’s even possible to set some warning time, so 20 seconds before the light will go off it will dim to 50% – so even something goes wrong I can still use the remaining light to switch back to 100%. So the configuration of actuator was an easy task, but when I wanted to order PIR sensors for the KNX bus, I almost fell of my chair. 100EUR each – and I wanted to have around 10! That’s why I thought here I go for my own development. I found on ebay some PIR sensor modules for around 1 EUR (!) each from China . As I was not in a hurry I ordered and around 3 weeks later they arrived. evb-pir

Right after the modules arrived I took one and connected it to one GPIO of a WIZ550web-EVB. The output of the PIR module is 3V so it can go to the GPIO of the module directly. This is good, as I don’t want to use an EVB for my “production” use and just the module itself. The WIZnet module has a preinstalled demo web page, which makes it possible to directly access the inputs and outputs. So after powering up I was immediately able to see that the Webpage showed Input D8 was high for some seconds,  when I was moving around.

First I thought there was an instability during boot. Whenever I pressed the Reset button on the board, the module did not come up and was waiting in the bootloader! But as I figured out this is not a bug but a feature. D8 has a second meaning during boot – in case you mess up the application code, you can pull D8 high during reset and the module will wait in the bootloader! This was not so good in my case, as soon as I moved my hand in direction of the Reset pin, the PIR module raised the level of D8 to high! To circumvent this for development, I just moved to another Input pin. (As look ahead to part2: I recompiled the bootloader and removed this feature, as i wanted to use all input pins without limitation – in case something really goes wrong during development, I can easily reflash the module via serial line – but if D8 is high during boot while in production use my application will “hang”)

Eibd on home server

Fine now I have a website with a virtual LED showing motion. I have an Alix-D3D board (this could be an Raspberry or something else today) hosting my FHEM server. To communicate with the KNX bus I need some Modem. I ordered a TUL from busware.de which can be connected via USB. The TUL is not standalone you still need an eibd on the system to communicate with the bus. There are also some gateways on the market that have already implemented it, but they cost more.  Eibd can also be a gateway to the ethernet. This is handled by multicasts, so the KNX bus is then available also as let’s say “virtual bus” on the ethernet also. IP devices can join that multicast group and get also all messages same as they were on the physical TP bus. gateway(look ahead: I will use that gateway function later)

Anyway, for my first try I don’t use that gateway functionality.But as the Eibd is running on that system it is possible to directly execute the “group(s)write” command on the command line and send a group message to the KNX bus.

Now I wrote a small script that is getting the output of WIZ550-web via php (php5-curl) every second. If D8 is “1” then ‘ON’ is sent to the actuator. This worked out of the box, but I’m not happy with it. I absolutely don’t like the polling every second. Even it’s my LAN that can easily manage that little data, it hurts my engineers heart if unneccessary data is constantly transmitted with http overhead every second. It’s a little bit like a dripping watertap. So as I had formerly seen, Eibd can be setup as a Gateway, so it’s possible to send directly a multicast to switch on the light…

Part2: Talk “Directly” to KNX devices via Gateway.

com-waysMy next idea was to write my own Firmware for the WIZ550web. systemAs the Eibd is transferring the KNX bus data to the ethernet, the module shall directly communicate with the KNX bus. So no more polling every second, just one packet for switching on the light.

Another goal for me is receiving multicasts on the module to get feedback. I wanted to control the module also. The module needs some information if it is currently night – because at night I don’t want to have a bright bed room in case the cat walks through…

(Look ahead: In part 3 I’ll also use this to control my projector and my power amplifier)

So first I had to install the toolchain and get the source code of WIZ550web.

Toolchain – Compiler and Eclipse

The following two articles describe how to install the Toolchain on a Linux System:

https://wizneteu.wordpress.com/2015/03/19/install-eclipse-and-compiler-for-stm32-with-w5500-on-linux/

https://wizneteu.wordpress.com/2015/03/19/flashing-stm32-via-serial-line-on-linux-stm32flash/

Import Source code to Eclipse

The following article is describing how to import an repository to eclipse. It also shows how to fork a repository. For further processing I suggest you sign up for a free github account, then fork the repository directly on github.com.Bildschirmfoto vom 2015-03-31 16:16:24 When you fork it to your account you are able to commit your changes to your repository so others can also participate. I have a branch “freebus” beside my “master” branch. That’s what you need to use when you are in eclipse.

https://wizneteu.wordpress.com/2015/03/19/import-github-project-of-the-webserver-wiz550web-to-eclipse/

https://github.com/7tobias/WIZ550web

Here you can see a picture of the Git Repository view of Eclipse:

eclipse-git

 

Currently I use a small python script to catch the multicast packets that are already on the bus, and I replay them with my module. It would be even nice to configure the module via the ETS software but that’s something for the future. For the beginning I’m fine with it how it is currently.

The module is checking the status of the input pins, as soon as there is a rising edge on a watched pin my multicast is sent out and the light is on…

Using the plain module

powerregulator web-wpowerAs I don’t need the complete EVB for my “production use” I bought some 3V voltage regulators. I added some jumper cables, so I can connect the power source directly to the module. As i don’t have any parts beside the power regulation I skip a special EVB; all PIR outputs are connected directly to the input pins of the module. In the picture on the right side you see only one PIR.

 

Part3: Control of Projector, Projection Blind and AVR Power Amplifier

My next step is using a second module to control my home cinema in my living room.

I have:

  • Projection blind
  • Projector Epson
  • AVR Denon power amplifier

Projection blind control

My blind is motor driven and has a RF remote control. So I soldered just some cables in parallel to the buttons of my remote control. These are attached to the relays of the EVB. When I want to roll up or down, I just have to close the circuit via the relay for a certain time, e.g., 0.3 seconds similar to what a human would do.

Projector Epson

My Projector has a RS232 port. It’s possible to control many things on that port and ask for error codes. But my primary use case is just to switch it off and on. All the other settings stay currently the same. So just have to wait for “:” as command prompt then I can send “PWR ON” or “PWR OFF” with 9600 bps on the serial line and the projector is starting or shutting down. If I ask with “PWR?”, I can get “PWR=01” or “PWR=00” as answer. I ask this every couple of seconds, as I also want to send feedback to the KNX Bus in case someone is switching on my Projector manually – so my touch panel is showing always the correct state.

AVR Power Amplifier

The Denon AVR is in one thing ahead of the Projector. Every time some setting is changed (input, volume, power, etc) this information is directly sent to the serial line. So I do not need to ask the AVR regularly for changes. That’s quite nice. Beside that the protocol is documented and not very complex. Basically I need power on and off the main zone. I also need to select the input source, and I want to control the volume of the main zone.

 

Conclusion

This setup is working well. I do not regret that I went for this solution combining KNX with my self made addons. I’d go for it again if I had to choose. There is still plenty of room for enhancements. I’ll report when there is something new.

Import Github project of the Webserver WIZ550web to Eclipse

In the load-two articles I Showed how to install the toolchain and how to flash the binary with stm32flash. This article will show how to import the project into eclipse with git Directly from Github. Git is a very powerful version managment system. GitHub is a platform implementing a git server with more nice tools for collaborating. If you do not know it yet, give it a try – you will be amazed how easy collaborative work will be.

So first we have to decide Which repository we will use. The primary repository can be found under https://github.com/Wiznet/WIZ550web. But at the time of writing this article there were some small errors as the case of some letters in file names were different. So on this case sensitve operating systems lead to compile errors. To circumvent this I forked the project and you can therefore clone my repository https://github.com/7tobias/WIZ550web

In case you want to publish your work so to others it would be even better to fork one of the mentioned repositories into your own github account. Then you can push your changes to your own github repository. You should give it a try, it’s very easy – and as public repositories are free, it does not even cost you money.

In the Following I’ll clone my own repsository I forked in github before.

First start eclipse and just go to the “File” menu and choose “Import …”. There you have to select “Git” / “Projects from Git”. In the next dialog you have to choose “Clone URI”.

 

Screenshot from 2015-03-18 15:25:55 Screenshot from 2015-03-18 15:24:19

In the next dialog enter the URI – host and repository path will be filled out automatically. In case you forked the repository to your own github account, you should enter your username and password into this dialog to be able to push your changes later.

The remaining steps are of basically “Next”, “Next”…, and “Finish”

Screenshot from 2015-03-18 15:26:17 Screenshot from 2015-03-18 15:27:15 Screenshot from 2015-03-18 15:27:27

Now you have to click on “Workbench” to see the following window. Now, you are ready and can build the project.

Screenshot from 2015-03-19 09:42:13

by TW

Flashing STM32 via serial line on Linux – stm32flash

For Windows users there is a tool called “Flash Loader Demonstrator”. This obviously does not run on Linux, but there is also a possibility to natively flash a binary (or hex file) in case you cannot use the WIZnet update tools that use the bootloader. So this is basically needed when you want to upgrade the bootloader. In case you don’t have subversion installed you need to do the following in a console:
tw@kallisto:~# sudo apt-get update && sudo apt-get install subversion

After that you have to first checkout the latest sourcecode of the tool

tw@kallisto:~$ svn checkout http://stm32flash.googlecode.com/svn/trunk/ stm32flash

Then you can compile and install the tool

tw@kallisto:~$ cd stm32flash && make && sudo make install

Bildschirmfoto vom 2015-03-18 14:17:16

Now you have to bring the board into boot mode. There is usually some BootEnable pin. Hold that booten pin during power up or reset of the module. After that, the module is waiting for the following command:
tw@kallisto:~$ stm32flash –w combine.bin –v /dev/ttyS0

Bildschirmfoto-Namenloses Fenster

Generate Padding for the Bootloader

There is one important difference between the Windows version of Flashloader Demo and the stm32flash. In the current version of the stm32flash the complete flash is erased before programming. As long as you have only one binary for the application this is no issue. But in case you have a bootloader and an application the bootloader is erased when you flash the application.
As a workaround for this you have to combine the two files.
How to combine Bootloader and Application file.

As an example i’ll show how to combine the bootloader and application file of WIZ550web. As per note on http://wizwiki.net/wiki/doku.php?id=products:wiz550web:wiz550web_download the bootloader shall go to the adress 0x8000000 and the application shall go to 0x8006000. So as we will copy both files together the bootload needs some padding to be exactly 0x6000 = 24576 in size.

Bildschirmfoto vom 2015-03-18 14:30:56So first we find out the size of the bootloader. In this example it is 23312 bytes in size. So we just calculate 0x6000 – 23312 = 1264. To get the padding we just dump 1264 bytes from the device /dev/zero which contains an unlimited number of zeros into some file, e.g., zeroes.bin.

tw@kallisto:~$ dd if=/dev/zero of=zeroes.bin bs=1 count=1264

After that, we just add these zeroes.bin to the bootloader file.

tw@kallisto:~$ cat zeroes.bin >> WIZ550web_Boot.bin

If you check now with ls, you can see that the size is now exactly 0x6000 = 24576 bytes.

Bildschirmfoto vom 2015-03-18 14:48:01

Now we can combine bootloader and application file in the same way. Later when you compile only the application, you can reuse the padded bootloader file, and only need this last step.

tw@kallisto:/tmp$ cp WIZ550web_Boot.bin combine.bin && cat WIZ550web_App.bin >> combine.bin

Bildschirmfoto vom 2015-03-18 14:55:16

tw@kallisto:~$ stm32flash –w combine.bin –v /dev/ttyS0

There is one important difference between the Windows version of Flashloader Demo and the stm32flash. In the current version of the stm32flash the complete flash is erased before programming. As long as you have only one binary for the application this is no issue. But in case you have a bootloader and an application the bootloader is erased when you flash the application.
As a workaround for this you have to combine the two files.

How to combine Bootloader and Application file.

As an example i’ll show how to combine the bootloader and application file of WIZ550web. As per note on http://wizwiki.net/wiki/doku.php?id=products:wiz550web:wiz550web_download the bootloader shall go to the adress 0x8000000 and the application shall go to 0x8006000. So as we will copy both files together the bootload needs some padding to be exactly 0x6000 = 24576 in size.

Bildschirmfoto vom 2015-03-18 14:30:56So first we find out the size of the bootloader. In this example it is 23312 bytes in size. So we just calculate 0x6000 – 23312 = 1264. To get the padding we just dump 1264 bytes from the device /dev/zero which contains an unlimited number of zeros into some file, e.g., zeroes.bin.

tw@kallisto:~$ dd if=/dev/zero of=zeroes.bin bs=1 count=1264

After that, we just add these zeroes.bin to the bootloader file.

tw@kallisto:~$ cat zeroes.bin >> WIZ550web_Boot.bin

If you check now with ls, you can see that the size is now exactly 0x6000 = 24576 bytes.

Bildschirmfoto vom 2015-03-18 14:48:01

Now we can combine bootloader and application file in the same way. Later when you compile only the application, you can reuse the padded bootloader file, and only need this last step.

tw@kallisto:~$ cp WIZ550web_Boot.bin combine.bin && cat WIZ550web_App.bin >> combine.bin

Bildschirmfoto vom 2015-03-18 14:55:16

by TW

Install Eclipse and Compiler for STM32 with W5500 on Linux

This installation was done on Debian Wheezy

Contents Installation and Configuration of

  • Build Essential
  • GNU GCC ARM Embedded tool chain
  • Oracle Java SE
  • Eclipse
  • GNU ARM Eclipse Plugins

Tool Chain – Install Build Essential

First you have to install the essential tool chain. Go to a root terminal,e.g., with “su” and do the following:

root@kallisto:~# apt-get update && apt-get install build-essential

Tool Chain – Install GCC ARM Embedded GNU

Go to https://launchpad.net/gcc-arm-embedded and download the latest “Linux installation tarball”. Then extract it. Most likely your filename will not be exactly gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2 but a little bit different – so adjust this command line to name of the downloaded one.
root@kallisto:/home/tw/Downloads# mkdir /usr/local/arm && tar xjvf gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2 -C /usr/local/arm

If you want to have it available for you users without the need for absolute pathes you can symbolic link it to the folder /usr/local/bin

root@kallisto:~# ln -s /usr/local/arm/gcc-arm-none-eabi-4_9-2014q4/bin/arm-none-eabi-* /usr/local/bin/

If you like, you can check this from the user account:

gccversion

JAVA SE Installation

There are no Oracle Java SDK repositories for Debian Wheezy, but you can add the ubuntu repository.

root@kallisto:~# echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" >> /etc/apt/sources.list && echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" >> /etc/apt/sources.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886

then install Oracle JAVA 8 after updating the repository:

root@kallisto:~# apt-get update && apt-get install oracle-java8-installer

If you like, you can check this from the user account:

Bildschirmfoto vom 2015-03-18 11:18:53

Eclipse Installation

First go to  http://eclipse.org/downloads/ and download the latest Version of “Eclipse IDE for C / C ++ Developers” – depending on the Java Version you installed you should go for 32bit or 64bit. As my Java is 64bit I’ll go for 64bit.

Bildschirmfoto vom 2015-03-18 11:29:22

Now extract eclipse:

root@kallisto:/home/tw/Downloads# tar xzvf eclipse-cpp-luna-SR2-linux-gtk-x86_64.tar.gz -C /usr/local/

Bildschirmfoto vom 2015-03-18 12:40:48

On my Debian Wheezy Eclipse Luna crashed during start (https://bugs.eclipse.org/bugs/show_bug.cgi?id=430736) . So in case your eclipse doesn’t start either you also have to execute “export SWT_GTK3=0” before the start of eclipse. You can make this persistent with:

tw@kallisto:~$ echo "export SWT_GTK3=0" >> ~/.profile

GNU ARM Eclipse Plugins

On the eclipse IDE, go to the Menu line and select  “Help” -> “Install New Software”. The following window will appear, where you have to click “Add”.

Bildschirmfoto vom 2015-03-18 12:56:37

There you have to enter the following data.
Name: GNU ARM Eclipse Plugins
Location: http://gnuarmeclipse.sourceforge.net/updates

On the next page, just select “GNU ARM C/C++ Cross Development Tools” and after some “Next” and “Finish” clicks the installation is finished.

IoT5500 LanJack

IoT5500-hm

The Internet of Things embedded Ethernet connectivity module IoT5500 comes in a very compact footprint, barely any larger than the Ethernet socket. As the base module it can be connected directly to a host system via SPI or with the optional CPU+SD thin-stack module becomes a network server offloading the burden of network operations as a smart peripheral. Even more importantly too is that is very cost effective even when compared to many serial to Ethernet only solutions alone.

Based on the WIZnet W5500 hard-wired TCP/IP Ethernet chip the module is both compact and easy to interface to via SPI and is footprint compatible with the older W5200 based WIZ820io module.

IoT5500-P8-Q

IoT5500 Features

  • WIZnet W5500 with eight hard-wired TCP/IP sockets
  • Simple 4-wire SPI interface
  • 32kB on-chip buffers
  • Through hole or SMD PCB flush mounting (0.8mm substrate)
  • 1″ x 0.9″ x 0.67″ deep
  • 10g (13g with +P8)

IoT5500

Source : https://docs.google.com/document/d/1Io0_RNINWn92OfVs32uL4ywK0gnyaRyuxdijwtPrSvI/pub