UniFi Controller on a Pi or DietPi

Having just invested in a UniFi AP UAP-AC-Lite (it is absolutely fantastic), and refusing to spend £70 on the USB UniFi controller or wanting to use the cloud system, I needed to get the UniFi controller installed.  I didn’t expect any issues.  Well there were.

I first ran up a new DietPi VM on my micro HP server running an old 5.5 version of Esxi – Ain’t broke don’t fix. I now have a policy of not combining systems but running individual VMs.  I was burned recently when an installation of HomeAssistant went Pete Tong and I had to rebuild from scratch.  That also took out Node-Red and Mosquitto so they all (broardly) have their own VMs.

I tried a number of different ways of installing the controller via apt.  The problem I kept hitting was Java.

[Edit 9th March 19] I have discovered a much better way via these scripts.

To cut a long and tedious story short, I stumbled upon a community post that linked to a docker version of the Controller (project links https://github.com/ryansch/docker-unifi-rpi and https://hub.docker.com/r/ryansch/unifi-rpi/).

To install this on DietPi (after my usual setup) I simply installed docker and then from apt docker-compose, before building the container.

And that was it.

The controller appears on port 8443, you need to use an https address and there is the usual stupidity around browsers complaining about no SSL cert for non-routable addresses but it all works fine.

Epilogue: I subsequently realised that there is a second method to install the docker that might actually be better as it has instructions on how to upgrade. I do not understand the difference in the methods and I will leave it until I need to upgrade.

Facebooktwitterby feather
Posted in DietPi, Hardware, Network, Technical - General | Tagged , , | Leave a comment

Pi-Hole and Disabling dnsmaq

Pi-Hole no longer uses the dnsmasq DNS proxy directly. However, existing installations will still have it installed and the service will still attempt to run and fail (as it should).

I was keen to get rid of it as I’m not a fan of unused services especially ones that should always fail. It was not as straightforward as I’d hoped as it is an init.d service. After a discussion on the forum, and some trial and error I think this is what I did. Unfortunately, I could not go back to where I was before I started so I cannot be 100% confident it is right (or the order).

So the issue was that, as this is a service that is started via update-rc.d a normal ‘disable’ does not work as it leaves the various run level files hanging around as seen by

To remove those you need to execute

Secondly, disabling a service simply stops it from running at boot, but does leave open the possibility of it being initiated by another service. To stop the possibility of that happening, a

is required.

This then removes it from the output of a systemctl status and avoids confusion.

There is a suggestion that dnsmasq could be uninstalled. I decided not to as it felt a little risky (I may take a VM snapshot and try).

To ‘uninstall’ a package, you need to do one of 4 things with apt.

remove– just removes the package from the os (i.e. uninstalls it) and not from the disk (the cached package).

purge – removes the installed package and associated files like personal settings, configuration files etc

auto-remove – removes any packages that are no longer required as a result of removing packages that had previously caused other dependencies to be installed. If used with purge will remove associated files as well.

clean – actually removes all of the above from disk, think emptying a recycle bin in windows.

Facebooktwitterby feather
Posted in DietPi, Linux, Pi-Hole, Technical - General | Leave a comment

Systemd Timer and monit

Why is it that, so often, a key bit of information is assumed by documentation writers?

I’ve had an issue for a while where monit will fail to start properly on boot.  The issue is that with DietPi, it seems that the system boots too quickly and monit trys to create a network interface before the network is ready.  Calling a systemctl restart monit solves the problem but that is a pain to remember to do after every boot.

I started looking at systemd solutions.  There is an obvious one; use a timer file.

In theory you create a file with the extension .timer and that then triggers the related service to start.  Good in theory but I could not get it to work; the monit service just started straight off.

The clue is a small line here – “The .service does not require an [Install] section as it is the timer units that are enabled. ”

Off goes the light.

So the monit.service file looks like this (note no install section)

and the monit.timer file looks like this

both reside in /lib/systemd/system/

To enable them you simply enable the timer systemctl enable monit.timer

One other thing I did and I’m not sure if it makes a difference, I removed the file /etc/init.d/monit

As a recap, a vanilla install of monit is simply apt-get install monit.

To access the status, you need to setup the internal http server. Add a file /etc/monit/conf-enabled/monitconfig with the contents;

There are other examples in the main config file  /etc/monit/monitrc.  This setup only allows access from my local subnet and as I used a fixed IP, I specify that IP.

I then access this from Node-Red (fill in your IP address) and output onto an MQTT broker as I explained in the past https://tech.borpin.co.uk/2017/03/21/node-red-and-xml-to-json/

Facebooktwitterby feather
Posted in Linux, Technical - General | Leave a comment

Contributing to Open Source Projects on GitHub

If it has crossed your mind to contribute to an Open Source project, but GitHub just seems too daunting, then I’d suggest reading this tutorial.

The bit that got me was how to actually contribute and this section explains it perfectly (I think). Before, there were too many origins the odd upstream and far too much pushing and pulling!

The key steps (which I have got wrong on numerous occasions before reading this tutorial) are:

  • Create a Fork of the repository you wish to contribute to (the upstream repository), to your GitHub account (the origin repository)
  • Clone the origin repository to your working machine (the local repository)
  • Add the upstream as a remote
  • Create a local branch off the master branch
  • add in your features and test them
  • commit to your local repository
  • push those changes to the origin (your GitHub repository)
  • Create a Pull Request to include it in the main project (i.e. ask the maintainer to pull in your changes).

This tutorial does refer to BitBucket but the principles are exactly the same and is a reference I keep on coming back to.

Facebooktwitterby feather
Posted in Coding and Programming, Technical - General | Leave a comment

Using nmcli to set a static IPV4 address in Hass.io

This method of setting a static IP for Hassio has been tested with a Hass.io vmdk image on an Esxi server. Log into the HASSOS base system via a console – note this is not the same as an SSH login via the add-on.

Welcome to HassOS
Hassio login:

Login as root (no password needed)

At the hassio > prompt, type login (as instructed).

From here you will use the nmcli configuration tool.

# nmcli connection show will list the “HassOS default” connection in use.

# nmcli con edit “HassOS default” will put you in a position to edit the connection.

nmcli> print ipv4 will show you the ipv4 properties of this connection.

To add your static IP address (select ‘yes’ for manual method);

nmcli> set ipv4.addresses 192.168.100.10/24
Do you also want to set 'ipv4.method' to 'manual'? [yes]:
nmcli> save
nmcli> exit

In addition I have found it is wise to set the dns server and the local gateway. For most home routers these will be the same address. If you are using Pi-Hole you can set the dns to that.

nmcli> set ipv4.dns 192.168.100.1
nmcli> set ipv4.gateway 192.168.100.1
nmcli> save
nmcli> exit

If you now view the default connection cat /etc/NetworkManager/system_connections/default you should see the method is manual and the address is set.

Doing a nmcli con reload does not always work so restart the VM.

Facebooktwitterby feather
Posted in Hass.io, HASSOS | 2 Comments

Emoncms on DietPi

Introduction

WARNING

The Install of EmonCMS has moved on since I wrote this and this guide is now depreciated

I am a huge fan of DietPi – lightweight and fast, runs an a large number of SBCs. The aim here was to build a local EmonCMS server as simply as possible. Doing it even from a Rasbian Stretch minimal image can be a bind – DietPi makes some of the tricky bits as easy as selecting from a menu. Not everything can be done that way and some command line effort is required. I started with a fresh V6.16 DietPi install. Well actually it is a base VM image I have that I simply updated. Yes, DietPi runs very happily on a VM, is much quicker than on a Pi and no issues with SD Cards corrupting. In addition, you can take snapshots so less risk of ruining an installation!

The other aspect is that these instructions will install a LLAP stack of Lightppd, PHP7 and MariaDB. Personally I think Apache is rather bloated.

Setting up

DietPi-Config

The initial setting up is best done via the DietPi interface. Simply type dietpi-config to enter the menu system.

  1. DietPi-config – Advance options – Time sync mode – time sync daemon + drift (more reliable time)
  2. DietPi-config – Security options – change root password and hostname (optional)
  3. DietPi-config – Network Options: Adapters  – fixed IP and turn off IPV6 (optional)

DietPi-Software

DietPi has a menu system for installing a number of different software packages. You can either do these installs via the menu system or shortcut it by using the command line syntax dietpi-software install [ID] (except for the SSH change).

  1. Avahi daemon [152] – gives you a hostname on your network.
  2. Install GIT [17]
  3. Install LLAP [82] – It will suggest you do not need this but go ahead anyway.
  4. DietPi-Software – SSH Server – OpenSSH (Optional – allows WinSCP to transfer files – replaces defualt dropbear)
  5. Install redis-server [91] – Only required if you are going to use Redis, but it is suggested you do!
  6. Install Mosquitto [123] – Only required if you intend to run an MQTT broker on this machine (I run the broker on my HASSIO instance). Not needed to publish and subscribe to topics.

Command line installs

Next you need to install a few bits directly. NOTE in DietPi you do most things as root (you can setup other users, I never bother) so sudo is not required.

  1. apt-get -y install php7.0-dev – This gives you the phpenmod and phpdismod commands
  2. apt-get -y install build-essential – Is used by PECL to build compile the redis and mqtt php modules.
  3. apt-get -y install php-pear
  4. apt-get -y install mosquitto-clients – Optional, required if you want to debug MQTT.
  5. pecl channel-update pecl.php.net
  6. pecl install redis-3.1.6 – This is the PHP extension for REDIS – the version is important.
  7. printf "extension=redis.so" | sudo tee /etc/php/7.0/mods-available/redis.ini 1>&2
  8. phpenmod redis – Enable the PHP Redis extension.

MQTT [edit]

I suddenly realised that I had not included how to install MQTT. The simplest way is to follow this guide (remembering you do not need sudo).

Configure Lighttpd

nano /etc/lighttpd/lighttpd.conf – Edit the Lighttpd configuration:

Add in mod_rewrite

And add these lines at the end…

Either restart Lighttpd or reboot the server (I like to do the latter) systemctl restart lighttpd

EmonCMS

I was going to refer to the main documentation for this, but it is somewhat out of date and inconsistent so…

The Base System

  1. cd /var/www
  2. git clone -b master https://github.com/emoncms/emoncms.git You may want to use the stable branch instead.

Setup The Database

  1. mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); DELETE FROM mysql.user WHERE User=''; DROP DATABASE IF EXISTS test; DELETE FROM mysql.db WHERE Db='test' OR Db='test_%'; FLUSH PRIVILEGES;"
  2. sudo mysql -e "CREATE DATABASE emoncms DEFAULT CHARACTER SET utf8;"
  3. mysql -e "CREATE USER 'emoncms'@'localhost' IDENTIFIED BY 'emonadmin'; GRANT ALL ON emoncms.* TO 'emoncms'@'localhost'; FLUSH PRIVILEGES;"

Create Data Directories

  1. mkdir /var/lib/{phpfiwa,phpfina,phptimeseries}
  2. chown www-data:root /var/lib/{phpfiwa,phpfina,phptimeseries}
  3. chmod 755 /var/lib/{phpfiwa,phpfina,phptimeseries}

Setup Log file

  1. touch /var/log/emoncms.log
  2. chmod 666 /var/log/emoncms.log
  3. chown root:www-data /var/log/emoncms.log

Edit EmonCMS Settings

  1. cd /var/www/emoncms && cp default.settings.php settings.php
  2. nano /var/www/emoncms/settings.php

First run

Open a browser window to [YourIpAddress]/emoncms. At the user prompt click on Register. Register a user then log in. First stop is the administration page and check database. Everything should now be ready to go!

You may wish to add in some additional Modules.

You may also wish to enable MQTT for subscribing and publishing.

Facebooktwitterby feather
Posted in DietPi, OpenEnergyMonitor, Technical - General | 2 Comments

Else is never necessary – Really?

I had an interesting experience with Codacy today.  I got this error.

When doing my IT Degree (many moons ago) I was taught 2 things (amongst others you understand):

  1. An If statement always has an else. You should always handle a possible situation even if it should never happen.
  2. There should only ever be one exit point from a function, loop etc.

Perhaps these mantras stemmed from a safety critical standpoint (I was using Ada).

However, it seems the ‘modern way’ doesn’t agree. Well tough, I still think I am right and any other way is just building in problems.

Facebooktwitterby feather
Posted in Coding and Programming | Leave a comment

Keeping time on a Pi

Again, this blog fall into the category of a ‘I need to remember how I did this’ post.  I actually started writing this months ago but never finished it.  Good job as some of what I originally said was wrong and we have moved on from Jessie to Stretch.

This started when I accidentally discovered that the date/time on one of my Pi’s was significantly out.  I won’t bore you with the things that I tried and failed, rather just tell you how to fix it.

You can check the date&time your own system by simply typing date and seeing if it is right or not.

Finding out how to get the right time set is remarkably difficult.  In the end I discovered that you can simply use this command (reference);

sudo sntp -s time.google.com

NTP is the protocol that synchronises time across the internet.  There are a number of free to use servers that you can query to get the current date & time.

One important fact is that if your date & time are significantly out, you cannot use ntp to set the time correctly.  Set it manually so about the right time then sync.

On more recent versions/distributions of Linux,  timedatectl  may be used to query and change the system clock and its settings.  Note this is not a daemon in it’s own right.  On Linux there are 2 daemons you can use, ntpd  or systemd-timesyncd . However you must not have both enabled at the same time. ntpd is the older daemon. systemd-timesyncd is the newer one and is a builtin service.

Now have a look at the daemon that controls synchronising your system with an ntp server.

The best explanation of this daemon I found was here, with another guide here.

As you can see from the output above, NTP is enabled and synchronised and my timezone is set correctly, it is likely that in the response you see, they are not.  Firstly, if your timezone is not right I’d suggest using sudo raspi-config to set it correctly.

In order to use ntp to keep your clock right, you first need to point the daemon to a time server.  The recommendation is to use a suitable one out of the ntp pool project; http://www.pool.ntp.org/en/use.html . To do so you need to edit the file  sudo nano /etc/systemd/timesyncd.conf  so that your Time section looks something like this;

Interestingly, the guide above suggested the line should start ‘NTP’ but as all I did to the standard line was uncomment it and change debian to uk.

To now switch on the synchronising use the command sudo timedatectl set-ntp true

One final thing, if you are using UFW you may find you need to open the port with  sudo ufw allow 123/udp

You may also need to restart the services  sudo systemctl restart systemd-timesyncd.service

Your system should now keep time 🙂

HTH

Facebooktwitterby feather
Posted in Technical - General | 1 Comment

Old DietPi Orange Pi Images

If, like me, you are a fan of DietPi, you may well have been irritated by recent events.  The decision to move to a completely new image that could not be upgraded to, was understandable, if unfortunate.  These things happen to any OS with Windows being the obvious comparison.

Unfortunately this upgrade coincided with a spat with armbian which seemed to revolve around a school yard ‘my image is better than yours’ Twitter argument.  The end result is that DietPi have dropped links with Armbian and so there are no new images for the OrangePi family which Fordee readily admits were some of the most popular downloads.

Fortunately, I had (unusually) quickly upgraded to the last Jessie version (v158) on my OrangePi Zero+ before it all went pete tong.  Although no new images are being made available, it is not as if there is no further support in that you can still do the apt-get update/upgrade so it is only the added support DietPi brought that has been lost.  DietPi did host some specific packages in their repositories so that will become an issue as time goes on.

DietPi are also being robust and deleting links to old images out there that are posted on the forum.  One user has kindly provided a download of the images, the link for which I got before it was removed.  If you want the last Jessie OrangePi image from DietPi you can get them here.

HTH

Facebooktwitterby feather
Posted in DietPi, OrangePi | 2 Comments

Adding a DietPi VM to an EXSi Host

This blog very much falls into the ‘how in the hell did I do that’ category.

A bit of background.  I have had an HP MicroServer for a number of years just sitting there not doing a lot except running an XP VM with a mailserver on it called Mailtraq.  This was a hangover from when mail servers were pretty poor and GoogleMail was a twinkle in someone’s eye.  It also helped with dial on demand (who remembers that!), NNTP and Demon Internet.  Suffice to say life has moved on so the XP VM needed to be binned and so, sadly, did the Mailtraq installation.

What then to do with the MicroServer.  It runs a free version of VMWare’s EXSi server (5.x) which I happily connect to via the old vSphere client.  Whilst this is a little old hat, I know it and can find my way around it so ‘it ain’t broke, don’t fix’ is the mantra.  I then realised that DietPi have some VM images so I thought I’d give them a go.  Whilst running things on RaspberyPis seems like a good idea, for somethings it really isn’t.  The network speed is poor (shared USB Bus), SD Card wear and a lack of grunt.  The DietPi images are built for the VMware Workstation but I was able to convert them using the VMware vCenter standalone converter with little problem.  The speed of the application was fast compared to a B+ Pi so all was well and good.

DietPi have just released a new platform.  This has caused some angst as the older platform is now simply not supported.  However, it is a step change for them, so I picked up the new V6 image and tried to convert it.  No joy. I kept getting an error “Unable to Obtain Hardware information for the selected machine”.  At first I thought it was an error with the new image file but on trying an image I had previously converted successfully, it also failed.

Following some searching, I am sure that the problem is with security on Windows 10.  I do not know if it is MS or BitDefender.  I had a brief foray with BitDefender but it interfered with Bash on Windows (no network) and they were unwilling to investigate without me doing all the work so it go canned. Getting rid of all the BitDefender garbage seems a bit tricky!  I did try opening the converter as Administrator, disabling UAC and disabling MS Defender all to no avail.

So plan B was to upload the VMDK and VMX files.  I was sure this had failed before but I had a go.  First boot failed on OS type.  This was fixed by selecting ‘otherLinux-64’.

Next boot did not like number of CPUs.  Changed that in setting.

Next boot did not like the disk type.  Error message “Failed to open disk scsi0:0: Unsupported or invalid disk type 7”.  The issue here is that the disk type is for VMware Workstation.  However, fixing this was relatively simple.  I had SSH enabled on the EXSi host so SSH in and use  vmkfstools -i <sourceVM> <targetVM> (KB item) to clone the disk to the right format.

The VM now booted and DietPi started.  One final issue was the network did not want to configure.  I fixed this by deleting the network adapter and installing a new one.

Having now got a DietPi VM that has run once, I will clone this and create the various VMs I need. http://www.mustbegeek.com/create-copy-of-existing-virtual-machine-in-esxi-server/

Facebooktwitterby feather
Posted in DietPi, Linux | Leave a comment