External devices and the watchdog

The ominous EEPROM

In one of my last posts I explained how the watchdog of the RevPi Connect can be used. If you look into our tutorial, there is also an ominous EEPROM mentioned. How exactly is that connected? And what do the Illuminati have to do with it?

The relay can be used to reset external devices when the watchdog triggers. But not for every application it is desired that the relay switches with the watchdog. In addition, the relay can be used as a normal relay output.

Therefore this function was designed to be configurable. This is where the EEPROM comes into play, because it carries the configuration for the relay.

The tutorial provide two ready-to-use Python scripts to program the EEPROM. enable_relay_watchdog.py configures the EEPROM to trigger the relay with the watchdog. enable_relay_watchdog releases the connection between watchdog and EEPROM. The logic of the Python scripts can of course be recreated in C. So the behaviour of the relay can be set directly from the application, without having to use the Python script.

The FTDI library

I noticed that the necessary library libftdi1 is present, but not the header. Here you will find the FTDI driver inclusive header file: https://www.intra2net.com/en/developer/libftdi/download.php. Please note, Raspian Stretch is delivered with the old version 1.2 of the library. Meanwhile there is 1.4 available. In case the headers have changed, I played it safe and downloaded the old version 1.2: https://www.intra2net.com/en/developer/libftdi/download/libftdi1-1.2.tar.bz2.

After creating a new project in Netbeans, I added the new library to the project. That killed my nerves a bit, because the library is there, but I could only get the linker to find the file if I specified the path absolutely. For this purpose, I specified “/usr/lib/arm-linux-gnueabihf/libftdi1.so.2” under “Build->Linker->Additional Options”.

Screenshot of the Netbeans Project Properties showing where to type in the path of the FTDI library

Later I created a symlink libftdi1.so -> libftdi1.so.2. with

ln -s libftdi1.so.2 libftdi1.so

Then I could also use “Libraries”→”Add Library” and just enter ftdi1 here. Should look like this

Screenshot of the Netbeans Project Properties showing the list of the libraries used in the project

Netbeans simply makes the compiler option “-lftdi” from this.

Translation of the Python script

For the program I translated the Python script enable_relay_watchdog.py one to one in C. The string handling is a little more complex than in Python. I have made it easy for myself at this point. The code only works as long as devnum consists of one digit, i.e. is less than or equal to 9.

int devnum = c - '0'; //convert char to int

char str[6] = "";
sprintf(str, "d:1/%i", devnum);

If you expect devnum to be larger, a simple devnum = c – ‘0’ is no longer sufficient for conversion. The string must also be longer than 6 characters. If you plan to use the code in a real application, I advise you to implement the conversion mechanism safely!

Here you will find the Netbeans project.

When executing the program, make sure that it is called with root privileges, i.e.

sudo <path>/revpiwatchdogrelayenable

If you want to test if the delay relay really switches, let the watchdog respond. Now you should hear the quiet clattering of the relay.

Here is the same program that matches the phyton script “disable_relay_watchdog.py”.

Leave a Reply

Your email address will not be published. Required fields are marked *