Tuesday, October 25, 2016

Long overdue update

Its been over 4 years since my last post. Partly because i had lost the credentials to the blog, partly because i was busy running  my company and my family life.
In the meanwhile a lot of things have happened and among them a new hobby. Scuba Diving

Following in the footsteps of Linus Torvalds, i started to scuba dive and have acquired an urge for diving into shipwrecks.

You can see videos of my dives in a Youtube channel i have created. Its also work in progress and there many hours of dives that i haven't found time to edit and upload.
But as old habits never die, i soon realised that there are many areas in scuba diving that embedded technology can make a difference.
My first take is to make a low cost wifi enabled Nitrox analyser, an instrument used by divers to measure the amount of oxygen in their tanks.
I though that i could use this as an opportunity to explore some of the new chips in the market like the ESP8266 that are used mainly for IoT projects and have a great user base and also happen to be dirty cheap ;)
I have spend the last few weeks reading about the principals of operation of Nitrox analysers and the ESP8266 and have started building a prototype of a DIY  Nitrox analyser.
Its going to be an Open Source Hardware and Software project and plan to use this blog as engineering diary of all the work.
So stay tune more things are coming soon.

Wednesday, November 7, 2012

Fixing asterisk addons in Ubuntu Part 2

In an older post i have shown a way to fix the following error
Module 'app_addon_sql_mysql.so' was not compiled with the same compile-time options as this version of Asterisk.

which shows up if you try to load the mysql app in asterisk so you can store the cdr in a mysql db or access mysql from within your diaplan.

There seems to be a 'nicer' way to do it, using the debian package system itself and not having to copy files around.

Here is what you need to do

First cd to a temporary directory as this procedure will download some files and generate several deb files
As root (or use sudo) issue the following commands

aptitude purge asterisk-mysql
apt-get build-dep asterisk-mysql
apt-get -b source asterisk-mysql

Once the last command finishes you will have ended up with a number of deb files.
Then issue

dpkg -i asterisk-mysql_1.6.2.0-1_i386.deb 

The version number and architecture might be different so check yours

And that's all. No copying files around

Thursday, October 25, 2012

Debugging Asterisk AGI in Python

Here is a one-liner that can literally save you days when developing a new asterisk AGI script in Python.

sys.stderr = open('/tmp/ast_agi_err.txt', 'w')

What it does is that it redirects STDERR to a file in /tmp so you can see the python console output after an un-handled  exception for example, that resulted in your agi script terminating early.
These kind of errors are not easy to find even with agi debug on, and can have you "scratching your head"  for hours if not days when debugging a new agi script

Sunday, February 5, 2012

Solving the "Re-installation failed due to different application signatures" error when debugging Android apps

If you work on an android app from multiple workstations (i.e a laptop and a desktop) you might have encountered the following error, when trying to install an app for debugging on a device that has a version of the app,that was build on the other workstation.

Re-installation failed due to different application signatures.


Normally you have to go to Seetings->Apps and remove the application manually before adb can re-install it.

To solve this you need to do two things.

Copy the file debug.keystore which resides in your home_dir/.android directory to both (or all) the machines you debug from.

and second rebuild the app, using the new key.

Now the app will be "automagically" updated on the device without having to go over a manual uninstall.

Thursday, January 26, 2012

NetMos 9845 Multiserial on Ubuntu 10.04

I have installed a NetMos 9845 Multiserial (8 port) card on my pc as i need several serial ports for a project.
Problem is Ubuntu does not recognize more than 4 ports by default.
To solve this you need to add a kernel boot parameter to instruct the kernel during boot to look for more serial devices.

With Grub2 on the machine, you can no longer edit the grub kernel parameters directly as Grub2 uses a templeting system.
So use your favorite editor and open (as root)

/etc/default/grub


there you will see a line

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"


change it to

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash 8250.nr_uarts=8"


save the file and then issue the command

sudo update-grub


for the changes to take effect

Reboot your machine and check dmesg for the number of serial ports you now have
In my case it looks like this

:/etc/grub.d$ dmesg | grep ttyS
[ 0.709951] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 0.710235] 00:07: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 0.710400] 0000:05:01.0: ttyS4 at I/O 0xc000 (irq = 19) is a 16550A
[ 0.710477] 0000:05:01.0: ttyS5 at I/O 0xc100 (irq = 19) is a 16550A
[ 0.710551] 0000:05:01.0: ttyS6 at I/O 0xc200 (irq = 19) is a 16550A
[ 0.710626] 0000:05:01.0: ttyS7 at I/O 0xc300 (irq = 19) is a 16550A
[ 0.710700] 0000:05:01.0: ttyS1 at I/O 0xc400 (irq = 19) is a 16550A
[ 0.710775] 0000:05:01.0: ttyS2 at I/O 0xc500 (irq = 19) is a 16550A


You can also check the number and setting of the serial ports using the setserial command for every port

sudo setserial /dev/ttyS7 -a
/dev/ttyS7, Line 7, UART: 16550A, Port: 0xc300, IRQ: 19
Baud_base: 115200, close_delay: 50, divisor: 0
closing_wait: 3000
Flags: spd_normal skip_test

Sunday, January 22, 2012

Getting your Android phone recognized by adb for debugging

In an older post i have shown hot to get a Samsung phone "recognized" by adb for debugging.
These were the "early days" of Android development...
Since then Android got more mature (so did adb) and now there are many companies producing Android compatible phones that developers want to use for testing/debugging their apps.
One of the main issues people have in Ubuntu is how to get the correct udev rules for their phone, as there are many sites ans post with old info or targeting specific phones.
The other problem developers face is how to use the phone in debug mode without having to run adb as root.

First thing to do is have a go at the official Android dev page
It has (most of) the instruction you need to get your phone connected and recognized.

It all boils down to creating a new udev rule file and adding something like this

SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"


Basically you have to tell udev that devices with idVendor=="0bb4" should get read/write privileges (the MODE="0666" part) for the group "plugdev"
In this example, the vendor ID 0bb4 is for HTC. The MODE assignment specifies read/write permissions, and GROUP defines which Unix group owns the device node.

It also has an extensive list of vendor id's you can use to match your device.

In case your device manufacturer is not in that list, there is an easy way to find the vendor id of your device.
Connect your device and issue

lsusb


and you will get a list of connected usb devices and their associated vendor and device id's

in my case it looks like this

Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 015: ID 12d1:1038 Huawei Technologies Co., Ltd.
Bus 001 Device 005: ID 0d8c:000c C-Media Electronics, Inc. Audio Adapter
Bus 001 Device 004: ID 05e3:0702 Genesys Logic, Inc. USB 2.0 IDE Adapter
Bus 001 Device 003: ID 0409:0050 NEC Corp.
Bus 001 Device 002: ID 03f0:4105 Hewlett-Packard ScanJet 4370
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


Locate your device (in this case it's the Huawei Technologies Co., Ltd) and the first part of the ID 12d1:1038 (i.e the 12d1) is the idVendor you need you need to put in the udev rules

Another common problem developers face is that although the udev rules are correct the phone does not connect to adb and shows up as a number of ???????????? when issuing an "adb devices" command.

The only way to get the phone connected is to start the adb with root privileges using sudo ,which in my book is a big "NoNo"
To solve this you need to set the correct user and group in the udev rules
Here is how my udev entry looks like

SUBSYSTEM=="usb", SYSFS{idVendor}=="22b8", OWNER="your-user-name" GROUP="your-group"
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0666"


To get your username and group issue the command

id

and look for the uid and gid entries
in my case they look like this

uid=1000(stelios) gid=1000(stelios)

Use the uid name in parenthesis in the OWNER and gid name in the GROUP, restart udev and now you will be able to access the phone from adb as a normal user without having to issue sudo

Sunday, June 19, 2011

Running out of inodes

Here is the problem.
Had a gazillion of small files stored in a 1TB partition and everything was fine, then we need it to move these files to a smaller partition and guess what, we could not.
What happened is that we would run out of inodes in the new smaller partition when copying the data over.

Lesson learned ?
If you create a small partition and have a ton of small files you will run out of inodes, and if you use Ext4 and have flex_bg in features, then you can't use tune2fs to increase inodes in that partition.
So then the only option is to reformat the partition and increase the number of inodes

Some would argue that you could use an other filesystem with dynamic inode allocation, but personally I would go with ext4 over any version of riserfs,xfs whatever as its way more mature.

To avoid the problem do the following when formatting:

mkfs.ext4 -I 512 /dev/foo
tune2fs -i0 -c0 -o journal_data_writeback /dev/foo

Formatting this way will give you way more inodes than a "normal" format would as it increases the inode size from the default 256.