Internet of Things – OpenHAB1 – MySQL (persistence)
1) Installeer de OpenHAB MySQL persistence addon met apt-get:
sudo apt-get install -y openhab-addon-persistence-mysql
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: openhab-addon-persistence-mysql 0 upgraded, 1 newly installed, 0 to remove and 127 not upgraded. Need to get 832 kB of archives. After this operation, 833 kB of additional disk space will be used. Get:1 http://dl.bintray.com/openhab/apt-repo stable/main armhf openhab-addon-persistence-mysql all 1.8.3 [832 kB] Fetched 832 kB in 0s (4,006 kB/s) Selecting previously unselected package openhab-addon-persistence-mysql. (Reading database ... 124416 files and directories currently installed.) Preparing to unpack .../openhab-addon-persistence-mysql_1.8.3_all.deb ... Unpacking openhab-addon-persistence-mysql (1.8.3) ... Setting up openhab-addon-persistence-mysql (1.8.3) ... |
2) Stel het MySQL wachtwoord in:
sudo mysqladmin -u root password
3) Maak een database aan genaamd “openhab”:
sudo echo "create database openhab" | mysql -u root -p
Controleer of de database is aangemaakt met: sudo mysql
MySQL commando: show databases;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 16 Server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | openhab | | performance_schema | +--------------------+ 4 rows in set (0.00 sec) |
4) Maak een mysql persist bestand aan om events/triggers in te stellen:
sudo nano /usr/share/openhab/configurations/persistence/mysql.persist
1 2 3 4 5 6 7 |
Strategies { default = everyChange } Items { * : strategy = default, restoreOnStartup } |
5) Bewerk het OpenHAB configuratiebestand om de MySQL gegevens zoals url, naam, wachtwoord in te vullen:
sudo nano /etc/openhab/configurations/openhab.cfg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
############################ mySQL Persistence Service ################################## # the database url like 'jdbc:mysql://<host>:<port>/<database>' mysql:url=jdbc:mysql://127.0.0.1/openhab # the database user mysql:user=<your user here> # the database password mysql:password=<your password here> # the reconnection counter #mysql:reconnectCnt= # the connection timeout (in seconds) #mysql:waitTimeout= # optional tweaking of mysql datatypes # example as described in https://github.com/openhab/openhab/issues/710 # mysql:sqltype.string=VARCHAR(20000) # Use MySQL Server time to store item values (=false) or use openHAB Server time (=true). # For new installations, its recommend to set "mysql:localtime=true". # (available since 1.9, optional, defaults to false) #mysql:localtime=true |