Using 16×2 LCD display with i2c controller in Arduino

If you are planning to use a 16×2 LCD display with i2c controller in Arduino, check out this page for the three general types of LCD i2c controller, and the settings for each one of them:

https://arduino-info.wikispaces.com/LCD-Blue-I2C

Also, some controllers will have brightness controllers which can be adjusted using a small screwdriver. If the LCD blinks as per the code in the above site, but you cannot see the characters, it most probably is a brightness issue.

Cheers

Advertisement

Convert SeaTools iso file into USB bootable on Mac

Seagate SeaTools for DOS is a free hard drive testing software that runs independent from your operating system. Seagate provide a iso file which needs to be burned to a CD. Considering that CD/DVD drives are fast disappearing, and most computers these days support booting of a USB drive, it makes life easier if the the iso get converted into USB bootable. It is actually easy to do it on a Mac using the following steps:

a) Download Seatools for DOS from Seagate site (http://www.seagate.com/support/downloads/seatools/)

b) Open the iso file downloaded. Simple double clicking should mount the file on your desktop. Open the mounted folder, and extract the SeaTools.ima to your desktop.

c) Rename SeaTools.ima to SeaTools.img (Accept the warning dialog box)

d) Insert a USB drive that you will use. Note that any data on this drive will be completely erased.

e) Start your terminal window and find the USB drive identifier:

diskutil list

. Make sure that you get the correct disk identifier. In my case it was /dev/disk1.

/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            249.4 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
   4:       Microsoft Basic Data BOOTCAMP                250.0 GB   disk0s4
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *16.0 GB    disk1
   1:             Windows_FAT_32 KINGSTON                16.0 GB    disk1s1

f) Unmount the usb disk folder using the following commands in your terminal window:

diskutil unmountDisk /dev/disk1

g) Copy the contents of the SeaTools.img file to USB drive

sudo dd if=Desktop/SeaTools.img of=/dev/disk1

That’s it. Your USB drive will now boot to SeaTools. One thing that I have observed with the SeaTools is that if you have set the drives to be discovered through AHCI mode in your bios, it might not always detect the drives. It is better to change the drive detection to IDE for it to work reliably.

For those looking to use the same procedure on a Windows machine, this link should help your out:
http://blog.nowherelan.com/2013/04/04/boot-seatools-off-of-a-usb-drive/ . For Linux and BSD, the procedure should essentially remain the same as Mac in principle, although the disk identifier & unmounting commands might be different. dd should work on all.

Creating custom pkgng repository for FreeBSD

pkg is a utility for installing binary packages in FreeBSD. But to install non-default options not selected by the packager/maintainer across multiple servers, use the ports to roll out custom packages. Creating custom package is very easy. There are only small changes compared to creating packages for the old pkg_* toolset.

mkdir -p /usr/ports/packages/All
make package-recursive install

Note that install keyword has been used, because new pkgng does not install the main port while creating the package. It will install all dependent ports though. Once packages are created, copy all of them to a staging directory:

cp /usr/ports/packages/All/* .

Alternatively, if the ports are already installed, create packages using:

pkg create -a

This will create packages for all installed ports in the current directory.

Once all the packages are in current directory, run pkg repo command to create repo files:

pkg repo .

Current directory now contains all the files to host custom repository :). Move it to some publicly accessible place which is reachable by target computers. Use of directory under a web server makes it easier. For more control over repository creation and how packages are created, see poudriere and tinderbox

On the target computers to use this repository, make a few changes. Disable the base FreeBSD repository:

mkdir -p /usr/local/etc/pkg/repos
echo "FreeBSD: { enabled: no }" > /usr/local/etc/pkg/repos/FreeBSD.conf

Now make the new repository active

echo 'REPONAME: { url: "http://REPO_URL"}' > /usr/local/etc/pkg/repos/REPONAME.conf
pkg upgrade

There are tons of options for the conf files, and also how to use multiple repositories with priorities, but those are beyond the scope this article. Consult man pages for pkg-repository and pkg.conf for more details.

Custom repository is now ready for use.

Please note that anything related to PACKAGESITE is no longer valid for the new versions of pkgng .

Installing Subversion server on FreeBSD using svnserve

There are lots of guides on net that help you out on installing subversion server on FreeBSD, but most of them describe installing subversion server with Apache and mod_dav. Apache is used to access your subversion repository using http or https. But this becomes a problem if you are using one of the alternate servers (nginx ot lighttpd), or would not like to install any web server. In that case, it is much easier to use “svnserve” daemon to access the repository. This is how I went about doing it after updating my ports tree:

cd /usr/ports/devel/subversion; make -DBATCH all install clean
or alternatively use the new pkgng ( to install binaries.Search for the right package using
pkg search subversion
and then install the latest version(1.8.5 as on date) available using
pkg install subversion-1.8.5
Using binary packages is far easier and faster, but you loose the flexibility of ports. You can also install subversion through the older pkg_add tools if it’s still supported in your release.

Once you have installed the subversion through either of the methods, create a user for svn:
pw groupadd svn; pw adduser svn -g svn -s /usr/sbin/nologin
Create a home directory for all repository:
mkdir -p /usr/home/svn/repos; chown -R svn:svn /usr/home/svn
Add entries in /etc/rc.conf to run svnserve daemon on startup
echo 'svnserve_enable="YES"' >> /etc/rc.conf ; echo 'svnserve_data="/usr/home/svn/repos"' >> /etc/rc.conf
Now start the svnserve daemon either by
service svnserve start
or by
/usr/local/etc/rc.d/svnserve start
Check if svnserve is running by
sockstat |grep svnserve
If it is running on port 3690, you have successfully installed subversion and is accessible through the svnserve daemon.

Now create the repositories in svn. Remember, each repository has its own configuration and access control. Once you create a repository using
svnadmin create /usr/home/svn/repos/myfirstrepo
the newly created repository is now located at /usr/home/svn/repos/myfirstrepo. You will need to modify three files for the repository to be accessible for you. Under /usr/home/svn/repos/myfirstrepo/conf, you will find authz, passwd & svnserve.conf files. In passwd file, create username and password in the following syntax:
username = password. Place each user in a new line. In the authz file, the simplest way is to set the access control for the repository itself, although there are a lot of combinations available for access control. I simply use this:
[/]
username = rw

You can use r for read access, w for write access and blank for no access. For the svnserve.conf file, under the [general] section, set the following three lines:
anon-access = none
auth-access = read
auth-access = write

This should replace any existing similar values.

You should now be ready to access the repository from a svn client. Just remember that you need to access the repository using svn:///myfirstrepo scheme. Hope it works out for you as well.

Cheers

Installing Freeswitch on FreeBSD 9

[This is a work in progress article. There can be changes or additions to this article in the near future.]

Freeswitch port on Freebsd is at 1.0.6 while the current version of Freeswitch is on 1.3.x . The devel port for Freeswitch does not compile on FreeBSD 9.1 at the moment. Instructions at Freeswitch site does not work cleanly for the current version of FreeBSD (9.1). It requires tweaking in the script/code to get it working correctly. Also, make sure that you have “source” selected while installing FreeBSD, otherwise DAHDI kernel module with fail to build.

First step is to install all the required dependencies using ports. FreeBSD 9.1 does not have pre-built packages because of the security breach found during the end quarter of 2012.

# portsnap fetch extract
# mkdir -p /usr/ports/packages/All

The reason I have created a packages/All directory is because I like to keep all the packages pre-built with me to save time on subsequent installations. Most of the ports can be left to their default configurations. One port that needs extra settings is Perl. In the config dialog box for perl, make sure to select multithreading and mulitplicity if you need mod_perl module enabled in Freeswitch.

# cd /usr/ports/lang/perl5.14
# make config
# make config-recursive
# make package-recursive clean

Install all the other ports in batch mode. If you are not interested in making packages, you can instead use

make all install clean

instead in the above command as well as all the commands that follow. I also needed access to Postgresql database from Freeswitch/mod_perl, for which certain modules are required to be installed. These are optional if you do not need mod_perl and/or Postgresql connectivity.

# cd /usr/ports/databases/postgresql92-client; make -DBATCH package-recursive clean
cd /usr/ports/databases/unixODBC; make -DBATCH package-recursive clean
# cd /usr/ports/databases/p5-DBI; make -DBATCH package-recursive clean
# cd /usr/ports/databases/p5-DBD-Pg; make -DBATCH package-recursive clean
# cd /usr/ports/net/p5-URI; make -DBATCH package-recursive clean

The dependency list is mentioned on the Freeswitch website:

# cd /usr/ports/devel/autoconf; make -DBATCH package-recursive clean
# cd /usr/ports/lang/gcc34; make -DBATCH package-recursive clean
# cd /usr/ports/devel/automake; make -DBATCH package-recursive clean
# cd /usr/ports/devel/git; make -DBATCH package-recursive clean
# cd /usr/ports/devel/libtool; make -DBATCH package-recursive clean
# cd /usr/ports/devel/ncurses; make -DBATCH package-recursive clean
# cd /usr/ports/ftp/wget; make -DBATCH package-recursive clean
# cd /usr/ports/devel/pkgconf; make -DBATCH package-recursive clean
# cd /usr/ports/graphics/tiff; make -DBATCH package-recursive clean

Install libpri and dahdi-kmod (installs dahdi as dependency). If you are making packages, you need to modify the Makefile for dahdi-kmod26 located in /usr/ports/misc/dahdi-kmod26. Comment out line number 47 which says “NO_PACKAGE= Should be in sync with the kernel to work correctly

# cd /usr/ports/misc/libpri; make -DBATCH package-recursive clean
# cd /usr/ports/misc/dahdi-dmod26; make -DBATCH package-recursive clean
# echo 'dahdi_enable="YES"' >> /etc/rc.conf
# echo 'dahdi_module="{MODULE_NAME}"' >> /etc/rc.conf

Replace the module name with the appropriate module for your card. For a list of modules, see this page. At the moment, support is only available for Digium cards on FreeBSD. If anybody knows how to configure Sangoma or other cards, I would love to hear about it.

Download Freeswitch from git repository:

# cd /usr/src
# /usr/local/bin/git clone git://git.freeswitch.org/freeswitch.git freeswitch-upstream
# cd freeswitch-upstream
# ./bootstrap.sh

Once the bootstrap process completes, move into spandsp directory.

# cd libs/spandsp

Edit the spandsp configure file and comment out the following code

for ac_header in tgmath.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "tgmath.h" "ac_cv_header_tgmath_h" "$ac_includes_default"
if test "x$ac_cv_header_tgmath_h" = xyes; then :
cat >>confdefs.h < <_ACEOF
#define HAVE_TGMATH_H 1
_ACEOF
INSERT_TGMATH_HEADER="#include "
fi

done

Once you are done with the changes, configure and install spandsp module. Also, freetdm needs to be configured with libpri enabled. Make sure that you use gmake as bsd make would not work for compiling spandsp and freeswtich

# setenv LDFLAGS -L/usr/local/lib
# setenv CPPFLAGS -I/usr/local/include
# ./configure; gmake install; cd ..
# cd freetdm; ./configure --with-libpri --prefix=/usr/local/freeswitch; gmake
# ./configure; gmake install samples sounds-install moh-install hd-sounds-install hd-moh-install

spandsp libs will be installed in /usr/local/libs while freeswitch and freetdm would be installed in /usr/local/freeswitch and /usr/local/freetdm respectively.

References:
(1) Freeswitch installation Guide
(2) FreeBSD Forums

Adding additional ip addresses in FreeBSD – Alternate methods

Traditional way of adding additional ip address in FreeBSD has been to add entries in /etc/rc.conf:

ifconfig_em0_alias0="inet 10.1.30.15 netmask 255.255.255.255"
ifconfig_em0_alias1="inet 10.5.30.16 netmask 255.255.255.255"
ifconfig_em0_alias2="inet 192.168.1.10 netmask 255.255.255.255"
ifconfig_em0_alias3="inet 10.1.30.245 netmask 255.255.255.255"

This works nicely, but the problem lies in the fact that if you miss the numbering in alias, subsequent aliases will not be read by the system. So a listing like

ifconfig_em0_alias0="inet 10.1.30.15 netmask 255.255.255.255"
ifconfig_em0_alias1="inet 10.5.30.16 netmask 255.255.255.255"
ifconfig_em0_alias3="inet 10.1.30.245 netmask 255.255.255.255"

will lead to the last alias ‘10.1.30.245’ to be not read/set by the OS. There exists an alternate way to set up additional ip address which does not include numbering of aliases. All you need to do is create a file /etc/start_if.<interface>, where <interface> is the name of the network interface you want to bind the aliases to. So for example you have an interface em0, the file that needs to be created is /etc/start_if.em0. This file is a shell script (bourne shell) file where you can call the ifconfig command to add the aliases to your nic. An example file could be:

#!/bin/sh
/sbin/ifconfig em0 alias 10.1.50.15 netmask 255.255.255.255
/sbin/ifconfig em0 alias 10.5.30.16 netmask 255.255.255.255
/sbin/ifconfig em0 alias 192.168.1.10 netmask 255.255.255.255
/sbin/ifconfig em0 alias 10.1.30.245 netmask 255.255.255.255

Since this is a standard shell script, you will be able to all sorts of scripting inside (Not tested though, apart from placing comments using # sign). This allows for better administration and scripting for aliases.

There exists another way to set aliases, though I haven’t tested them myself. This goes into /etc/rc.conf file and lets you easily add groups of ip address at a time:

ipv4_addrs_em0="192.168.1.10/32 10.1.30.0/27 10.1.30.245/32"

Large file upload with PHP and NGINX

When trying to upload large files with PHP in an environment which also includes nginx, apart from the php.ini directives of ‘upload_max_filesize’ and ‘post_max_size’, you also need to increase the value of ‘client_max_body_size’ in nginx.conf . See this link for explanation: http://wiki.nginx.org/HttpCoreModule#client_max_body_size

If you are still facing problems, it might be related to max execution time variables which are present across php.ini, php-fpm.conf and nginx.conf. This page has couple of them listed out: http://www.villescorner.com/2012/02/nginx-php-fpm-file-upload-battle.html

Amitabh

Partition automation in bsdinstall auto script in FreeBSD

[This post is part of the bsdinstall automation series. It should be read with the main article posted @ http://www.amitabhkant.com/custom_iso_with_bsdinstall_in_freebsd/]

These lines should go out in the bsdinstall auto file, after commenting out bsdinstall autopart and bsdinstall mount section. Remember, this would wipe out the entire disk contents without any warning, so use it at your own risk. I am also assuming that if you have multiple disks connected, the first disk is what you want to install your OS on. Otherwise, you might have to modify the script accordingly.

Get the disk layout, and the first disk connected to the system
# disk_layout=`sysctl -n kern.disks`
# first_disk=${disk_layout%% *}

Destroy any existing partition, and then create a gpt partition
# gpart destroy -F $first_disk
# gpart create -s gpt $first_disk

Create a boot partition to hold the loader, size of 512K. Give it a GPT label of gpboot, which will show up in /dev/gpt when the device is discovered:
# gpart add -t freebsd-boot -l gpboot -b 40 -s 512K $first_disk

Install the GPT bootcode into the boot partition:
# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 $first_disk

Create a swap parition
# gpart add -t freebsd-swap -l gpswap -s 4G $first_disk

Create a partition for /. It should start at the 1M boundary for proper sector alignment on 4K sector drives or SSDs. This is compatible with GPT drive layout for many other systems. Give it a GPT label of gprootfs.
# gpart add -t freebsd-ufs -l gprootfs -a 1M $first_disk

Format the root partition
# newfs -U /dev/gpt/gprootfs

Mount the partition at /mnt
# mount /dev/gpt/gprootfs /mnt

Add entry to fstab ($PATH_FSTAB)
# echo '# Device Mountpoint FStype Options Dump Pass#' > $PATH_FSTAB
# echo '/dev/gpt/gpswap none swap sw 0 0' >> $PATH_FSTAB
# echo '/dev/gpt/gprootfs / ufs rw 1 1' >> $PATH_FSTAB

(1) Although the post is meant as part of automating bsdinstall, the concept could be used to create partitions over a new disk with appropriate safeguards