Thursday, August 22, 2013

Installing and running Antidote IEEE 11073 library for personal healthcare device systems


When comes to personal health care device systems, a major problem which can occur is the incompatibility between different devices manufactured by different vendors. The obvious solution is the standardization. So, IEEE has defined the IEEE 11073 protocol for personal health device communication. Antidote is an open source library which implements this protocol for using in such personal health device systems. Recently I got a chance to try this implementation and find out how it works. As usual, for the sake of not forgetting the steps I followed, I'm writing down everything here.

To test Antidote with the sample Agent and Manager components, we need two computers with the bluetooth capability. So, I used my desktop PC which is connected with a USB bluetooth adapter and a laptop which has bluetooth capability. Both are running Ubuntu 12.04 version. I performed following steps on the desktop PC which is going to run the Manager component.

First of all, download Antidote 2.0 version from their website. After uncompressing it to somewhere in my Ubuntu 12.04 desktop machine, I started the installation process. When I try to install it, there were many error messages about missing packages in my platform. So, before installing Antidote, we have to issue following commands on the terminal to install those required package tools.

sudo apt-get install automake
sudo apt-get install libtool
sudo apt-get install libdbus-1-dev
sudo apt-get install libdbus-glib-1-dev
sudo apt-get install libusb-1.0-0-dev


After completing their installation, we can proceed to install Antidote. Move into the antidote-2.0.0 directory from the terminal and issue following commands.

./autogen.sh
./configure
make
sudo make install


Now Antidote installation on desktop machine is complete. I have to follow the same steps to install Antidote on the laptop but first I have to fix a little bug. After downloading Antidote to the laptop which is also running Ubuntu 12.04, I opened the file "antidote-2.0.0/src/communication/plugin/bluez/plugin_bluez.c" and commented the line number 1455 which is a call to "channel_connected" function. This is required to solve some problem occured by Agent program in Antidote. I found this solution in this mailing list discussion. After doing this little fix, then followed all the above instructions to install Antidote on the laptop computer too.

After completing the installation, we can try sample applications. In the IEEE 11073, there are two basic components which are Agent and Manager. Agent is the medical device which generate health-care data. Manager is a user device which collects the data from Agent device and provide some useful functionalities for the user such as visualizing and storing data or send to some other remote application. Manager device can be a smart-phone or a tablet, while Agent device will be a medical equipment which generate data. Agent and Manager communicates to each other via Bluetooth HDP profile. In our case, we are going to run a simple Manager program on desktop computer while the simple Agent program will run on the laptop computer(which has the bug fixed Antidote). Agent will send just dummy data to the manager to demonstrate the functionality.

First of all we must run the manager. For this purpose move in to the "antidote-2.0.0/src" directory from the terminal of desktop computer. Now issue the following command.

./healthd

Our terminal should now print some stuff and then hangout. Open a new terminal or a tab and then move into the same directory. Now issue the following command.

python test_healthd.py

That healthd program and this python script are collectively going to give us the Manager functionality. Now its time to run the Agent on the laptop computer. Before that, turn on wifi in both computers and then pair them. Now in the laptop computer, open a terminal and move into the directory "antidote-2.0.0/src" and issue the following command. Note that we have given the bluetooth address of the desktop computer running Manager as a parameter to this sample Agent program.

./sample_bt_agent 00:19:0E:11:9F:5D

After issuing this command, sample Agent start to communicate with the Manager program via bluetooth HDP with the help of IEEE 11073 protocol. On the desktop computer where the test_healthd.py script is running, you will see some output like the following which shows that Manager has received some dummy data from the Agent. When we get this output that means our Agent and Manager are working fine.

This is the very basic level of Antidote Agent and Manager for testing. There are more things for me to learn about Antidote library.

Thursday, August 8, 2013

On Screen Keyboard for Raspberry Pi

I faced a little difficulty with the limited number of USB ports available on Raspberry Pi. I wanted to test a USB bluetooth adapter on a Raspberry Pi and obviously I wanted the keyboard and mouse connected to it at the same time. So, I needed 3 USB ports but there are only 2 ports available. One option was to use a USB hub. However when using a USB hub, it seemed my bluetooth adapter is not working as expected which I guess due to low amount of current it can drag through the USB hub. Anyway, I had to look for a solution and there is a simple solution.

I searched in the web for a on-screen keyboard for Raspberry Pi and found this thread. I tried it and worked fine. I'm writing down it here in case I need to do such a thing again oneday. I installed the on-screen keyboard program by issuing the following command in the terminal.

sudo apt-get install matchbox-keyboard

After it completed the installation, we can start it by typing the following in the terminal. The reason is, there is no any launcher icon coming to the desktop or anywhere. Therefore we have to launch it from the command line.

sudo matchbox-keyboard

However its obvious that we cannot have a hardware keyboard to type that command in the terminal in each time we need a keyboard. So, we need a launcher icon. So, we have to add a desktop shortcut for launching the on-screen keyboard. For that, as instructed in that thread, I created a file in the desktop and named it keyboard.sh (name can be anything). In the file I added the following.

#!/bin/bash
matchbox-keyboard

When we double click it, this shell script should run. For that we have to set the executable permission for this file. So, from the terminal, I went to the desktop where this file is saved and issued the following command.

chmod +x keyboard.sh

 Now, when we double click on the file in the desktop, a pop up message should come asking what to do. One option should be to run the file as an executable. By selecting that option, our on-screen keyboard should launch.

Friday, July 19, 2013

Algorithms in IEEE latex paper manuscripts

While preparing a manuscript on a IEEE latex paper template, I wanted to add a pseudo code of an algorithm to it. I write it down here to avoid forgetting it and also for the benefit of somebody somewhere in this world.

First of all I should have installed the full package of latex on my Ubuntu 12.04 machine to avoid the problems of different missing packages. I do it by the following command.

sudo apt-get install texlive-full

For preparing the manuscript I used the bare_conf.tex file coming with the latex templates which can be downloaded from IEEE website here. So, following commands should be added to that file in the appropriate places to make an example algorithm.

1:  \usepackage{algpseudocode}  
2:    
3:  \begin{figure}  
4:  \begin{algorithmic}[1]  
5:  \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}  
6:  \State $r\gets a\bmod b$  
7:  \While{$r\not=0$}\Comment{We have the answer if r is 0}  
8:  \State $a\gets b$  
9:  \State $b\gets r$  
10:  \State $r\gets a\bmod b$  
11:  \EndWhile\label{euclidendwhile}  
12:  \State \textbf{return} $b$\Comment{The gcd is b}  
13:  \EndProcedure  
14:  \end{algorithmic}  
15:  \caption{Euclid's algorithm}  
16:  \label{euclid}  
17:  \end{figure}

After this if we generate the PDF file, our algorithm should appear in the paper like the following.












So, have a nice time with preparing research papers!




Monday, July 8, 2013

Transferring files via bluetooth using python scripts

In a previous post, I wrote about bluetooth programming using python. A library called BlueZ is used for that. We can do various things including client-server programs using that library. However, today I had a requirement to send or receive a file from a python script via bluetooth. As usual I started to search through the web until I find some way. Finally I came through a solution. A python library called lightblue can be used for this task. So, I'm writing down the basics I learned today about file transferring via bluetooth.

First of all, we need to download the lightblue library from the website http://lightblue.sourceforge.net/. It's scary to see the notice "This project is no longer maintained" in the website but thankfully it worked for me. I'm running Ubuntu 12.04 in my machine. Download the file "lightblue-0.4.tar.gz" and uncompress it. Now move into it from the terminal. We need to install some packages before installing the library. Issue the following commands for that purpose.

sudo apt-get install libopenobex1-dev
sudo apt-get install bluez
sudo apt-get install python-bluez libbluetooth-dev python-dev

Now, issue the following command to install the downloaded library.

sudo python setup.py install

If everything goes fine, we can start programming. Save the following program as lightblue_test.py in your machine. The variable "target_name" should contain the name of the bluetooth device we are going to connect to. "file_to_send" variable should contain the path to the file which we are going to send. 

1:  import bluetooth  
2:  import lightblue  
3:    
4:  # we should know  
5:  target_name = "SHV-E210K"  
6:  file_to_send = "/home/asanka/Downloads/20130621_151742.jpg"  
7:    
8:  # we don't know yet  
9:  obex_port = None                 
10:  target_address = None  
11:    
12:  print "searching for nearby devices..."  
13:  nearby_devices = bluetooth.discover_devices()  
14:    
15:  for bdaddr in nearby_devices:  
16:    print bluetooth.lookup_name( bdaddr )  
17:    if target_name == bluetooth.lookup_name( bdaddr ):  
18:       print "found the target device!"  
19:      target_address = bdaddr  
20:      break  
21:    
22:  print "searching for the object push service..."  
23:  services = lightblue.findservices(target_address)  
24:  for service in services:  
25:       if service[2] == "OBEX Object Push":  
26:            obex_port = service[1]       
27:            print "OK, service '", service[2], "' is in port", service[1], "!"  
28:            break  
29:    
30:  print "sending a file..."  
31:  try:  
32:       lightblue.obex.sendfile( target_address, service[1], file_to_send )  
33:       print "completed!\n"  
34:  except:  
35:       print "an error occurred while sending file\n"  

Before running this program, we need to pair the two devices. For example since I'm going to send a file from my linux PC to an Android smart-phone, I paired the PC and Android phone first. Then issue the following command to run the script.

python lightblue_test.py

Some of the basic examples are available in the lightblue library website. I referred some other websites which are listed below to solve some issues I faced during this work.

http://bayo.opadeyi.net/2009/08/bluetooth-file-transfer-with-pybluez.html

https://code.google.com/p/bluespam/

https://groups.google.com/forum/#!msg/pybluez/XrPgYLeDej4/2Uf8za3oM4cJ

I didn't move into try file receiving functionality, however I hope it is also working properly. So far, this is all I know about file transferring via bluetooth using python.

Thursday, June 27, 2013

Using rtimer in Contiki for more accurate timing

In contiki programs, the usage of rtimer is important when we need a real-time functionality. While having different kinds of timers such as ctimer and etimer, the most accurate timing can be achieved by using rtimer. Recently had such a requirement where my program should have very accurate timing. So, I learned about rtimer and used it in my program. For the sake of remembering it, I'm writing down a simple program which use rtimer.

The program shown below is a modified version of the hellow-world program which is in /contiki-2.6/examples/hello-world directory. Therefore I can run it just by issuing the following command in terminal inside that directory.

make TARGET=cooja hello-world

1:  #include "contiki.h"  
2:  #include <stdio.h>  
3:  #include "sys/rtimer.h"  
4:  #define     PERIOD_T     5*RTIMER_SECOND  
5:    
6:  static struct rtimer my_timer;  
7:    
8:  PROCESS(hello_world_process, "Hello world process");  
9:  AUTOSTART_PROCESSES(&hello_world_process);  
10:    
11:  // the function which gets called each time the rtimer triggers  
12:  static char periodic_rtimer(struct rtimer *rt, void* ptr){  
13:    uint8_t ret;  
14:    rtimer_clock_t time_now = RTIMER_NOW();  
15:    
16:    printf("Hello from rtimer!!!\n");  
17:    
18:    ret = rtimer_set(&my_timer, time_now + PERIOD_T, 1,   
19:          (void (*)(struct rtimer *, void *))periodic_rtimer, NULL);  
20:    if(ret){  
21:     printf("Error Timer: %u\n", ret);  
22:    }  
23:    return 1;  
24:  }  
25:    
26:  PROCESS_THREAD(hello_world_process, ev, data)  
27:  {  
28:   PROCESS_BEGIN();  
29:    
30:   printf("Starting the application...\n");  
31:    
32:   periodic_rtimer(&my_timer, NULL);  
33:    
34:   while(1){             
35:    PROCESS_YIELD();  
36:   }  
37:   PROCESS_END();  
38:  }  

Our program will keep printing Hello from rtimer!!! as the output.

Saturday, June 15, 2013

Bluetooth Programming On Linux



Sometimes we need to write programs that run on a PC and communicate with an external bluetooth capable device such as a smartphone. In such cases we need some good programming library which provide the necessary capabilities to access bluetooth hardware components in our PC easily. While looking for a good programming library for this task I came across a library called Bluez. It seems it has been widely used for Bluetooth programming in linux based environments. So, I decided to take a look at it.

I tried it on a Ubuntu 12.04 system connected with a USB Bluetooth adaptor. First thing is to install the necessary packages. Give following commands to install those packages.

sudo apt-get install bluez
sudo apt-get install python-bluez

After these library packages completes the installation, we will first check whether our hardware setup works. Connect the bluetooth adaptor to the USB port and turn On bluetooth. I had some problems with the default bluetooth manager that comes with Ubuntu 12.04 as I mentioned in my previous post. Therefore I use Blueman bluetooth manager to turn on/off and do anything with bluetooth on my PC.

After turning bluetooth ON, first I checked whether every thing's fine by pairing my PC with a smartphone and sending and receiving some files. Then it's time to check our Bluez libray. Put the following code in the text editor and save as bluez_test.py somewhere in the file system.

1:  import bluetooth  
2:  target_name = "SHV-E210K"  
3:  target_address = None  
4:  nearby_devices = bluetooth.discover_devices()  
5:  for bdaddr in nearby_devices:  
6:    print bluetooth.lookup_name( bdaddr )  
7:    if target_name == bluetooth.lookup_name( bdaddr ):  
8:      target_address = bdaddr  
9:      break  
10:  if target_address is not None:  
11:    print "found target bluetooth device with address ", target_address  
12:  else:  
13:    print "could not find target bluetooth device nearby"  

Please note that the target name variable is set to the name of the external bluetooth device we are going to connect. "SHV-E210K" was the name of my smartphone for bluetooth connection. According to the program, it print the names of available Bluetooth devices around and check whether our target device is available.

Now go to the location of the file from terminal and issue following command to run the python program. 

sudo python bluez_test.py













If every thing is fine, it should print that target device is found just like the one shown above. That means simply our Bluez library is capable of accessing the Bluetooth adaptor and using it. Following link will be a good reference for learning to use Bluez library.

Reference:

Enjoy with Bluetooth  programming on Linux! :)

Wednesday, June 12, 2013

Problem of sending files from Android smartphones to Ubuntu 12.04 via Bluetooth

Recently I wanted to check a USB bluetooth adaptor on a Ubuntu 12.04 system. I plugged the adapter to machine and paired it with a Galaxy S3 smart-phone. Sending files from Ubuntu machine to smart-phone works fine with the default bluetooth application that comes with Ubuntu 12.04.  However when sending files from the phone to the machine, a failure message is shown in phone and Ubuntu system does not notice any incoming file from the paired device.

I searched in web and found that many people have faced this problem. I tried the solution suggested in this link [http://askubuntu.com/questions/211006/unable-to-transfer-file-via-bluetooth-from-android-phone]. According to that, instead of using default bluetooth application, I installed Blueman Bluetooth Manager from software center. Now, sending files from Ubuntu to Android and Android to Ubuntu works fine.