Monday, 8 May 2017

How to scan for Bluetooth Smart / BLE (iBeacon) devices on Linux (Raspberry Pi)

Assuming you are using a Debian based Linux distribution like for example Ubuntu and Raspbian on the Raspberry Pi...

The following have been verified using Ubuntu 14.04 and Raspbian 'September 1014'.

Overview

The following demonstrates how to use the command line in Linux to scan for Bluetooth Smart devices (BLE, or iBeacon).

Install

Install the Linux Bluetooth stack (Bluez) for use of it's HCI (Host Controller Interface) tools.
e.g.
sudo apt-get install bluez
sudo apt-get install bluez-hcidump

Scan

Firstly start sniffing HCI traffic to and from your Bluetooth device.
e.g.
sudo hcidump -i hci0 &

Next instruct your Bluetooth device to start looking for Bluetooth Smart devices.
e.g.
sudo hcitool -i hci0 lescan --duplicates

References

http://www.linuxcommand.org/man_pages/hcidump8.html
http://linuxcommand.org/man_pages/hcitool1.html

Monday, 30 March 2015

How to install latest Oracle JDK in Ubuntu

Assuming you are connected to the internet and Ubuntu 14.04 is installed.

The following will add the Java 1.8 repos and install the latest 1.8 version.
Open a terminal an type the following
sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
Just accept the license during installation and that's it!.

You can verify installation by typing the following at the terminal
java -version
Should show something like the following (depending on the version you have installed).
java version "1.8.0_40"

How to change mysql password

Assuming you have a working mysql installation and know the current password...
The instructions here are for a Linux/Unix mysql installation, however should also work for MS Windows using mysql.exe.

Open a terminal and type the following to change the admin password
mysqladmin –u root –p'oldpassword' password 'newpassword'
Now login to mysql to change the root password
mysql –u root –p'newpassword'
At the mysql prompt type the following to change the password for the root user
UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
And repeat the following for any user where appropriate
UPDATE mysql.user SET Password=PASSWORD('userpassword') WHERE User='username';
Type quit when done.

Monday, 19 January 2015

How to install and configure mysql server on Linux

Prerequisites

Assuming you have a vanilla installation of Ubuntu 14.04.1 LTS Server... and are connected to the internet... Ensure your repository is up to date by entering the following at the terminal.
sudo apt-get update
Set a static IP address on the machine hosting the database server. You don't have to do this, however if using DHCP your IP address may change. To configure the static IP address enter the following at the terminal to open the network configuration file for editing.
sudo vi /etc/network/interfaces
And change the following
auto eth0
iface eth0 inet dhcp
to
auto eth0
iface eth0 inet static
address <ip address>
netmask <subnet mask>
gateway <gateway>
Replace <ip address> and alike with your database IP address and network details accordingly. Then save the file (:w) and quit vi (:q).

Installation

Install MySQL Server

To install mysql server simply enter the following at the terminal.
sudo apt-get install mysql-server
During the installation you will need to enter a password for the 'root' user - record / recall this.

Enable remote listening

To enable remote listening enter the following at the terminal to open the mysql configuration file for editing.
sudo vi /etc/mysql.mysql.cnf
Ensure skip-networking is commented / removed ( although this is not applicable in ubuntu 14.04.1 ) and changethe bind-address from 127.0.0.1 to <ip address>
Then save the file (:w) and quit vi (:q).

Create a new database

Firstly login to your database server.
mysql -uroot -p<password>
Then the mysql prompt will appear e.g. 'mysql>'

Next create the new database called 'mydb'
mysql>create database mydb;
Important to remember to include the trailing semi-colon, as mysql uses this to delimit the end of the instruction.
If successful you will see something like 'Query OK, 1 row affected'
Exit database server.
mysql>quit;

Create user and set permissions


Now login to the new database 'mydb' on the database server.
mysql -uroot -p<password> mydb

Enable remote user. Replace <myuser> and <passowrd> with your 'mydb' database user name and database passwords respectively.
mysql>create user '<myuser>'@'localhost' identified by '<passowrd>';
mysql>create user '<myuser>'@'%' identified by '<passowrd>';
Configure permissions.
mysql>grant all on *.* to '<myuser>'@'localhost';
mysql>grant all on *.* to '<myuser>'@'%';

That's it!.

Now restart the network service so the new IP address and new database settings take effect.
sudo /etc/init.d/networking restart
sudo service mysql restart
Or simply reboot the database server to restart the network and mysql service.
sudo reboot


Monday, 10 November 2014

How to automatically start an application on boot using a Raspberry Pi

Assuming you are using Raspbian (at the time of writing using version 'September 2014')...

Create an LSB init script in the usual place
e.g.
sudo vi /etc/init.d/myinit

Note you could just copy the provided LSB script template as shown below, but this has far to much stuff in it for our purposed. Or may be just copy it and edit...
e.g.
sudo cp /etc/init.d/skeleton /etc/init.d/myinit
sudo vi /etc/init.d/myinit

Anyhow, now edit myinit as below
#!/bin/sh

### BEGIN INIT INFO
# Provides:          myinit
# Required-Start:    networking bluetooth
# Required-Stop:      
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6 
# Short-Description: myinit 
# Description:       This file is only to start / stop myinit.
### END INIT INFO

case "$1" in
  start)
    echo "starting myinit..."
    /home/me/./myinit &
    ;;
  stop)
    echo "stopping myinit..."
    pkill myinit
    ;;
  *)
    echo "Usage: /etc/init.d/myinit {start|stop}"
    exit 1
    ;;
esac
The above example LSB script will start or stop a program called myinit located in /home/me.

Probably a good place to start for understanding this file is the Debian wiki (see reference below), however I have provided a brief summary here:
  • Provides: the name of the service this script will start / stop
  • Required-Start: names of services required to be started before this service
  • Default-Start / Default-Stop: run levels for which this script is used

Next you must make sure the permission of the script are correct (the script is executable).
e.g.
sudo chmod 755 /etc/init.d/myinit

Note the ownership should already be root if the script was created as above.

Finally to enable the script on boot, the appropriate links based on the script dependencies need to be added to the /etc/init.d sub folders.
e.g.
sudo update-rc.d myinit defaults

References

https://wiki.debian.org/LSBInitScripts
http://www.linuxfoundation.org/collaborate/workgroups/lsb
http://en.wikipedia.org/wiki/Runlevel

Monday, 8 July 2013

How to add a user to the sudoers file in Linux (to give root permissions)

Assuming you have access to the root account...
Change to root user and then open the sudoers file.
su root
vi /etc/sudoers
Scroll to line that says
root ALL=(ALL:ALL) ALL
Copy this line and change the 'root' to the desired username
Save file and exit vi
Exit root
Now your user should be able to use sudo
For example, to get the latest packages in your package manager
sudo app-get update
This was tested with Debian 7.7. Should work with other distros that use the apt package manager e.g. Ubuntu.

Thursday, 14 February 2013

How to add new user in Linux

To add a new user simply type the following
useradd newusername
To set a password for the new user do the following
passwd newusername newpassword