Linux

来自Domoticz

此页面描述了如何在Debian-based操作系统中编译/构建最新beta版Domoticz。
此过程已经成功测试于Ubuntu Server 14.04 LTS 以及 16.04 LTS

安装依赖库

注意: 如果你使用Ubuntu 16.04或更新版本,推荐使用apt代替apt-get

首先,升级你的系统:

sudo apt-get update
sudo apt-get upgrade

如果你最近没有升级过,那么上面的命令可能会需要很长时间。

然后为编译Domoticz安装开发工具和依赖库:

sudo apt-get install build-essential nano cmake git libboost-dev libboost-thread-dev libboost-system-dev
sudo apt-get install libsqlite3-dev curl libcurl4-openssl-dev libssl-dev libusb-dev zlib1g-dev python3-dev


修复在Ubuntu 12.04 LTS及更早版本中可能出现的依赖性问题

以上安装在Ubuntu (12.04 LTS)及更早版本中可能会出现以下编译失败错误: error: ‘class boost::asio::io_service’ has no member named ‘stopped’ 这种情况,你需要手动用更新版本的boost库替换apt-get命令安装的版本。请参考树莓派说明页 点这里

CMake版本

要使用Python插件,cmake版本需要3.0.1或更新才能找到Python 3。查看系统中cmake的版本使用以下命令:cmake --version。如果版本过旧,cmake可能无法找到python 3.

下载及构建3.2.2版cmake使用以下命令:

sudo apt-get install build-essential
wget http://www.cmake.org/files/v3.2/cmake-3.2.2.tar.gz
tar xf cmake-3.2.2.tar.gz
cd cmake-3.2.2
./configure
make
sudo make install

编译/构建Domoticz库

注意: 如果你需要支持Z-Wave或Tellstick,你需要在编译Domoticz之前先增加对Z-Wave或Tellstick的支持。如何增加Z-WaveTellstick支持请阅读以下部分。


在低配电脑上进行编译可能需要10-15分钟。如果你的电脑拥有多核CPU,可以通过给'make'命令增加'-j'标识来使用更多核心,这样会快很多。四核CPU可以使用make -j4代替make

通过以下命令获取最新Domoticz源代码并进行编译/构建:

cd ~
git clone https://github.com/domoticz/domoticz.git domoticz
cd domoticz
cmake -DCMAKE_BUILD_TYPE=Release .
make

注意: 如果你有任何设备连接到USB口或串口,你需要在启动Domoticz之前先授权ttyUSB端口。根据这些说明来操作。

Some older Boost libraries on certain hardware can give you If linkage error. In that case you could try adding the flag -DCMAKE_EXE_LINKER_FLAGS=-lboost_atomic to the cmake command.

To start Domoticz type:

./domoticz

When you open your browser at http://ip_of_your_machine:8080, you should be presented with the Domoticz web interface.

For additional parameters of the Domoticz daemon, run:

./domoticz -h

To start Domoticz automatically when the system boots follow these instructions.

Allow non-root user to access ttyUSB* ports

If you don't plan on interfacing Domoticz with USB and/or serial devices, you can skip this step.

By default (at least on Ubuntu) a non-root user has no permission to access the ttyUSB* ports. So if you have Domoticz running under a separate user (which is always a good idea to make the system more secure), Domoticz isn't allowed access to your RFXCOM for example. Here are two methods of doing it. For most people the first one by adding the user to the dialout goup is enough and by far the easiest.

Adding the user to the dialout group

This can be done by running the command below:

sudo usermod -a -G dialout YOURUSERNAME

(Where you replace YOURUSERNAME with the user that runs Domoticz.)

Setting up an udev rule

Alternatively you can setup (as root) a udev rule that matches the RFXCOM device. To find which attributes match your device use the command:

udevadm info -a -p $(udevadm info -q path /dev/ttyUSB1) | less

Where /dev/ttyUSB1 is the device. If you wish to run Domoticz under the YOURUSERNAME credentials, who is member of the YOURGROUPNAME group and your device has serial YOURSERIAL a suitable udev rule would be:

SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{serial}=="YOURSERIAL", ATTRS{idProduct}=="6001", SYMLINK+="ttyUSB21", OWNER="YOURUSERNAME", GROUP="YOURGROUPNAME"

Save it to a file under /etc/udev/rules.d/ with the .rules extention and run:

service udev reload

Unplug and replug the device and execute:

ls -l /dev/ttyUSB*

You should see something like

crw-rw---- 1 domoticz domoticz 188, 1 Nov 10 15:27 /dev/ttyUSB1
lrwxrwxrwx 1 root     root          7 Nov 10 15:27 /dev/ttyUSB21 -> ttyUSB1

The added SYMLINK+= creates an additional link to the device node. This is a static name that is useful when you have multiple usb-serial devices that go into your box. Use the static link in Domoticz. For more information on udev rules have a look here: http://www.reactivated.net/writing_udev_rules.html

Starting Domoticz automatically when the system boots

Init.d Method

To let Domoticz start automatically when the system boots (which is probably the case, as most people run it on a headless server), run the commands below, (You want to end up in /home/YOURUSERNAME/domoticz/)

cd domoticz
sudo cp domoticz.sh /etc/init.d
sudo chmod +x /etc/init.d/domoticz.sh
sudo update-rc.d domoticz.sh defaults

Edit the startup script.

sudo nano /etc/init.d/domoticz.sh

The lines you usually need to change are USERNAME, DAEMON and DAEMON_ARGS

USERNAME=yourusername
DAEMON=/home/$USERNAME/domoticz/$NAME
DAEMON_ARGS="-daemon -www 8080"
  • Change the USERNAME variable to the user you want domoticz to be run as. It's recommended to run domoticz as its own user and not as root, due to security reasons.
  • If you installed Domoticz in the USERNAME home directory /home/yourusername/domoticz you don't need to change the DAEMON variable. If you installed it in an alternate location for example /usr/local/domoticz/ you should change DAEMON to /usr/local/domoticz/$NAME
  • If you want to use another web interface port change the '8080' in: DAEMON_ARGS="-daemon www 8080" to your own port.

Note: To be able to use ports below 1024, for example the standard port for webbrowsing, 80, you need to run domoticz as the root user.

If you want to see more arguments for DAEMON_ARGS run this in the domoticz directory. This is usually not needed.

./domoticz -h

Domoticz will now start automatically when you reboot your machine.

Manually controlling the Domoticz service

This only works if you followed the above steps.

You can now start/stop/restart and check the status of domoticz with:

sudo /etc/init.d/domoticz.sh start
sudo /etc/init.d/domoticz.sh stop
sudo /etc/init.d/domoticz.sh restart
sudo /etc/init.d/domoticz.sh status

If your system supports it you can instead use:

sudo service domoticz.sh start
sudo service domoticz.sh stop
sudo service domoticz.sh restart
sudo service domoticz.sh status

Systemd Alternative

Open the systemd configuration file :

vi /etc/systemd/system/domoticz.service
[Unit]
       Description=domoticz_service
[Service]
       User=domoticz
       Group=domoticz
       ExecStart=/home/domoticz/domoticz/domoticz -www 80 -sslwww 443
       WorkingDirectory=/home/domoticz
       #give the right to open priviliged ports
       ExecStartPre=setcap 'cap_net_bind_service=+ep' /home/domoticz/domoticz/domoticz
       Restart=on-failure
       RestartSec=1m
       #StandardOutput=null
[Install]
       WantedBy=multi-user.target

Enable the service

systemctl daemon-reload
systemctl enable domoticz.service

Start the service

systemctl start domoticz.service

Updating Domoticz

Once in a while, a new Domoticz version is released, and of course you want to update. You can do this with the commands below:

  1. First stop Domoticz with sudo /etc/init.d/domoticz.sh stop or sudo service domoticz.sh stop
  2. Navigate to the directory where Domoticz is installed: cd domoticz (You want to end up in /home/YOURUSERNAME/domoticz/)
  3. Pull the latest Domoticz code from Github: git pull
  4. Compile/build the files that have been downloaded: make && sudo /etc/init.d/domoticz.sh start (Compiling will take a while, but the command will automatically start Domoticz again when compiling is done, so you can go to sleep or do something else in the meantime.)

If all went correctly, Domoticz should be updated to the latest version and should be running again automatically.

Attention: when you use Monit, be sure to disable it before doing the update process, otherwise after you have stopped Domoticz by hand yourself, it will get restarted automatically by Monit within a few minutes (because that is what is Monit should do normally).
Stopping Monit can be done by sudo /etc/init.d/monit stop and after updating it can be started again with sudo /etc/init.d/monit start.
You could also use this command: make && sudo /etc/init.d/domoticz.sh start && sudo /etc/init.d/monit start to update, start Domoticz & start Monit when updating is done.

Script to update almost automatically

For updating almost automatically, i made this script

#! /bin/sh
cd /home/YOURUSERNAME/domoticz/ \
&& sudo /etc/init.d/monit stop \
&& sudo /etc/init.d/domoticz.sh stop \
&& git pull \
&& make \
&& sudo /etc/init.d/domoticz.sh start\
&& sudo /etc/init.d/monit start

Save it as domoupdater.sh, give it executable rights (chmod +x domoupdater.sh) and call it by sh /home/YOURUSERNAME/domoupdater.sh
It will change the current path to the Domoticz folder, stop Monit, stop Domoticz, pull binaries, compile, start Domoticz, start Monit again.
Very handy to run & go do something else.

In theory it can work automatically (weekly cronjob for example), however when running as a non-root user (which is the case in my situation), it will ask for the password of the user. But after you have provided the password (almost immediately after the script has started), it will continue without needing any further user input.
In theory it is possible to let it run fully automated, but i myself prefer a bit of feedback (watching afterwards if all went well). If you want to work around this sudo password asking, look here.

Add support for Z-Wave

Follow the steps below if you want to add support for Z-Wave devices in Domoticz. This needs to be done before compiling domoticz.

Install libudev-dev

To install the specific dependencies issue the command:

   sudo apt-get install libudev-dev

Compile OpenZWave

The OpenZWave source directory needs to be in the same directory as the domoticz directory

   cd ~
   git clone https://github.com/OpenZWave/open-zwave.git
   ln -s open-zwave open-zwave-read-only
   cd open-zwave
   make
   cd ..

The directory should look something like this

   drwxrwxr-x 27 pi pi 4096 aug 12 19:59 domoticz
   drwxrwxr-x 11 pi pi 4096 aug 14 16:30 open-zwave
   lrwxrwxrwx  1 pi pi   10 aug 14 16:32 open-zwave-read-only -> open-zwave

Updating OpenZWave

To update the OpenZWave-part, run these commands:

   cd open-zwave
   git pull
   make clean
   make
   cd ..

Problems when compiling Domoticz with OpenZWave

For people having trouble compiling with OpenZWave try with a fresh source.

   cmake -USE_STATIC_OPENZWAVE -DCMAKE_BUILD_TYPE=Release CMakeLists.txt

instead of

   cmake -DCMAKE_BUILD_TYPE=Release .

when compiling the main Domoticz binary. For more information read this thread on the forum: Link

Problems locating Python

Some users, particularly those on old operating systems see the following message when starting Domoticz:

 2016-12-20 09:44:32.251 Failed dynamic library load, install the latest libpython3.x library that is available for your platform. 

this shows that, even though python3 may be on the system, the python library can not be located. This error will not stop Domoticz from starting but will mean that hardware supported by the Python Plugin Framework will not be available. To fix this, install the newest version of libpython3 for the platform. For example, RaspberryPi Jessie has python 3.4 on it but the library is not included. Executing:

 sudo apt-get install libpython3.4

should solve the issue. Note that python 3.4 is the earliest support version of python, where available later versions should always be used.
If the python 3 is installed but Make is not able to progress, try to add

 set(Python_ADDITIONAL_VERSIONS 3.4)

just before find_package(PythonLibs 3.4) in the CMakeLists.txt

If your platform does not have a compatible version, for example RaspberryPi Wheezy, then one can be built from source using:

 wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
 tar -xvf Python-3.5.2.tar.xz
 cd Python-3.5.2
 ./configure --enable-shared
 make
 sudo make install

Don't miss the enabled-shared flag otherwise libpython will not be built.

After building Python 3.5.x change CMakeLists.txt

 option(USE_PYTHON_PLUGINS "Use Python Plugins" YES)
 IF(USE_PYTHON_PLUGINS)
   set(Python_ADDITIONAL_VERSIONS 3.5)      <---- add this line
   find_package(PythonLibs 3.5)   <---- change version into 3.5
   IF(PYTHONLIBS_FOUND)

Add support for Tellstick

If you need support for Tellstick or Tellstic Duo you need to install telldus-core before compiling Domoticz. On Debian-based systems (For example Ubuntu and Raspbian) telldus-core can be installed by doing the following:

echo "deb http://download.telldus.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/telldus.list
wget -q http://download.telldus.se/debian/telldus-public.key -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install libtelldus-core-dev