Thursday, November 7, 2013

Lowcost Bluetooth Roomba adaptor (rootooth)

Materials: 

- 1 x 0.1mF Capacitor
- 1 x 0.33mF Capacitor (0.1mF Capacitor works too)
- 1 x +5V Fixed-Voltage Regulator 7805
- 1 x Bluetooth - TTL Bluetooth Module (Serial UART) - 115200 8N1 capable
- 1 x UST to TTL adaptor (could be optional)
- 1 x Roomba 5xx (I believe that works with other models too but I didn't test it)
- Welder and utilities


Introduction:

I have an iRobot Roomba 530 that I found for free in craigslist (broken battery) some weeks ago, this model of Roomba has no option to schedule vacuum jobs, so you have to press START button each time that you want to vacuum the floor, it's not a big deal, but I knew that you could do that through serial port. After reading about it in the Internet, I realized that there is a Bluetooth module called rootooth to do that wireless.
Rootooth is expensive and big and I did't want to have something attached to my roomba, then I decided to do it by myself.


Bluetooth module:

To substitute the iRobot Bluetooth module (Rootooth) you need a Bluetooth to TTL module, I found it in Ebay (there are a lot) and it costs me less than $15, it has to have these features:
- 5V VCC input
- AT mode
- 115200 8N1 capable
- RX, TX, VCC and GND pins



Steps:

 First, we have to configure our Bluetooth module to work in 115200 8N1 if this isn't the default configuration. For that, use a USB to TTL adapter connected to your Bluetooth module and follow the manufacturer steps to change it.


*picture of the USB-TTL adapter

In my module, it was in 9600 8N1 by default, so I used putty with this config and "AT+BAUD8" to change it as described by manufacturer.

Once our Bluetooth module is configured in the same way as our roomba, it's time to create our power adapter. Since the roomba works with more than 5V, we need something to convert this voltage to 5V, then I used a 7805 regulator that I bought in Radioshark and two capacitors, you have to create this schema:
INPUT and GND will be connected to out roomba, OUTPUT and GND to VCC and GND to our Bluetooth module.

Now is time to open the roomba to access to the board, we could connect it directly to roomba's port, but I don't like this idea, since I prefer to have it inside of the roomba. Anyway, if you want to use the port, this is the schema:
* Remember that TX and RX have to be switched and Vpwr and GND have to be connected to the power adapter.


   But if you are a perfectionist, you can follow any how-to to open the roomba, after that,  look for the TTL port on the roomba board, and try to localize where you have to connect your Bluetooth module:



It was easy using a multimeter in "continuity" mode. This image above if for my 530, it will be safe if you test it for your roomba model, just in case.
Using a welder, we have to connect GND to GND in our power adapter, VCC to input of our power adapter, TX to RX of our bluetooth and RX to our TX of our bluetooth device, you have to be sure that you use enough cord to put your bluetooth module with the power adapter in the hole where the charger plug is (see next picture).


It's time to check that it works before close the Roomba, so now you need a computer with bluetooth. Connect your Roomba's battery and link you computer to your bluetooth module as a normal bluetooth device, then use a terminal software (as putty or minicom) to connect to the bluetooth/TTL that you just created (it depends of your OS). If you are using Linux, follow this steps:

   # rfcomm connect 0 xx:xx:xx:xx:xx:xx #your bluetooth module mac
   # minicom -b 115200 -D /dev/rfcomm0

Now if you push "STAR" button in your roomba some lines have to appear in you screen, it not, try to check that all connections are working fine, if it still doesn't work, try to swap TX and RX connections, it worked for me.

It's time to close your roomba and if you have an Android phone, try "Roomba touch drive" app (https://play.google.com/store/apps/details?id=com.fl&hl=en) and enjoy!
If you don't have an Android phone, there are a lot of different programs for windows and maybe for mac/IOS that you can try.


References:
http://hackingroomba.com/projects/build-a-roomba-bluetooth-adapter/
http://www.securitybydefault.com/2011/01/hacking-roomba.html


Acknowledgments:
- G. Giribet, without your wheel, my roomba would still limp...
- M. Leon, your help with the power adapter was essential.


Friday, March 1, 2013

Import data file to MySql Database


Introduction:

We are trying to add data from a text file (snp file, dep file, etc) to a MySql table but we want to be sure if the import process was successfully before save or discard this data.

Steps:

#From the mysql shell, we start the transaction:

mysql> BEGIN;

#We use "load data infile" to load the data, we can define in which column is going each file column.
mysql> LOAD DATA INFILE '[PATH_OF_THE_FILE]'  INTO TABLE [TABLE] (column2,column3,column5,column8);
Query OK, 69144 rows affected, 1 warning (0.71 sec)
Records: 69144  Deleted: 0  Skipped: 0  Warnings: 1
#After that, we can use show warnings to decide if we want this data or not
mysql> show warnings;
+---------+------+---------------------------------------------+
| Level   | Code | Message                                     |
+---------+------+---------------------------------------------+
| Warning | 1364 | Field 'column1' doesn't have a default value |
+---------+------+---------------------------------------------+
1 row in set (0.00 sec)

#Save data or discard
mysql> commit; #Save
mysql> rollback; #Discard

REFERENCES:

http://dev.mysql.com/doc/refman/5.0/es/load-data.html
http://dev.mysql.com/doc/refman/5.0/en/commit.html

Friday, July 6, 2012

Sort by more than one column Bash

Problem:

Sort this data using first and second column. 
chr10   10010946
chr1    10010947
chr1    10010948
chr1    10010949
chr1    10010950
chr1    10110951
chr10   10010952
chr10   10010953
chr10   10010954
chr10   10010955
chr10   10010956
chr10   10010957
chr10   10010941
chr10   1001942
chr10   1001943
chr10   1001944
chr10   1001945
chr10   1001958
chr10   1001959
chr10   10010960
chr10   10010961
chr10   10010962
chr10   10010963
chr10   10010964
chr10   10010965
chr10   10010966
chr10   10010967
chr10   10010968

Introduction:
If we use only #sort command (sort [file]):
chr10   10010941
chr10   10010946
chr10   10010952
chr10   10010953
chr10   10010954
chr10   10010955
chr10   10010956
chr10   10010957
chr10   10010960
chr10   10010961
chr10   10010962
chr10   10010963
chr10   10010964
chr10   10010965
chr10   10010966
chr10   10010967
chr10   10010968
chr10   1001942
chr10   1001943
chr10   1001944
chr10   1001945
chr10   1001958
chr10   1001959
chr1    10010947
chr1    10010948
chr1    10010949
chr1    10010950
chr1    10110951
If we use #sort with the second column as a number (sort -k2n [file]):
chr10   1001942
chr10   1001943
chr10   1001944
chr10   1001945
chr10   1001958
chr10   1001959
chr10   10010941
chr10   10010946
chr1    10010947
chr1    10010948
chr1    10010949
chr1    10010950
chr10   10010952
chr10   10010953
chr10   10010954
chr10   10010955
chr10   10010956
chr10   10010957
chr10   10010960
chr10   10010961
chr10   10010962
chr10   10010963
chr10   10010964
chr10   10010965
chr10   10010966
chr10   10010967
chr10   10010968
chr1    10110951
 Solution:
We need to sort with both columns (sort -k1,1 -k2,2n [file])
"Sort from first column to first column with default method and then, sort from second column to second columns with numeric order"
chr1    10010947
chr1    10010948
chr1    10010949
chr1    10010950
chr1    10110951
chr10   1001942
chr10   1001943
chr10   1001944
chr10   1001945
chr10   1001958
chr10   1001959
chr10   10010941
chr10   10010946
chr10   10010952
chr10   10010953
chr10   10010954
chr10   10010955
chr10   10010956
chr10   10010957
chr10   10010960
chr10   10010961
chr10   10010962
chr10   10010963
chr10   10010964
chr10   10010965
chr10   10010966
chr10   10010967
chr10   10010968

Monday, June 25, 2012

Install UCSC Genome Browser

Introduction:

How to install a minimal installation of UCSC Genome Browser on Centos6 x86_64 with in a custom directory.

Steps:

- Install apache and mysql:
 yum install httpd mysql-server mysql
- Start services:
service httpd start
service mysqld start
chkconfig httpd on
chkconfig mysqld oni
- Configure Apache:
cd /var/www
mkdir html
mkdir cgi-bin
Create a config file like: /etc/httpd/conf.d/ucsc_genomebrowser.conf:
#
# UCSC GENOME BROWSER
#

<Directory "/var/www/ucsc-genomebrowser/html">
     Order Allow,Deny
     Allow from all
</Directory>

<Directory "/var/www/ucsc-genomebrowser/cgi-bin">
     AllowOverride None
     Options None
     Order allow,deny
     Allow from all
</Directory>

XBitHack on
<Directory "/var/www/ucsc-genomebrowser/html">
     Options +Includes
</Directory>

ScriptAlias /genomebrowser/cgi-bin /var/www/ucsc-genomebrowser/cgi-bin
Alias /genomebrowser /var/www/ucsc-genomebrowser/html
Alias /style /var/www/ucsc-genomebrowser/html/style
Reload Apache: service httpd restart
- Preparing the system:
Execute and add to /etc/profile:
    export WEBROOT=/var/www/ucsc-genomebrowser/html
    export CGI_BIN=/var/www/ucsc-genomebrowser/cgi-bin
    export MYSQLDATA=/var/lib/mysql
cd /usr/local/
mkdir apache
cd apache/
ln -s /var/www/ucsc-genomebrowser/html/ htdocs
yum install openssl
cd /usr/lib64
ln -s libcrypto.so.10 libcrypto.so.6
ln -s libssl.so.10 libssl.so.6
- Getting web files:
rsync -avzP rsync://hgdownload.cse.ucsc.edu/cgi-bin/ $CGI_BIN
rsync -avzP rsync://hgdownload.cse.ucsc.edu/htdocs/ $WEBROOT/
mkdir  /gbdb
cd /gbdb
mkdir -p hg19/nib
cd hg19/nib
rsync -avzP --delete --max-delete=20 rsync://hgdownload.cse.ucsc.edu/gbdb/hg19/hg19.2bit .
cd  /gbdb/hg19/
ln -s nib/hg19.2bit
chcon -R unconfined_u:object_r:httpd_sys_script_exec_t:s0 /gbdb
chown -R apache.apache /gbdb/

- Set up the Database:
  - hgcentral DB:
wget http://hgdownload.cse.ucsc.edu/admin/hgcentral.sql
mysql> create database hgcentral
mysql --[mysqlaccessoptions] hgcentral < hgcentral.sql
   - hgFixed DB:
mysql --[mysqlaccessoptions] -e "create database hgFixed"
  - hg19 DB:
mysql> CREATE DATABASE hg19
cd /var/lib/mysql/hg19
rsync -avP rsync://hgdownload.cse.ucsc.edu/mysql/hg19/grp* .
rsync -avP rsync://hgdownload.cse.ucsc.edu/mysql/hg19/trackDb* .
rsync -avP rsync://hgdownload.cse.ucsc.edu/mysql/hg19/hgFindSpec* .
rsync -avP rsync://hgdownload.cse.ucsc.edu/mysql/hg19/chromInfo* .
rsync -avP rsync://hgdownload.cse.ucsc.edu/mysql/hg19/gold* .
rsync -avP rsync://hgdownload.cse.ucsc.edu/mysql/hg19/gap* .

- BD Permisions:

GRANT SELECT, CREATE TEMPORARY TABLES
  ON hgcentral.*
  TO readonly@localhost
  IDENTIFIED BY 'access';

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER
  ON hgcentral.*
  TO readwrite@localhost
  IDENTIFIED BY 'update';
 
GRANT SELECT, CREATE TEMPORARY TABLES
  ON hg19.*
  TO readonly@localhost
  IDENTIFIED BY 'access';

GRANT SELECT, CREATE TEMPORARY TABLES
  ON hgFixed.*
  TO readonly@localhost
  IDENTIFIED BY 'access';

 - Getting config file:
wget http://genome-test.cse.ucsc.edu/~kent/src/unzipped/product/ex.hg.conf
mv ex.hg.conf /var/www/ucsc-genomebrowser/cgi-bin/hg.conf
chmod 600 /var/www/ucsc-genomebrowser/cgi-bin/hg.conf
chown apache.apache /var/www/ucsc-genomebrowser/cgi-bin/hg.conf
chcon unconfined_u:object_r:httpd_sys_script_exec_t:s0 /var/www/ucsc-genomebrowser/cgi-bin/hg.conf

- Configuring:
Change users and passwords (readonly/access and readwrite/update)
[...]
defaultGenome=hg19
[...]

-Trash:
mkdir /var/www/ucsc-genomebrowser/trash
chown apache:apache /var/www/ucsc-genomebrowser/trash


REFERENCES:

http://genome.ucsc.edu/admin/mirror.html
http://bergmanlab.smith.man.ac.uk/?p=1111
http://genomewiki.ucsc.edu/index.php/Browser_Installation
http://genomewiki.ucsc.edu/index.php/Minimal_Browser_Installation

Thursday, June 21, 2012

Permission denied Apache in Centos 6

When you have a "Permission denied" error but the permissions of the files are correct:

File: /var/log/httpd/error_log
Couldn't open ./hg.conf , Permission denied, referer: http://127.0.0.1/
# ll hg.conf
-rw-------. 1 apache root 13659 Jun 21 19:12 hg.conf

Try to see more information with ls -laZ
# ls -laZ hg.conf
-rw-------. apache root unconfined_u:object_r:admin_home_t:s0 hg.conf
And try to change with:
# chcon unconfined_u:object_r:httpd_sys_script_exec_t:s0 hg.conf

And...... IT WORKS!


Monday, June 11, 2012

Exchange mail + contacts + calendar Thunderbird

Introduction:

Configure Thunderbird as a Exchange client using DavMail.

Steps:

Common:
- Install DavMail (http://davmail.sourceforge.net/)
    - DavMail is a gateway mailClient <-> MS Exchange
    - Configure it with:
        * Main tab -> OWA (Exchange) URL: https://YOUR_WEBMAIL_URL/
        * Advanced tab -> Default windows domain: YOUR_DOMAIN

Mail:
- Configure a new email account in thunderbird with:
    - Protocol: IMAP
    - Server: localhost
    - Port: 1143
    - User: YOUR USER WITHOUT DOMAIN
    - Pass: YOUR PASS
    - SMTP server: localhost
    - SMTP port: 1025

Contacts:
- Go to your Thunderbird Address Book
    - File -> New -> LDAP Directory...
        - General Tab:
            * Name: EXCHANGE
            * Hostname: localhost
            * Base DN: ou=people
            * Port number: 1389
            * Bind DN: YOUR USER WITHOUT DOMAIN
        - Advanced Tab:
            * Search filter: (objectclass=*)

Calendar:
- Install Lightning Extension (from tools -> Add-ons menu)
- Go to Calendar Tab (Events and Tasks -> Calendar)
- Right button on left column (down of the last calendar) -> New Calendar
    - Select On the Network
        * Format: CalDav
        * Location: http://localhost:1080/users/MAIL_ACCOUNT/calendar
    - Next
        * Calendar Name: EXCHANGE
    - Next
        * User: YOUR USER WITHOUT DOMAIN
        * Pass: YOUT PASSWORD

Conclusions:

With this configuration, you can use all capabilities of a MS Exchange server in Linux an OSX systems.

REFERENCES:

http://davmail.sourceforge.net/
http://davmail.sourceforge.net/thunderbirdcalendarsetup.html

Wednesday, June 6, 2012

Apace mod_python with CentOS 6

Introduction:

How to install mod_python.so CentOS 6 

We gonna use the svn trunk source code because the last stable version at http://archive.apache.org/dist/httpd/modpython/ doesn't compile (see ref. 3).

Steps:

Install dependences:
yum install gcc
yum install httpd-devel
yum install python-devel
yum install flex
yum install svn
Download source code with svn:
svn co https://svn.apache.org/repos/asf/quetzalcoatl/mod_python/trunk
cd trunk