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

Sunday, 7 October 2012

UML - class symbol

  • A Class is shown as a rectangle and can have three regions

  • The same class may be simply, and is typically, shown as a single region or empty set of regions

  • It is common to show only significant detail and often some or all methods and attributes are omitted
  • The exception to this are interfaces where it is necessary to detail all methods (obviously a true interface has no attributes)
Copyright © 2012 www.deanwarrenuk.com 

Friday, 5 October 2012

How to create a symbolic-link (hard-link) in Windows

Windows XP/Windows Server 2003

By default Windows XP and Windows Server 2003 do not have any utilities to make a symbolic-link. Use either linkd or junction.

  1. Download linkd from here
    http://www.microsoft.com/en-us/download/details.aspx?id=17657
  2. From the command-line type the following to create, for example, a symbolic-link called link in c:\ to the folder c:\folder.
    linkd c:\link c:\folder


    or
  3. 
    
  4. Download junction from here
    http://technet.microsoft.com/en-us/sysinternals/bb896768
  5. From the command-line type the following to create, for example, a symbolic-link called link in c:\ to the folder c:\folder.
    junction -r c:\link c:\folder

Windows Server 2008/Vista/Windows 7

Use mklink.
  1. From the command-line type the following to create, for example, a symbolic-link called link in c:\ to the folder c:\folder.
    mklink c:\link c:\folder

References

http://www.microsoft.com/en-us/download/details.aspx?id=17657
http://technet.microsoft.com/en-us/sysinternals/bb896768
http://support.microsoft.com/?kbid=205524


Tuesday, 25 September 2012

How to check for an empty array in vbscript

In the following example we exit the script with an exit code of one if myArray has zero elements i.e. myArray is empty.
If UBound(myArray) = 0 Then WScript.Quit(1)

References

http://msdn.microsoft.com/en-us/library/fhx59d0t(v=vs.84).aspx

Tuesday, 18 September 2012

UML - example Class diagram

  • Here is an example of a class diagram showing a simplified model of a hotel system. 
  • A Hotel contains one-to-many rooms. A room is either a double or single room. A Hotel can have many Customers. A customer can book many rooms.
Copyright © 2012 www.deanwarrenuk.com 

Monday, 17 September 2012

UML - what is a Class diagram

  • A class diagram describes the OO class construct and it’s relationship(s) to other classes 
  • Symbols includes: Class and Association(s) 

Gotcha

Often Class diagrams are inappropriately crammed with lots of detail for each Class and omit useful description of Class relationships

Tip

Leave the detail of attributes and methods to the implementation unless absolutely necessary, always describe relationships unless implied by the association

Copyright © 2012 www.deanwarrenuk.com 

Thursday, 13 September 2012

UML - what are the common diagrams

  • The diagrams typically fall in one of three categories: Structure, Behaviour or Requirements 
  • Structure includes: Class, Package, Component and Deployment diagrams 
  • Behaviour includes: Activity, State-chart, Sequence and Collaboration diagrams 
  • Requirements includes: Use Case 
  • There are many other diagrams…
Copyright © 2012 www.deanwarrenuk.com

Thursday, 6 September 2012

How to recursively walk a folder in C++ / Boost

Walking a folder structure in most languages is typically achieved using a recursive function or loop of some kind (although this behaviour may be wrapped and hidden from the programmer) - for C++ this is not any different. However the walking isn't the problem, rather writing a platform generic (Unix/Linux/Windows) version has been a little tricky due to C++ having no standardised support for folder/directory handling across different platforms (of course file handling is standardised.).
Boost makes this simple using it's filesystem library iterators and a very simple loop construct of your choice.

Example

This example shows a recursive walk of a folder structure printing the full path of all folders and files found.
#include <boost/filesystem.hpp>
#include <iostream>

void main()
{
    boost::filesystem::path path = boost::filesystem::current_path();
    boost::filesystem::recursive_directory_iterator itr(path);
    while (itr != boost::filesystem::recursive_directory_iterator())
    {
        std::cout << itr->path().string() << std::endl;
        ++itr;
    }
}
  1. Firstly we assume you have built the Boost filesystem library and it and it's header are appropriately defined in your project e.g. link to the library and include the header file.
  2. Next you create the iterator recursive_directory_iterator. We have loaded our iterator example with the current working directory.
  3. Finally you loop until you run out of iterators.

References

http://www.boost.org/


Wednesday, 5 September 2012

How to load a Linux image to an SD card for a Raspberry Pi using Windows

Download

Get you Linux image from here:
http://www.raspberrypi.org/downloads

Get an image utility here:
https://launchpad.net/win32-image-writer/+download
At the time of writing version 0.6 is the current/stable release.

Upload

  1. Extract the archive to a location of your choice eg. c:\diskimager.
  2. Navigate to c:\diskimager and double-click on c:\diskimager\Win32DiskImager.exe. The Win32 Disk Imager window will appear.
  3. From the Win32 Disk Imager window enter the full absolute path of the disk image file in the Image File text-box.
  4. From the Win32 Disk Imager window select the SD card from the Device comb-box.
  5. From the Win32 Disk Imager window click on the Write button. The image file will be written to the SD card. This may take a while... (observe the progress bar)
  6. On successful completion a dialog will appear indicating this.

References

Tuesday, 4 September 2012

How to trace executable dependencies in Windows

Download

Either download Dependency Walker from here:
http://www.dependencywalker.com/
At the time of writing version 2.2 is the current/stable release.

Or

Download Process Monitor from here:
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
At the time of writing version 3.03 is the current/stable release.

Dependency Walker

Start-up Dependencies
To trace the modules loaded when an executable is first started do the following:

  1. Extract the archive to a location of your choice eg. c:\depends.
  2. Navigate to c:\depends and double-click on c:\depends\depends.exe.  Dependency Walker will start.
  3. From the Dependency Walker menu click File->Open. The Open dialog will appear.
  4. From the Open dialog navigate to the executable that you wish to trace, select it and click on the Open button. Dependency Walker will show a list of modules loading and indicate any issues/errors.
  5. See the Dependency Walker help to understand the icons used and error messages given. For a description of the icons navigate the menu and select Help->Help Topics and this Understanding the Module Session->Module List View.
Usage Scenario Dependencies
To trace the modules loaded given a specific usage of an executable, follow the Start-up Dependencies as listed above and then do the following:

  1. From the Dependency Walker menu click Profile->Start Profiling... and the Profile Module dialog will appear.
  2. From the Profile Module dialog click on the Browse button and navigation to the executable that you wish to trace (as previously). Add any program arguments and configure the options as required. Click on the OK button to trace and close the dialog.
  3. Dependency Walker will show a list of modules loading and indicate any issues/errors.

Process Monitor

Start-up/Usage Dependencies
On starting Process Monitor it will display a list of all current running processes. We will configure Process Monitor to be used as with Dependency Walker.

  1. Extract the archive to a location of your choice eg. c:\procmon.
  2. Navigate to c:\ procmon and double-click on c:\procmon\procmon.exe. Process Monitor will start.
  3. From the Process Monitor menu click Filter->Filter... and the Process Monitor Filter dialog will appear.
  4. From the Process Monitor Filter dialog select the combo-box current displaying Architecture and select Process Name.
  5. From the Process Monitor Filter dialog enter the process name of the executable you want to trace in the third (empty) combo-box right of the Process Name. Click the Add button.
  6. From the Process Monitor Filter dialog deselect all other items in the Column column with the exception of the Process whose Value you just added. Click on the OK button and  Process Monitor Filter dialog will close.
  7. From the Process Monitor menu click Edit->Clear Display.
  8. Now start your executable and observe the trace (profiling) output in the  Process Monitor window.
  9. To start/stop the trace click on the menu item File->Capture i.
  10. To view the modules/files accessed click on the menu item Tools->File Summary... and the File Summary dialog will appear - see the Path column.

References

http://www.dependencywalker.com/
http://technet.microsoft.com/en-us/sysinternals/


Sunday, 2 September 2012

leJOS NXJ - basic motor control

The NXT can control up to three motors connected to interfaces A, B and/or C. The Motor class provides three static instances - one for each each motor interface - namely A, B and C. To rotate the motor either forward or backwards (relative to the rear of the motor - where the cable is attached) call the appropriate method forward() or backward() on the motor instance accordingly.

For example to rotate motor A forward do the following.
Motor.A.forward();
To rotate motor B backwards do the following.
Motor.B.backward();
Following an instruction to rotate forward or backwards the motors will continue to rotate indefinitely.
To stop motor C do the following.
Motor.C.stop();
To use the Motor classes import the following package.
import lejos.Motor

References

http://lejos.sourceforge.net/nxt/nxj/api/index.html

Thursday, 30 August 2012

UML - why use it

  • UML is an industry standard and it is likely something described in UML is more widely understood than something described in other or bespoke diagrams. 
  • A design should almost always have some documentation. This can help communicate ideas during development and help facilitate successful maintenance.
Copyright © 2012 www.deanwarrenuk.com

Monday, 27 August 2012

UML - what it is and what it is not

  • UML is a collection of diagrams, symbols, words and rules that can be used for describing the structure and behavior of things
  • UML is typically used with OO software analysis and design, but can be used for non OO software design, system design and advanced database design (EER)
  • UML is not a process, procedure or methodology for designing stuff
  • UML is extensible
Copyright © 2012 www.deanwarrenuk.com

Thursday, 23 August 2012

How to configure/install Boost C++ libraries

Windows

Using Windows Server 2003 r2 with SP2. 1
  1. Download Boost from, fro example, here http://sourceforge.net/projects/boost/files/boost/1.50.0/ and unzip to an appropriate location eg. C:\boost. 2, 3
  2. To build the Boost libraries first you have to build the tool that builds Boost the boost.build engine bjam. From the command line go to the boost folder eg. C:\boost and execute bootstrap.
    When successfully complete the command line should look something like as follows:
  3. Now we can build the Boost libraries. From the command line go to the boost folder eg. C:\boost and execute b2.
    The  boost.build engine will now build all the libraries, this will take some time...
That is it, boost is built and ready for development use.

Notes

  1. These instructions should be the same for all versions of Windows from XP 32bit to Windows 7 64bit.
  2. If you have an SVN client installed  just open the command line and type the following:
    svn co http://svn.boost.org/svn/boost/tags/release/Boost_1_50_0/ c:\boost
  3. Where 1.50.0 was the latest stable release of boost at the time of writing and C:\boost is the chosen destination folder.

References

http://www.boost.org