Thursday, 12 June 2014

Allow Remote Connections to MySQL Database on Raspberry Pi

This article shows how to set up a MySQL database to allow remote client connections. This will allow other programs on remote computers to access the database.
The first step is to allow machines to connect. This is done by removing the bind-address line from the configuration file /etc/mysql/my.cnf

Once this is done restart the database to pick up the changes
/etc/init.d/mysql restart

Once the database is restarted, we need to create database user for the remote clients. We create a user called remoteuser.
CREATE USER 'remoteuser'@'%' IDENTIFIED BY 'remoteuser';

Next, we grant all permissions to remoteuser for our database, mydatabase
GRANT ALL ON mydatabase.* TO 'remoteuser'@'%';

Finally, we set the password for the user to 'remotepassword'.
SET PASSWORD FOR 'remoteuser'@'%'=password('remotepassword');

Now external clients can connect remotely to the database and should be able to execute commands against it.

Thursday, 20 March 2014

Create a Simple Kernel Module on Ubuntu

Create a file, hello.c, that prints "Hello, world" when the module is loaded and prints "Goodbye, cruel world" when the module is unloaded
#include 
#include 
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void) {
        printk(KERN_ALERT "Hello, world\n");
        return 0;
}

static void hello_exit(void) {
        printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

Create a Makefile
ifneq ($(KERNELRELEASE),)
        obj-m := hello.o

else
        KERNELDIR ?= /lib/modules/$(shell uname -r)/build
        PWD := $(shell pwd)

default:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif

Running make will create the kernel module named hello.ko
make

load the module by using the following command
sudo insmod hello.ko
View the messages by entering the dmesg command.
dmesg

unload the module by using the following command
sudo rmmod hello

Sunday, 16 March 2014

Playing Internet Radio Stations on Raspberry Pi

Install mpd and mpc. MPD is the music player and MPC is a client to control the music player
sudo apt-get install mpc mpd

Once these are installed, you just need to have a stream to play from. I found this site useful for getting streams: http://www.listenlive.eu/index.html
Add the stream to the playlist
mpc add http://stream.hoerradar.de:80/deltaradio-alternative128
Play the station using the following command.
mpc play
Use the following command to stop the player.
mpc stop
Once the station is added, you will only need to use mpc play or mpc stop to control the player.

Add Syntax Highlighting in Vim

Syntax highlighting is extremely helpful when editing code. Vim has syntax highlighting built in to it but it is not enabled by default. To enable syntax highlighting, edit the Vim configuration file, /etc/vim/vimrc, and add "syntax on" to the file and then restart Vim.

Show line numbers in Vim

Adding line numbers in Vim is very simple. To add line numbers in Vim, edit the vim configuration file, /etc/vim/vimrc and add "set number" to the file and then restart Vim.

Connect to Wifi network with Raspberry Pi

Edit the /etc/network/interfaces file. You will need to use sudo when editing the file.

sudo vim /etc/network/interfaces


The contents of the file should have the following, where you have to substitute your_network and network_password are the ssid and the password of your network:
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0

iface wlan0 inet dhcp
        wpa-ssid "your_network"
        wpa-psk "network_password"


Restart networking to pick up the changes
sudo /etc/init.d/networking restart

Setting up VNC on Raspberry Pi

Setting up a VNC server on Raspberry Pi will allow you to access the desktop remotely, similar to Windows Remote Desktop Connection (RPC). Unlike RPC, multiple VNC sessions can be run concurrently, allowing multiple users to use the same machine at once.

To set up a VNC server on Raspberry Pi, install tightvncserver

sudo apt-get install tightvncserver

Get the resolution of your screen in Windows
Right click on the desktop and click on "Screen Resolution"

Then see what the resolution of your screen is. Mine is 1600 x 900


Start a VNC session on the Raspberry Pi with the following command
vncserver -geometry 1600x900

This will ask for a password, enter the password.

Once this is done, the session will be displayed
New 'X' desktop is raspberrypi:1

The session number is 1. You can now view the desktop remotely.

To do this you will need to download a VNC viewer. I use RealVNC http://www.realvnc.com/download/viewer/

Now you will need the IP Address of your Raspberry Pi. Use the following command to get the IP Address
ifconfig | grep inet

pi@raspberrypi ~ $ ifconfig | grep inet
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet addr:192.168.1.37  Bcast:192.168.1.255  Mask:255.255.255.0

You will need to the inet addr. There will be two addresses. 127.0.0.1 and some other address. In my case, it is 192.168.1.37

Open the VNC viewer and type in the IP Address, colon, VNC session in the VNC Server field. <ipaddr>:<sessionnum>
Select the "Let VNC Server choose" option for Encryption and then click "Connect".



A warning message will be shown saying the connection is unencrypted.  Click the "Do not warn me about this for <vnc session> again" and click the continue button.


You will then be prompted for your password. Enter the password that you used when you installed tightnvc and click OK.

You will now be able to use the desktop