SEO-friendly, user-readable URLs with phpBB 3.2

I set up a forum using phpBB 3.2 this week and I wanted the URLs to be user readable and SEO-friendly (although this doesn’t really matter to search engines anymore, still figured it’d be a nice-to-have feature). I decided to make some changes to the phpBB core files. Now, my approach isn’t exactly ideal, because there will definitely be problems that arise from merging if any of the files modified for this are updated in newer versions of phpBB, but it gets the job done. If you would like to achieve this, you can proceed with the steps below after the friendly warning.

Disclaimer: Proceed with these steps at your own risk. I am not liable for any damage or harm that may occur to your forum, database, server, computer, or even pets from making use of the modified files in order to achieve the desired functionality. Always remember to make multiple backups of your files before making any changes.

First things first. Here are the fancy URL formats that we want to achieve.

  • /memberlist.php becomes /members
  • /memberlist.php?mode=viewprofile&u=2 becomes /members/u2-admin
  • /viewforum.php?f=1 becomes /f1-awesome-forum-url
  • /viewtopic.php?t=1&f=2 becomes /f2-another-awesome-forum/t1-just-do-it

This can be achieved by adding the following Apache rewrite rules to your .htaccess file (or your httpd configuration). Please note that mod_rewrite needs to be enabled for this to work.

If you’re running on nginx, you can add the following lines to your configuration.

Once you’ve updated your configuration files, unpack the ZIP archive into the top-level folder of your phpBB installation. Remember to make a backup of all your files before doing this. For reference, here are the files that will be overwritten after extracting the files in the archive.

  • .htaccess
  • index.php
  • memberlist.php
  • posting.php
  • search.php
  • viewforum.php
  • viewonline.php
  • viewtopic.php
  • includes/functions.php
  • includes/functions_content.php
  • includes/functions_display.php
  • includes/functions_posting.php
  • phpbb/feed/helper.php

You can view the modifications in action at To reiterate, this is not an ideal solution, and you have to watch out for conflicts if you’re trying to upgrade to newer versions of phpBB, but it gets the basic job done. If there are any improvements you’d like to see, post a comment below.

The archive can be downloaded from

Configure Redis as an in-memory only cache like Memcached

There’s a new project I have been working on where I needed to make use of an in-memory cache to take some load off of the database. Memcached has been around for a long time, and it’s what I thought about using at first, but I decided to use the opportunity to learn about Redis instead. Working with Redis is fairly straightforward, and it provides very useful and helpful data types in addition to simple strings such as sets and maps.

Redis stores every object in memory, but it turns out it also dumps the contents of memory to disk by default. I needed to disable this, so after digging around, I came up with this minimal configuration which makes Redis act more like Memcached, in-memory only with no disk writes. Of course, keep in mind that if you have to restart the Redis instance, the data will be lost, so it only makes sense to use this if the data which you need to cache can be repopulated from a persistent store.

Controlling an Arduino connected to the PINE64 over I2C with C and C#

In a previous post, we connected an Arduino Mega to the PINE64 and wrote a sketch for the Mega for data communication. The data to be sent and received will follow the simple rules which were listed in the post. Next, we’re going to write a shared library with some C code to interface with I2C natively, and then a C# class which will call the shared library and bring everything together. Just a quick recap of the data rules:

  • Maximum length: 16 bytes.
  • First byte: Number of bytes sent/received.
  • Second byte: Control command. CMD_DIGITAL_WRITE (0x01 or 1), CMD_DIGITAL_READ (0x02 or 2) and CMD_ANALOG_WRITE (0x03 or 3).
  • Third byte: Pin number.
  • Fourth byte: Value of either 1 (for high) or 0 (for low) for CMD_DIGITAL_WRITE, or
  • Fourth to seventh bytes: Integer value for CMD_ANALOG_WRITE.

Linux has native I2C support which lets us communicate directly with any device connected to the bus. Since native communication is possible, we create a shared library with methods which can be invoked from our C# code. Since we can open the connection to a device on the I2C bus as a file descriptor, we will be making use of fcntl.h for the descriptor. Let’s take a look at the C library.

The first thing we do is include required headers and define a constant specifying the maximum number of bytes, which is 16. Then we create the nanite_i2c_open function try to open the specified device file (usually /dev/i2c-1). Next we call ioctl so that we will be able to control the device using a reference to the file descriptor, and the specified slave address. The file descriptor is returned for reference in other function calls. If any of the steps in the function fails, -1 is returned to indicate an error condition. Other functions in the library will handle the failure the same way.

The nanite_i2c_close function is fairly simple. It takes the file descriptor as an argument and checks if it is open in order to close it.

Next is the nanite_i2c_send function which takes the file descriptor and the data to be sent as arguments. The bytes are written to the open file descriptor, and the number of bytes written is verified. If it does not match the length defined in the first byte, -1 is returned to indicate an error condition.

The nanite_i2c_read function will be used to read data over I2C. The first byte is retrieved in order to determine how many more bytes to read. Then we validate the number of bytes that were received with the expected length. 0 is returned if the operation was successful.

The final function in the library is nanite_i2c_max_bytes() which returns MAX_BYTES. This gives us a complete library that we can use for I2C data communication. You can create the shared library using gcc -shared -o -fPIC main.c. The full code listing for the library is available at

Using DllImport, we can call functions from the shared library in the C# code which we’re going to look at next. We create our class, define the supported commands as an enumeration and specify the private members. We also define a couple of constructors with the default constructor using the default I2C device file which is /dev/i2c-1 on the PINE.

The DllImport calls are defined within the class and are used to map the functions from the library to functions that we can call in the I2CExtendedIO class. For instance, to call the nanite_i2c_send in the class, we’ll make use of I2CSendBytes.

Here, we’ve defined our class dispose function which closes the file descriptor if it is open. We also have a bunch of simple helper functions which will be called within the class.

The Open function is simple as it delegates to the OpenI2C function with the specified device filename and the slave address, and assigns the returned file descriptor to a private member.

With DigitalWrite, we build the data to be sent based on the specified rules. Then we delegate to I2CSendBytes using the specified arguments, which calls the corresponding library function.

AnalogWrite is similar to DigitalWrite, except that we convert the integer value to 4 bytes instead of the single byte for low (0) or high (1). Valid values are between 0 and 255 inclusive.

To wrap it all up, we have the DigitalRead function which is a little different because we have to send data and then immediately receive a response. We obtain a mutual-exclusion lock so that the send and receive process completes before any subsequent operations are run. Then we validate the received data and return the value for the pin that was read.

You can obtain the full code listing for the C# class at

We can put this all together and test with a simple interactive console application.

The console application accepts inputs like 13 on, 18 off or 9 analog 172 which makes it easy to test the Arduino pins. Although this is practically a complete solution for most requirements with respect to controlling an Arduino connected to the PINE (or Pi or any other SBC) over I2C using C#, you could choose to implement an additional command for analogRead. All you would have to do is follow the logic for digitalRead and add the necessary code to the sketch and the C# class.

Extending GPIO with an Arduino connected to the PINE64 using I2C

Although the PINE64 provides quite a decent number of GPIO pins, there are several reasons that you may want to have access to more pins. For example, the Arduino can provide an extra number of native PWM pins, or you may want to implement low-level control of a robot using the Arduino, with high-level operations being handled by the PINE. This post will cover how this can be achieved with the PINE64 and an Arduino Mega. We’ll also create a sketch for the Mega which for handling I2C communication. In the next post, we will write some C and C# code which will show how to send and receive data between the PINE and the Mega. Note that this can be done with any single board computer that supports I2C including any of the Raspberry Pis, the Beagleboard and others.

PINE64 connected to Arduino Mega over I2C

I2C stands for Inter-Integrated Circuit and it is a serial computer bus that enables communication between multiple devices that support the protocol. Every board that supports I2C will have 2 pins called SDA (serial data line) and SCL (serial clock line).

Pins 3 and 5 of the Pi 2 pinout on the PINE64 are the SDA and SCL pins respectively. On the Mega, they are pins 20 and 21. Connect the SDA and SCL pins from the PINE64 to the SDA and SCL pins respectively on the Arduino. I have also connected the 5V from the PINE to the Mega in order for the Mega to be powered by the PINE. If you decide to take this approach, one of the ground pins also has to be connected between both boards.

A closer look at the I2C connection between the PINE64 and the Arduino Mega

Before connecting the Mega, we’ll need to create and upload a sketch that will assign an I2C address which will be used to access the device. The sketch will make use of the Wire library which will be used for I2C communication. We will be making use of byte arrays to send and receive data over the I2C bus. You can come up with a fancy protocol for this, but I came up with the following simple rules.

  • Maximum length of 16 bytes.
  • First byte will always be the length (inclusive of the first byte) of the data sent or received.
  • Second byte is the command. We’ll support 3 simple commands, digital write (0x01 or 1), digital read (0x02 or 2) and analog write (0x03 or 3).
  • Third byte is the pin number.
  • For digital write only, fourth byte be a value of either 1 (for high) or 0 (for low).
  • For analog write only, the next four bytes after the third byte will store an integer value between 0 and 255 inclusive.

With that out of the way, let’s take a look at the sketch. First things first, define our constants and variables.

The code is straightforward. We define 0x08 as the I2C address that we want the Mega to use. We also define our commands, pin states (for digital read / write), buffers for storing data to be sent and received and other variables that will be used. The ioPins array is a list of all the pins available on the Mega. This will need to be changed to match the board that the sketch will be uploaded to. The ioPinStates is a pseudo hashmap which will map the pin number (used as the array index) to one of the defined pin states (IO_PIN_STATE_INPUT or IO_PIN_STATE_OUTPUT). We’re keeping track of the pin states so that we can activate the pins on demand, instead of activating them all at once in the setup() function.

The setup function simply initialises the Wire library using the specified I2C address, and enables Serial output which will be used to output debug messages. Wire.onReceive registers the onDataReceived function which will be called when data is sent from the PINE64, while Wire.onRequest registers the onDataRequested function which will be called when the PINE64 requests data from the Mega. The isPinValid function is a helper method which checks if the pin specified as the parameter is valid for the board. It checks the pin against the ioPins array that we defined earlier.

Next is the onDataReceived function which handles most of the work. It accepts an argument which represents the number of bytes that were received.

The while loop checks if there is data available from the Wire library. If there is, the absolute minimum number of bytes received that can be considered valid based on the rules we defined earlier is 3 (length, command, pin). If the number of bytes received is less than 3, then the function ends at that point and output is written to the Serial console. The next step is to use a switch statement to check and handle the command that was received. The second byte (index 1) contains this data.

For digital write, the minimum number of bytes to be considered valid is 4 (length, command, pin, value). The function is terminated if we received less than 4 bytes for the command. The isPinValid is called to check if the pin received is valid, and if it isn’t, the function ends at that point. Next thing to be done is to check if the pin has been activated. We make use of the ioPinStates array to do this making use of the pin number as the index. If the pin has not yet been activated (IO_PIN_STATE_OUTPUT), then we activate the pin using pinMode. Once this check is complete, we can call digitalWrite using the pin and the value specified.

Digital read also follows the same set of steps as digital write (validate date length, validate pin, check pin state) but we will call the actual digitalRead function in onDataRequested. What we do here is store the command and the pin in variables (lastReadCommand and lastReadPin respectively) which we can then make use of in onDataRequested.

Similar to digital write, analog write follows a couple of steps (validate data length and validate pin). We don’t need to check or set the pin state before calling the analogWrite function. We check that the value is between 0 and 255 inclusive before calling analogWrite with the pin and the value as the arguments.

If the data sent did not match any of the defined commands, the code falls back to the default statement which outputs Unrecognised command. to the serial command, and then the onDataReceived function will be called again when new data is received.

Finally, we have the onDataRequested function which makes use of lastReadCommand and lastReadPin. The function is straightforward, as it uses the Wire library to send data back to the PINE following our simple rules.

And that’s it! Compile the sketch using the Arduino IDE and then upload it to your board. Connect your Arduino to the PINE after the sketch is successfully uploaded, and boot up the PINE. You can obtain the full code listing for the sketch at

Install i2c-tools using sudo apt-get install i2c-tools. By default, only root can use the I2C commands, but you can add the user account with useradd -G i2c ubuntu (replace ubuntu with the username that you want to use to access I2C). Reboot the PINE and then scan the I2C bus with the command, i2cdetect -y 1. You should get output should be similar to the following:

Based on this output, we can see that the Mega was recognised over the I2C bus with the configured address in our sketch (0x08 or 8). With this, we have access to the extra pins which we will be able to control directly from the PINE. That’s pretty neat. In the next post, we will write the C and C# code for the PINE for handling I2C communication.

Control GPIO pins on the PINE64 with C#

Similar to the Raspberry Pi, GPIO pins on the PINE64 can be controlled through sysfs. You can refer to my previous post which goes into the concept in detail, and the C# code remains the same for the PINE64. However, with the longsleep Ubuntu image, root access is required to control the GPIO pins. You will need to grant the necessary permissions in order to be able to control GPIO pins as a normal user.

Granting user permissions
We’ll assume that we want to be able to control the pins as the default ubuntu user. Follow these steps to grant the necessary permissions.

  1. Create a user group called gpio.
    groupadd gpio
  2. Add the ubuntu user to the gpio group.
    useradd -G gpio ubuntu
  3. Add a udev rule to run chown on the sysfs files. The chown command will set group ownership to the gpio group. Adding the udev rule will run the chown command automatically whenever you export a pin. Create a file called 99-com.rules in /etc/dev/rules.d and paste the following contents.

    Physical pin to GPIO number mapping
    I took some time to test the physical pins on the PINE in order to determine the sysfs gpio numbers and came up with this table. As an example, physical pin 22 on the Pi 2 pinout corresponds to /sys/class/gpio/gpio79.

    Pin #GPIO #
    Pi 2 pinout
    Euler pinout
    Exp pinout

Implementing cross-origin resource sharing (CORS) using middleware in CakePHP 3.3

I worked on a project recently where I had to allow XMLHttpRequests from a different domain. I initially thought about adding the necessary Access-Control headers at the controller level, but after doing some reading, it turned out it was a better idea to make use of a dispatcher filter. However, dispatcher filters would only apply prior to CakePHP 3.3 since they are now deprecated.

Enter middleware, which I found to be quite familiar since I have made use of a similar concept in Express during my Node.js development. Think of middleware as reusable components which you can use to handle your web requests and modify responses.

The CakePHP middleware classes should be placed in the src/Middleware folder. You can create the folder if it doesn’t already exist in your project.

We’ll create a class in the Middleware folder called CorsMiddleware.php.

The code listing is pretty straightforward. The response is modified with the necessary headers to enable the cross origin requests to be successfully handled by the browser.

You can modify the header values as you see fit, like limiting the Access-Control-Allow-Origin header to specific domains – the wildcard (*) allows requests to be accepted from all domains – or the the request methods to just GET and POST, or the allowed request headers.

To make use of the cors middleware, modify src\Application.php and add the middleware using:
$middleware->add(new CorsMiddleware())

And that’s all there is to it. There are more details about what you can do with middleware in the CakePHP documentation, so be sure to check it out.

Measuring PINE64 Idle Power Consumption

I got a DROK digital multimeter and I decided to find out just how much power the PINE64 consumes running headless.

PINE64 connected to RAVPOWER powerbank through DROK multimeter

The measurements were taken on my 1GB PINE64 running longsleep’s Ubuntu image. The measured voltage from the powerbank is 5.06V.

CPU @ 1152MHzCPU @ 480MHz
WiFi / BT module plugged in260mA (1.32W)200mA (1.01W)
WiFi / BT module removed250mA (1.27W)190mA (0.96W)

This is not by any means a proper scientific test, but it gives an idea of what to expect. Got any tips for reducing power consumption? Feel free to share them in the comments below.


Hello and welcome to Antinormal. I used to maintain this as a personal blog but I decided to start all over since I wanted to take things in a different direction. I hope to make useful posts going forward.

My name is Akinwale and my favourite things are computers, video games, good movies and books. As I’ve grown older, I find that I haven’t had much time to play games anymore, but I still play The Division fairly regularly. The only other games I have played this year are Deus Ex: Mankind Divided and X-COM 2.

I like science fiction, technology and programming.

Thank you for reading! Comments and feedback are welcome.

Building MonoDevelop for the PINE64

MonoDevelop running on the PINE64 using SSH X11 forwarding

4 Dec 2017 Update
These instructions will not work with the latest versions of Mono and MonoDevelop from github. I tried compiling from scratch on a new image, and they will work with the following versions listed below. You can checkout the specific tags immediately after cloning the corresponding repositories before you start building.
Mono – git checkout tags/mono-
MonoDevelop – git checkout tags/monodevelop-

My PINE64 is here and the first thing I decided to do was build MonoDevelop which I’ll use to manage C# projects, since most of the code I’ll be writing for my autonomous project will be in C#. I’m using the longsleep Ubuntu Xenial image as a base, so these instructions assume that this is what you have installed. You can adapt as required based on your distro.

Of course, the easiest way to get MonoDevelop installed is by using the package manager. The version is also fairly recent (, so you can choose skip the rest of this post if you prefer. Simply run the apt-get install command and all required dependencies will also be automatically installed.

Most of the steps will be similar to the MonoDevelop for Raspberry Pi build post, but we’ll be skipping fsharp altogether. I cloned the fsharp repository but the make process failed due to the following error:

F# is only required for the fsharpbindings extension and I don’t plan on using that. There appears to be an fsharp package which you can install using apt, but this will also install the mono 4.2.1 dependencies. If you’re fine with using an older version of mono and would still like to build MonoDevelop, then you can also skip the steps up till Build MonoDevelop.

So let’s get started!

Install all prerequisites
Git is required to clone the source repositories for Mono, MonoDevelop and dependencies. The other packages are required for building MonoDevelop dependencies from source.


Pre-build: NuGet certificates
The MonoDevelop build process makes use of NuGet at certain points. You will need to import certificates into your certificate store using the following commands.


Build Mono
This step is fairly straightforward. Clone the mono source repository and run the build process.

This build will take a while. If you wish to run the mono and mcs test suites, you can do a make check before make install.

Build MonoDevelop dependencies
MonoDevelop requires gtk-sharp and gnome-sharp to be installed on the system. To build gtk-sharp.

gnome-sharp follows a similar process.

Some reference PCL Assemblies are required for the build to complete. You will need to build a deb package and install following the instructions below.

Remove mono-xbuild from the list of dependencies in the control file, save and close. Then proceed with the following commands.


Build MonoDevelop
First, we clone the monodevelop repository and initialise the submodules using git.

Next, we remove references to fsharp. The assumed working directory for these steps is the top-level monodevelop source directory.

Remove the external/fsharpbinding/MonoDevelop.FSharpBinding/FSharpBinding.addin.xml \ line, save the file and close.

Comment out or remove the following lines in the file and save your changes. To comment out the lines, simply prefix each line with the # character.

Then we can go on to build the IDE.

You can run mono main/.nuget/NuGet.exe update -self if you get the following error after running make.

Once the build is successfully completed, you can run the application using monodevelop. If you have X11 forwarding enabled for your SSH session, you should see the MonoDevelop IDE on your screen after a couple of seconds.

MonoDevelop running on the PINE64 using SSH X11 forwarding

MonoDevelop running on the PINE64 using SSH X11 forwarding

The PINE64 is finally here

1GB PINE64 with the WiFi module and RTC battery module installed. It's huge!

I received my PINE64 yesterday and I was pretty excited after such a long wait. The following items were in the package:

  • PINE64 1GB board
  • Camera module
  • RTC battery module (which is actually bigger than I expected)
  • WiFi/Bluetooth module

They were all in good shape, and the board was not bent nor warped which I was afraid would happen after reading a few horror stories. The Pine64 is most definitely a huge board (compared to the Raspberry Pi), and the build quality also seems solid. I was able to burn the longsleep Ubuntu Xenial image to a 32GB microSD card, and since I wanted to run the board as a headless device, I mounted the microSD on my Linux box and updated the /etc/network/interfaces file to connect to my wireless network. The connection to the network was established a few seconds after providing power to the board and I was able to SSH into the device after the boot process was successfully completed.

I’ll update this post with a few pictures once I get a decent camera.


1GB PINE64 with the WiFi module and RTC battery module installed. It's huge!

1GB PINE64 with the WiFi module and RTC battery module installed. It’s huge!

PINE64 side-by-side with a Raspberry Pi 3 and the Keyestudio Mega clone

PINE64 side-by-side with a Raspberry Pi 3 and the Keyestudio Mega clone