Controlling a PC via Apple HomeKit: part 2

On the first part of the tutorial, I showed how to install the infrastructure software to allow Apple devices to control a PC via Homekit. Now I am going to show how to install the services that interface with the infrastructure to execute the actions triggered by the Apple devices.

Installing the power on service on the Raspberry PI

The first service to install is the service responsible for powering on the PC using WakeOnLan. This is done using this small project I wrote: Smart PC Control.

This software is not packaged for Raspbian and it needs to be compiled from source along with 2 of its dependencies. Luckily this is a simple process.

First, let’s start by installing the build dependencies:

sudo apt-get install  build-essential gcc make cmake libjson-c-dev uuid-dev liburiparser-dev

With the build dependencies installed, we can proceed to install the first dependency: GRU.

git clone https://github.com/orpiske/gru.git
cd gru
mkdir build && cd build
cmake ..
make
sudo make install

Now we need to install the Eclipse Paho C MQTT client:

git clone https://github.com/eclipse/paho.mqtt.c.git -b v1.3.1
cd paho.mqtt.c
mkdir build && cd build
cmake .. && make
sudo make install

And, finally, the Smart PC Control project:

git clone https://github.com/orpiske/smart-pc-control.git
mkdir build && cd build
cmake ..
make
sudo make install

With this project installed we can proceed to its configuration.

Configuring the Power On Service on the Raspberry Pi

The Smart PC Control project install SystemD unit files and its respective configuration.

First, let’s edit the service configuration

cp /etc/sysconfig/smart-pc-control-power.set-me-up /etc/sysconfig/smart-pc-control-power
sudo nano -w /etc/sysconfig/smart-pc-control-power

The configuration should look similar to this:

# The URL of the MQTT broker
MQTT_BROKER_URL=tcp://localhost:1883

# Replace changeme with the hostname where the system is running
CLIENT_ID="power-control-changeme"

# Uncomment for clients that don't store any state
DAEMON_OPTIONS="--stateless"

# Ensure to export library dir if not using a standard location
# LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

Now, let’s edit the System D unit file: /usr/lib/systemd/system/smart-pc-control-power@.service.

The content should look like this:

[Unit]
Description=Smart PC Control - Power Daemon
After=syslog.target network.target

[Service]
User=%i
Type=forking
EnvironmentFile=-//etc/sysconfig/smart-pc-control-power
ExecStart=/usr/local/bin/smart-pc-control-power -d -b $MQTT_BROKER_URL -i $CLIENT_ID $DAEMON_OPTIONS
PrivateTmp=false
Restart=on-failure

[Install]
WantedBy=multi-user.target

Enable the service

To enable the service for the pi user, run:

sudo systemctl enable --now smart-pc-control-power@pi.service

Install the Power Off Service on the PC

This part assumes a PC running Fedora. For other distributions or OSes, you have to build the tool manually and install it.

The software is fully package for Fedora and available on the awesome Fedora COPR. To do so:

sudo dnf copr enable orpiske/orp-tools-testing
sudo dnf install -y smart-pc-control

With the services installed, we can proceed to configuring its daemon

sudo nano -w /etc/sysconfig/smart-pc-control-power

The contents of the file should look like this:

# The URL of the MQTT broker
MQTT_BROKER_URL=tcp://mimas:1883

# Replace changeme with the hostname where the system is running
CLIENT_ID="power-control-changeme"

# Uncomment for clients that don't store any state
# DAEMON_OPTIONS="--stateless"

# Ensure to export library dir if not using a standard location
# LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64

Note that the DAEMON_OPTIONS is commented. The Power Off doesn’t need it.

To enable the service, run:

sudo systemctl enable --now smart-pc-control-power@USER.service

Note: replace USER with your actual user

This should be all that is required to install and run the power daemons.

Go to part 3.

Minicloud: the Free OpenPower cloud

I recently got access to the Minicloud, a Free OpenPower Cloud hosted by Unicamp, one of the most prominent universities in Brazil. This cloud is a good way to ensure that your application provides good support for the Power architecture.

Having access to this cloud, I can help ensure that some of the projects I am interested about can be ran and supported on this architecture. Additionally, it offers me a Power environment to test the messaging-related packages I maintain on Fedora and CentOS – entirely on my free time.

To start with this cloud, I decided to go big and deploy Maestro there. Having only 4Gb, it means that I need to adjust very well the resources of my VMs so that I can maximize the usability of the cloud environment. I will write some posts about this.

The other project that I am interested in playing with in the Minicloud is Paho C, the MQTT client from Eclipse Foundation. As the Fedora maintainer for the package, having access to this environment means that I have a personal environment where I can ensure the quality of the packages.

Garmin Connect IQ on Fedora

Garmin Connect IQ is the SDK used to build applications and widgets for Garmin Devices such as the awesome Garmin Vivoactive 3.

Unfortunately, the package does not work on Fedora out of the box. In order to make it run, you have to take the following steps:

1. Install Gnucash (it is required because there’s no package for a compatible webkitgtk):

2. Export the path to the webkit library required (you might want to leave this on your shell profile or similar):

3. Install libjpeg8.

3.1 (Update) Enable this COPR and install libjpeg8 from there.

3.1 If you are using Fedora 27, you can install this RPM

3.2 If you are using Fedora 26, luck is on your side and you can just use the package from this COPR.

My personal tips for a better Fedora experience

Fedora is a rock-solid stable, with a good selection of official and non-official packages. Just like many other distros, it still gives you the flexibility to adjust the system to your workflow. Here’s my basic steps to adjust it to my needs:

  1. Install Cinnamon
  2. Install Lightdm:
  3. Replace GDM with LightDM:
  4. Remove evolution and all evolution stuff:
  5. If you are Brazilian, using a US International keyboard, install Roberto’s cedilla patch to fix the annoying default behavior for cedilla.
  6. Install zsh and oh-my-zsh.

Google Sanitizers and Fedora 25

Here’s a tip if you are using Fedora and trying to use one of the Google Sanitizers with clang and is having problems doing so. One of the common problems is not being able to find libclang_rt.asan-x86_64.a:

This can be resolved by simply installing the compiler-rt package:

Restoring click method behavior on Fedora 25 and libinput

Here’s a quick tip if you need to enable the Software Button Area behavior on an Apple macbook running Fedora 25:

Some comments about this:

  1. You have to run it after every reboot
  2. There’s, probably, a better way to do this. Per documentation, it should be possible to set it up permanently by creating a file on /etc/X11/xorg.conf.d however I did not manage to create a file that works so far.

References:

 

OpenPHT builds for Fedora

I have created Fedora packages for OpenPHT, a community-driven fork of the Plex Home Theater client. The packages can be download from this link (I plan to propose adding the RPM specs to the main project, but before doing so, I would like to make sure they are working as expected).

The build instructions, for those interested in reviewing or rebuilding the package can be found in this gist or in the RPM spec file.

Macbook touchpad configuration tip for Fedora Linux

Some time ago I wrote a few tips about Running Fedora 22 on a Late 2013 Macbook Pro (Retina). Fedora is now on its version 24 and remains the best Linux distribution out there and the tips are still valid.

However, there’s one new tip. Instead of dealing with the Synaptics/Synclient stuff by yourself, you may want to try using the configuration from my Copr repository instead:

And with that you should have a touchpad behavior that is similar to the one on OS X.

 

Some messaging stuff

Just sharing some messaging tools I have been working with recently.

The first one is this performance test tool: msg-perf-tool. There’s no secret here: you run the tool and it does its best to bring your messaging system to its knees (though this may not be the correct way how to test it … check the testing tips on the Github page). For now it supports only AMQP, but Stomp and MQTT support is on the way. You can find rpms for RHEL/Centos (6 and 7) and Fedora (22, 23 and 24) for i686 and x86_64 on my Copr profile here.

The second one is a web page that can display the performance data stored on an ElasticSearch database and present it in a beautiful way. I call it messaging performance center. Here’s how it looks like:

messaging performance tool
mpt-perf-ui

Some bits are still in progress, but it’s functional.

Lastly, there’s litestomp. A C implementation of the Simple (or Streaming) Text Oriented Messaging Protocol. It was built on top of what-seems-to-be the now defunct libstomp project. There’s a couple of bugfixes, a simpler and higher level API for ease of use. Still a work in progress, but you can download the current rpms for RHEL/Centos (6 and 7) and Fedora (22, 23 and 24) for i686 and x86_64 from my Copr project page on this link.

Parallels Tools 10 and Linux Kernel 4.2

There seem to a be problem with Parallels Tools 10.3 and recent versions of the Linux kernel (4.2, at least, which is used by recent versions of Fedora 22 and Fedora 23, for example). During the installation tools, the installer fails to compile one of the modules. That can lead to problems booting up your virtual machine.

In Fedora, in order to avoid this problem, you can just add the following line to /etc/dnf/dnf.conf file:

After Parallels release an update, you just remove the line, update the system, and it should be fine. As a final reminder, you should always generate a snapshot before upgrading the system.