2024-02-05
md
Mochad on Recent Linux Distributions

Let's start with an executive summary: if problems are encountered when compiling the mochad source code or if the gateway will not run because of a usb_claim_interface failed -6 error, then try installing my fork on GitHub: https://github.com/sigmdel/mochad.

If you are happy to just get a working mochad installation, the GitHub repository has all the needed information; there is no need to read what follows.

Table of Content

  1. The Background
  2. Updates that Break Things
  3. It's a Bit of a Mess

The Background toc

Mochad is a gateway between an X10 controller (CM15A, CM15A Pro or CM19A) and computers on the local area network using the TCP protocol. Written in C, it was uploaded to SourceForge on December 8, 2010, by mmauka which may be the user name of Brian Uechi.

... $ usr/local/bin/mochad --version mochad 0.1.17 Copyright (C) 2010-2012 Brian Uechi.

I have used mochad from 2016 (see Domespic [3] Gateways) until about three weeks ago when my home automation system was moved to a new server and all X10 hardware was removed. Because the combination of a CM19A USB PC transceiver and a HR12A PalmPad remote control is a simple, straightforward means of controlling IoT devices that anyone can understand, I wanted to pass it on to someone about to set up a home automation system. This required installing mochad on a 64-bit ARM-based single board computer running a recent Ubuntu 22.04 based distribution from Armbian. I was nonplussed when the installation failed for the first time in the last six years during which mochad was used with numerous Linux images on at least four different single board computers.

A number of problems were encountered. First the configure script started with an ominous message.

.../mochad-0.1.17$ ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes /home/mike/mochad/mochad-0.1.17/missing: Unknown `--is-lightweight' option Try `/home/mike/mochad/mochad-0.1.17/missing --help' for more information configure: WARNING: 'missing' script is too old or missing ...

Then the build failed with the following messages, which were repeated a number of times.

/usr/bin/ld: decode.o:/home/house/mochad-master/global.h:31: multiple definition of `RfToRf16'; mochad.o:/home/house/mochad-master/global.h:31: first defined here /usr/bin/ld: decode.o:/home/house/mochad-master/global.h:29: multiple definition of `RfToPl16'; mochad.o:/home/house/mochad-master/global.h:29: first defined here /usr/bin/ld: decode.o:/home/house/mochad-master/global.h:26: multiple definition of `PollTimeOut'; mochad.o:/home/house/mochad-master/global.h:26: first defined here /usr/bin/ld: decode.o:/home/house/mochad-master/global.h:25: multiple definition of `Cm19a'; mochad.o:/home/house/mochad-master/global.h:25: first defined here

Thinking, incorrectly as it turned out that the outdated configure script may have somehow been the source of this error, I searched for an updated version of mochad. This yielded a repository on GitHub by Boris Jonica (bjonica) that started as a fork of version 0.1.12 of the original mmauka mochad code on SourceForge. A few months later, Nicholas Humfrey (njh) made a significant contribution that removed the configure script and replaced it with an autogen script which will generate a configure script. This change was not incorporated by mmauka into the SourceForge repository. On the other hand, changes made by mmauka up to version 0.1.17 were for the most part incorporated into the GitHub repository, but not all as will be seen. Among the forks of the bjonica repository, there is one by Neil Cherry (linuxha) of Linux Home Automation fame that added optional support for IPV6 and bumped the version number to 0.1.18. I decided to try that version https://github.com/linuxha/mochad.

This time round, configuration proceeded without a flaw, but the linker errors remained. Luckily, this was easy to fix because I had faced that type of error on quite a few occasions writing small microcontroller projects. Declaring those variables defined multiple times as extern in global.h and defining PollTimeOut in global.c was all that needed to be done. With that change, the mochad binary was created without error it and it worked as expected when launched manually. However when the daemon was launched by the udev rule added to the system during the installation process, it would be quickly shut down with the following error message.

... usb_claim_interface failed -6

This was something seen before, and indeed, it had been the motivation to use version 0.1.17 back in 2016. A little investigation showed that all the changes brought to version 0.1.17 by mmauka had not been added in the GitHub forks. That was surprising because the change log was explicit about what the new version added.

mochad-0.1.17 * Fix for Linux distros using systemd-udev such as Raspbian 4.4. * Fix for newer versions of autotools.

Consequently, it made sense to add the systemd changes introduced in 0.1.17 into the modified version described above as I suspect that a significant proportion of the few that still use mochad would require compatibility with that init system. This also required a slight change to the Makefile.am file. The version of mochad.service found in this fork comes from Andreas' 2021-09-07 post mochad gets usb_claim_interface failed - udev rule on the grounds that the unit file looks more sophisticated to me... but then what do I know?

For the sake of historical accuracy, let's add that the source of the usb_claim_interface failed -6 problem under systemd was identified by Vicente back in 2016-04-07. Patrick Kuijvenhoven (petski) provided a working systemd service file in a 2016-04-15 commit in a 2014 GitHub fork of the SourceForge code that is independent of the bjonica hierachy of forks. There were no udev rules and petski's 2016-04-15 post on SourceForge has a line deleting the previous udev rules. Presumably, he envisioned that the service file was to be enabled and hence automatically loaded at boot time.

Updates that Break Things toc

Why was the linker reporting errors in 0.1.17 when compiling the project on the Armbian system and the most recent Raspberry Pi OS but not on my relatively recent Mint 20.1 desktop and why had no one reported this problem? It has to do with the version of the build-essential package and more specifically with the version of the linker, ld, it contains and perhaps the version of the gcc compiler.

systemversion0.1.17
compilation
gccldbuild-essential
Mint 20.19.4.02.3419.8succesful
Raspberry Pi OS 2022-04-0410.2.12.35.219.9failed
Armbian 22.05.311.2.02.3819.9failed

I was wrong about the compilation error not being mentioned anywhere. Not only did Steve Porter report the problem on the mochad discussion board in a post entitled Rasberry PI compile errors on February 5, 2022, but he also provided a solution based on the original 0.1.17 version. His solution is different from mine and a proof that there is always more than one way to do anything.

It's a Bit of a Mess toc

After all these years, SourceForge still serves version 0.1.16 of mochad as the latest version. That version is not compatible with systemd which is probably used on the majority of Linux computers on which mochad will be run. It was up to users to find version 0.1.17 which is a shame because I believe 0.1.17 would have installed properly in non systemd environments. But now, even if version 0.1.17 is used, it will no longer compile on newer distributions.

Some will probably search GitHub in the hope of finding an updated version of the code. They will find numerous "one-off" forks none of which will work with the latest build tools. Here are some that I found.

As already mentioned, the Patrick Kuijvenhoven petski/mochad fork, which is based on version 0.1.16, added a mochad.service and corresponding udev rules before version 0.1.17 was put up by mmauka. Patrick has also contributed a docker-compose.yml file. There are two forks of this version of mochad but they contribute nothing new.

Also mentioned before, there is the bjonica/mochad repository in GitHub and its numerous forks. As stated, none of these (except my own) will work with systemd but they do have a newer configuration system. After a cursory examination of these forks, the most interesting is the Neil Cherry linuxha/mochad version that adds optional IPV6 support. This is version 0.1.18 of mochad and it is this version that I modified.

Steve Porter hints that there may be a 0.1.19 version, but I could not find it. Nor is there even a whisper of a 0.1.20 version. As stated above, he provides a fork of mmauka 0.0.17 which he presents as mochad-0.1.21 . It is a different solution to the compilation problem. See details here. Casey Langen (clangen) has incorporated the changes by Steve Porter into another mochad GitHub repository; I have not tested this version.

This profusion of forks would probably be confusing to anyone wanting to use mochad for the first time. So the conclusion to all this appears to be that for most users, either

or

is the best choice.

If IPV6 support and compatibility with systemd are needed, then my version would presently be the only choice. Note that by default, IPV6 is not enabled until the value of the IPV6 macro at the very start of mochad.c is changed from 0 to 1.

#define IPV6 1

I do not use IPV6 and have not tested that code at all. Any questions about that feature would have to be addressed to its author, Neil Cherry.