Key Takeaway

Raspberry Pi is an experimenter’s dream come true. It offers light to medium computing power in a small form factor with all the bells and whistles like Wi-Fi, Ethernet, Bluetooth, USB 2.0 ports etc. Further augmenting a tinkerer’s abilities are the software capabilities, which now stand further extended due to the introduction of .Net Core which allow you to leverage your existing background with Visual C# and run code on ARM architecture. In this post we will take a look at all the steps that one has to perform to run code created using Visual C# and targeting .Net Core on a Raspberry Pi 3.

Read On

.Net Core is a cross platform offering from Microsoft which allows you to run your C# code on multiple hardware (x86, x64, ARM etc.) and software platforms (Windows, Linux and macOS). Of course, it does not provide universal coverage, and at the time of writing this post, industrial grade long-term support versions of operating systems are being targeted with higher priority by Microsoft. It is natural, after all those are the operating systems that organizations would be using to run their applications.

But there’s something about frugal engineering and Raspberry Pi is a prime example of that. With support from the community, it is possible to have the code made targeting .Net Core, be run on Raspberry Pi 3. Here are some of the points that you may want to read before going any further:

1. Note that the compilation targeting ARM hardware (ARM32) for both Linux and Windows software platforms are not being officially supported by Microsoft. So, have justified expectations and be prepared to get your hands dirty with some virtual dirt. See their official statement here.

2. At the time of writing this post, it is only possible to run .Net Core code on Raspberry Pi 2 and 3, and not on Pi Zero. This is because .Net Core at the moment targets ARMv7 instruction set and above for ARM architectures. Raspberry Pi 3 uses a Broadcom BCM2837 chip which uses ARMv8 instruction set, while Raspberry Pi Zero uses BCM2835 chip which uses ARMv6 instruction set. See the official statement here.

3. There is no Software Development Kit (SDK) available at the moment that helps you develop software on Raspberry Pi for Raspberry Pi, so you will have to develop your code on a supported development environment and then copy over to Pi for execution.

Alright, if you have made this far, I am assuming that you want to give it a go.

Creation of a console application

First let’s develop our application and since this will be the first time we will be running a .Net Core project in Raspberry Pi, let’s keep things simple. Fire up your Visual Studio and then create a new console application project. I named mine as “DotNetCoreOnRPi”. Just so that we can easily identify that the things are working as desired, add a line in your main program:

Console.WriteLine("This program was created in Windows 10, but running in Raspberry Pi. :)");

Save your program and open the developer console and navigate to the folder containing your project.

Any application targeting .Net Core can be executed either as a self-contained application (Self-contained deployment) packing all the assemblies that its execution depends upon, or as an application depending on the .Net Core framework (Framework-dependent deployment). You can read more about that here. We will publish our application as a self-contained application on Raspberry Pi.

Self-contained deployment

In order for the application to execute in a supported operating system, it still needs some functionality that is supported by the targeted operating system. Raspbian Stretch operating system, the official operating system supported by the Raspberry Pi Foundation, comes missing just one essential package. Run the following code to install the “libunwind” package.

sudo apt-get install curl libunwind8 gettext

Once done we need to return to our developer prompt and publish the project targeting the “linux-arm” platform by using the following line of code:

dotnet publish -r linux-arm

This will create a folder in the bin/Debug/netcoreapp2.0 named “linux-arm”. Within the linux-arm folder will be a folder named “publish”.

Copy the entire publish folder at a suitable location in your Pi. Open a terminal window and navigate to the publish folder. Make sure that you have the appropriate permission to execute the application. You can use the following command to grant the execution permission:

chmod 755 ./DotNetCoreOnRPi

Then execute the application by using the command:

./DotNetCoreOnRPi

For now, all the official and un-official documentation points to the fact that framework-dependent deployments are not supported. Let’s hope that Microsoft starts supporting Arm32 builds officially and we can reduce the size of our deployments by relying on the .net core framework available on a system-wide basis.

In my last post I wrote about how to install and operate Raspbian operating system in a headless mode using a static IP address with the intention of starting and using services that require a static IP address. Plex Media Server is one such service which can run fruitfully on Raspberry Pi 3 Model B and use the hardware to the fullest. In this post I will demonstrate how to install Plex Media Server on your Raspberry Pi and consume media from it.

Read On

Plex Media Server as the name suggests is a media server and can serve various types of media on a variety of devices. The basic premise behind the server is to provide media to the consuming point per the capabilities of the client. For example, if you have a video file in mkv (Matroska) format and you want to see the video on an iPad, you cannot do until you transcode the file into a format that is compatible with iPad. In this case it will be mp4. Plex provides on the fly transcoding capabilities, so you do not have to wait for the entire video file to be transcoded and then see it. It instead, transcodes the file on the fly and streams it to your device.

To get started, make sure that you have the latest version of Raspbian operating system installed and Pi is configured to communicate to your router using a static IP address. Before we start, let’s make sure that the system is having the latest packages installed using the following commands:

sudo apt-get update sudo apt-get upgrade

Update command brings information about the newer versions of the packages installed in the operating system and are available in the repository, while upgrade actually downloads the packages and installs them. Please note that upgrading the packages can download a significant amount of data, so if you are on metered bandwidth, beware.

After this we need to ensure that the traffic between Pi and clients travel on an encrypted channel. For that we need to make sure that the “https” package is installed and running. Run the following command:

sudo apt-get install apt-transport-https

Plex is not officially supported on Pi, so we will download the port created by the good folks at dev2day. The first step to do that is to add the public key corresponding to the package. Run the following command to get it done:

I tried searching for the Plex package made for Stretch, but was not available at the time of writing this post/. So we will install the one available for Jessie. Add the package to the list of packages by running the following command:

We need to change the default user under which the PMS is supposed to run from “plex” to “pi”:

sudo nano /etc/default/plexmediaserver.prev

Now restart the plex service and reboot Pi:

sudo service plexmediaserver restart sudo reboot

Once Pi comes up, go to the static IP address at which Pi operates appended by “:32400/web” and it will take you to the welcome screen. From there on you can register for an account and add media to your library. Note that creating and using an account is not necessary to use Plex.

Key Takeaway:

Installation of the Raspbian operating system on a Raspberry Pi requires an external keyboard and mouse for providing input and an external HDMI monitor to see what’s happening. In this post, we will learn how to configure the boot media, so that we are able to leverage our existing Windows hardware for the installation and subsequent operations without requiring an external keyboard, mouse and a monitor, also known as the “headless mode”. We will also be connecting our Pi to our Wi-Fi network without the any intermediate use of an Ethernet cable and will allocate it a static IP address.

Read On:

Raspberry Pi is a single board computer that offers a fun way to learn about Linux and is capable of handling various projects that require light to medium computing power. It is one of the most favored platforms for prototyping an IoT project.

Installation of most of the Raspberry Pi compatible operating systems at the time of writing this post requires the presence of an external USB keyboard and mouse to provide input and an HDMI capable monitor to receive video feed of what’s happening. These requirements prove to be a bit of a hurdle in getting Raspberry Pi up and running. Fortunately, things are improving and creators of Linux distros are making sure that there are ways to configure Raspberry Pi to facilitate a headless install, configuration and subsequent operation with the use of existing integrated hardware like a pc or a laptop.

In this post I will demonstrate how to install and operate Raspbian operating system in a truly headless fashion using your existing Windows PC hardware. We will accomplish the following:

I am writing this post assuming that you are working with a Windows enabled computer.

Head over to RaspberryPi.org and download the latest version of Raspbian operating system with desktop. Now we need to transfer this operating system to the micro-SD card.

To transfer the operating system onto the micro-SD card we will be using Etcher from resin.io. Brilliantly simple to use and just works with a wide variety of image formats. Etcher can directly work with zipped images, eliminating the need to unzip the downloaded images. You can also download the portable version and use it without installing it.

Figure 1 Etcher in action

Once you have flashed and validated the micro-SD card with the operating system, prepare to perform some steps that are going to make the entire installation and subsequent operation a headless one. If you open the card in Windows Explorer, then you will be able to access the boot folder containing a few files. Since Windows does not recognize EXT4 file system, you will not be able to see or access any other of the partition on the card or any folder or file contained therein.

Enabling SSH

To enable headless configuration and operation of Raspberry Pi, it is essential that we have some mechanism to login into our Pi. SSH enables that. By default, SSH now comes disabled in Raspbian Stretch operating system. But it can be easily enabled by introducing a file named “ssh” with no extension. You do not have to bother putting anything in the file as just the presence of the file will indicate your intention to enable SSH in Raspbian at the first and subsequent boots.

Figure 2 Insert a blank text file SSH excluding any extension

Configuring Wi-Fi

One of the changes introduced in Raspbian Stretch was the ability to put “wpa_supplicant.conf” file into the boot folder which at first boot could be used to configure network settings. So open up your Notepad++ and open a new text file. Make sure to change the “End of Line” setting set to “UNIX” (Edit->EOL Conversion). If you do not change this setting, Notepad++ will use Windows end of line settings and network settings will not take effect.

Figure 3 Change the EOL setting in Notepad++ to UNIX when handling any file for Raspbian

Insert the following settings into the file:

1: country=in

2: update_config=1

3: ctrl_interface=/var/run/wpa_supplicant

4:

5: network={

6: scan_ssid=1

7: ssid="MyNetworkSSID"

8: psk="MyNetworkPassword"

9: }

Change the country entry to the applicable one. Similarly use the SSID of your Wi-Fi network and corresponding password.

Save the text file in the boot folder and name it “wpa_supplicant.conf”. The significance this file is that it serves the configuration to the supplicant (basically hardware or software that connects to a network. More info is available here), and after the first boot gets copied into the “/etc/wpa_supplicant” directory for operational purposes. You can read more about this here (in context with Raspbian Stretch).

Now that we have taken care of SSH and Wi-Fi settings, let’s get ourselves a static IP address where we can SSH to. Boot up your Pi.

Configuring for a static IP address

Now to assign a static IP address to our Pi, we need to login into Pi at the IP address that gets allocated to our Pi at its first boot. We will use that IP address in Putty and start our SSH session and carry out further configuration to work with a static address.

We can find the IP addresses allocated to various devices with the help of the Advanced IP Scanner tool available from Famatech. The best thing about this tool is that you can run this tool without installing it, in portable mode. Boot up your Pi and then run this tool to see the IP address allocated to the device.

Once you have noted down the IP address allocated to Pi, use Putty or your favorite SSH tool to login into Pi.

Figure 5 SSH into Pi using the allocated IP address

The default username and password to be used for logging into Pi are “pi” and “raspberry” respectively. After logging into Pi via SSH, use the following steps to configure Pi to have a static address.

Figure 6 Successful SSH login

Now give the following command to know about the gateway (your router in this case), just to be sure that your Pi is communicating at the IP address shown by the IP Scanner. This IP address is the one that will always be used by Pi to communicate to the router.

1: route -ne

Figure 7 Gateway IP address

Once we have noted down the gateway’s IP address, it is time to figure out the name server. This setting is stored in resolv.conf file. Use the following command to pull it up and note down the IP address of the name server.

1: cat /etc/resolv.conf]

Figure 8 Name server IP address

Now we need to modify the file “dhcpcd.conf” file which contains the network settings that go into effect once Pi boots up. Use the following command to pull up the file in editable mode in nano text editor:

1: sudo nano /etc/dhcpcd.conf]

You should be able to see some pre-existing but, commented out entries showing you the way to configure the settings in this file. We will create a new entry block at the bottom of the file. Use the following entries to configure your Pi to use a static IP address at boot time and communicate to your gateway and use the designated name server:

1: interface wlan0

2: static ip_address=”your desired IP address”

3: static routers=”your router’s IP address”

4: static domain_name_servers=”your name server’s IP adderss”

Figure 9 Configure the entries with the desired IP addresses

Once the aforementioned steps are complete, reboot your Pi for the network settings to take into effect. Use the command to reboot:

1: sudo reboot –p

Once your Pi boots up, it will acquire the configured static IP address, and you should be able to login into it, using Putty.

Figure 10 Verification of newly allocated static IP address with the help of IP Scanner

Figure 11 Using the new static IP address to SSH into Pi

Once you have gotten into Pi, pull up the raspberry pi configuration utility to configure the Pi for the following:

1. Change the password from the default “raspberry” to something that only you know. This is an essential security measure.

2. Change the setting in “Advanced Options” to allow the Pi to see and use the entire file space. By default, that is not the case.

3. Change the setting in “Advanced Options” to change the resolution of the screen to what is native to your Windows machine.

4. Enable graphical desktop at boot from “Boot Options”.

5. Enable VNC from the “Interfacing Options” setting so we can use the VNC viewer to login into Pi using the GUI capabilities of Raspbian OS.

Figure 12 Raspberry configuration utility with all the options available

Figure 13 Configuring to boot into desktop mode

Figure 14 Changing the resolution to that of my Windows machine

Once all the changes have been done, reboot Pi. Now we will be able to login into Pi using VNC viewer.

Figure 15 First boot into GUI via VNC viewer

We have accomplished all that we had set out to achieve. Now every time you will access Pi, you will be able to access it over a static IP address and login into GUI. From here-on you can go ahead and configure Pi for services that require a static IP address. Depending on your expertise level and requirements, you can completely skip the VNC part and just configure Pi to have a static IP address and operate it over SSH.

Key Takeaway:

Redis has the facility to setup replication with the help of master-slave configurations. A master can have multiple slaves and a slave can further have slaves. In this article we will focus on a simple setup having a single master and two slaves and will discuss a general usage pattern which would allow for a robust setup.

Read on:

Redis allows for configuration in two flavors:

1. With the help of a configuration file,

2. At runtime through commands.

In this article we will setup both the master and slaves with the help of configuration files, as that is something more understandable and how instances are configured in a production environment.

Next we are going to discuss some of the settings required to be implemented in the configuration files, one for each instance of Redis. The general architecture that I am trying to produce here looks something like the following:

Figure 1 Redis replication basic architecture

Explanation of the architecture:

In Redis, master instance allows for both reads and writes, and in addition to that allows for disk persistence. Slaves, by default, are read only and allow for disk persistence. Over here, since this is just an introductory article, we are going to learn how to setup the simplest master-slave configuration. A more prudent setup would allow master to engage only with memory writes, and offload disk persistence to one of the slaves, and one or more slaves will dedicatedly handle the read queries. But we will discuss this in some later article.

In order to implement the aforementioned architecture we need to create three configuration files, one for master and one for each of the two slaves.

1. Nomenclature of configuration file:

It is important to name a Redis configuration file in such a way that the purpose and some vital information contained can be gleaned off from the name itself.

We will follow the pattern: redis.hosting environment.type of instance.purpose of instance.port number.conf

So a configuration meant for a master instance would bear the name like redis.windows.master.writes.5555.conf.

2. Creation of configuration files:

Redis master: Copy the configuration file that comes pre-packaged with Redis and rename it to redis.windows.master.writes.5555.conf, where 5555 is the port that will be dedicated to master instance. You can name it differently according to the port availability on your machine. Open the configuration in a text editor and change the default port from 6379 to the one that is available in your machine.

Figure 2 Configure master instance to run on port 5555

Redis slave 1: Make a copy of the master’s configuration file and name it like redis.windows.slaveof5555.reads.5556.conf. Change the port in the file to 5556 or something that is available on your machine. Now search for the “Replication” section and un-comment the setting of “slaveof” and provide the IP address on which the master instance will be hosted and the port number. Since we will be just running all the three instances locally, the IP address should be 127.0.0.1 and the port number used in the master’s configuration file. The slave instance that we will run will take it’s configuration from this file.

Redis slave 2: Repeat the aforementioned steps, with the exception of changing the port number to 5557 or something that is available on your machine and accordingly use the same port in the name of the file. I have named mine to redis.windows.slaveof5555.reads.5557.conf.

3. Running instances

Redis master: Open a command prompt and navigate to the folder where you are having Redis executable files and execute redis-server.exe in conjunction with the name of the configuration where fro it is supposed to pick it’s configuration from.

Figure 4 Master instance receives requests for data sync from slaves

Redis slave 1: Open another command prompt and again run the redis-server.exe file, this time specifying the slave configuration file. This will enable running a slave instance connected to the master. As soon as the slave instance will come up, the master will receive a request from slave for synchronization of data. This is shown in the screenshot.

Figure 5 Slave 1 receives and syncs data with master

Redis slave 2: Repeat the aforementioned step for slave 1, but with the other configuration file meant for slave 2.

Figure 6 Slave 2

Now run another command prompt and run redis-cli.exe and connect to the master instance. Insert some keys in the master and query them, just to make sure, they have gotten stored. Now disconnect from the master instance and connect to the first slave hosted on port 5556 (or where you hosted it.) and query for the same keys, that you inserted in the master. You will find them. Similarly you will find the same information synchronized in slave 2.

Figure 7 Redis client shows that master and slaves are at parity

Conclusion:

Running replication in Redis is very simple and minimal configuration. The pattern shown here, is elementary, just to give an idea about Redis replication. There are more robust architectures that should be used in production settings.

Key Takeaway:

Learning a lot of NoSQL data-stores is easy in part because all you have to do in order to run the server, is to click on an executable file and it starts listening on a local IP address and port. Redis works the same way. But in order to run Redis in production environment, one cannot rely on a console application listening on a port. After all, there’s always a risk of someone closing the console application and shutting down the entire cache.

To remediate this, we run such products as services. Redis is no exception and in this article we will learn how to run Redis as a Windows service.

Read on:

In my last article I showed how to compile and run Redis in a 32 bit Windows environment. In this article, I am going to use the same build to run it as a Windows service.

NOTE: If you have a 64 bit processor computer, you can directly go to this link and download the binaries, in ready to use condition.

NOTE: It is always preferable to run Redis on non-default port, as that gives us the option of running an ad-hoc instance of Redis server for quick experimentation and learning. In this exercise we are going to run Redis as a service in 32 bit Windows environment and provide the runtime configuration via a configuration file.

1. Navigate to the folder with a sample configuration file. In the source code that folder will be

redis-3.0->msvs->setups->documentation->redis.windows.conf.

2. Locate the line that signifies the port on which the Redis will listen for connections. This is found in “General” category. To search, use the word “port” and change the port number to something that is available on your machine. For this exercise, change it to 6377.

3. Copy the file in the same folder as redis-server.exe. If you compiled the code that folder will be located at the following location: redis-3.0->msvs->Win32(*mine is 32 bit environment)->Release(* compile configuration). For more information on how compile Redis source code for 32 bit Windows environment, refer to my last post.

4. Open a command prompt and navigate to the location where you are storing the Redis executable named redis-server.exe and execute the following commands: