kludge - (or kluge) is a workaround, a quick-and-dirty solution, a clumsy or inelegant, yet effective, solution to a problem, typically using parts that are cobbled together.

Blazing ping times with GPRS (AT&T and Telit GM862)

Posted: April 12th, 2011 | Author: | Filed under: ramblings, wireless | Tags: , , | No Comments »

I have been testing some web snippets with the Telit GM862 module lately, it’s incorporated into a project that I am working on for a client and while ironing out some connectivity issues and yadda-yadda blah blah blah, whatever Joe Rogan. Anyway I just wanted to share some blazing ping times I was getting with the module; ever wonder why your browser seems a bit sluggish to get moving on your phone?

Yes. I still use the Bliss wallpaper and XP.


Reading ID3 tags with PHP (kludge)

Posted: April 8th, 2011 | Author: | Filed under: php | Tags: , | 2 Comments »

The other day a co-worker faced the issue of determining the total duration of multiple mp3 and mp4 files spread across an arbitrary number of directories on the file server. Now we could’ve opened a group of mp3s into Media Player or the like and determined the total duration of that playlist but I couldn’t quickly think of a way to do this for mp4 and right clicking for the file properties was out of the question. Given the fact that this task would become more regular than just a one-time gig I decided to set out and create a script to automate this process. Since I am in bed with PHP I figured I’d go ahead and write this script using just that and run from command prompt.

You will need to download the terrific getID3 class from http://www.getid3.com, this will enable you to perform the necessary file functions required to extract ID3 tags. Once you have downloaded you will need to extract to your working directory from which we will be running our script. By default it will be in a getID3 folder so we will use this for our example.

Ok so let’s make some kludge, open up Notepad or whichever IDE you are comfortable with and start this schniz.

Include ID3 and create instance of ID3

//Require our newly downloaded getid3, main file is getid3.php.
//Under the Linux Environment you would use forward slashes,
//e.g. require_once('/getid3/getid3.php');
//Create instance of ID3
$getID3 = new getID3;

Since I am running this script from the command prompt I am going to ask the user to input the directory they wish to search.

Prompt user for directory they wish to search

//Prompt user for directory location and store in $directoryToSearch
echo "Input the directory to search (C:\\\BLAH\\\FOO):";
$directoryToSearch = trim(fgets(STDIN));

We will declare a variable that will contain our desired file type, this will be used in a check later on in the script. Also we will declare a variable to hold our total duration.

File type and Time variable declaration

//Declare file type we wish to find
$fileType = "mp3";
$totalTime = 0;

We will read through the inputted directory and grab each file one by one. Once we grab a file we will utilize the analyze function of ID3

Traverse Directory and analyze file if found, placing tags into array

//Check to make sure directory is valid
//Directory is valid, open it.
$dir = opendir($directoryToSearch);
//Loop through each file in the directory
while (($file = readdir($dir)) !== false) {
     if (is_file($fileName)) {
          $fileName = realpath($directoryToSearch.'/'.$file);
          //Put tag information into an array for output

There are many different tags you can retrieve using ID3, I am just interested in the file type and the total duration so we will use $array['playtime_seconds']. For more information on what information is available review the structure.txt file or view them here.

Here will double check that this file is our desired file format and if so accumulate the duration.

Check for file type match and accumulate time

//Check to see if the file matches types declared above
//if so accumulate total.
if($currentFile['fileformat'] == $fileType){
    $totalTime = $totalTime + $currentFile['playtime_seconds'];

Now remember this script was made to traverse the Windows Environment; so if you are compiling on Linux make sure you correct your slashes. Also the $directoryToSearch is input at the console, you may wish to change this to a static variable or maybe even a form field if you are migrating this to a web application.

In the real world version of this script I included file operations to output information to a tab delimited file for use in Excel. You may want to add some of this functionality to your script as well or maybe even store to a DBMS of your choice.


Seared i7 anyone?

Posted: April 8th, 2011 | Author: | Filed under: ramblings | Tags: , , , | No Comments »

So we tracked down the problem to the computer that apparently had a mind of its’ own, shutting down at random times throughout the day. While the obvious answer anyone would guess is overheating, supposedly the i7 should scale down it’s speed if heat becomes an issue it cannot overcome so this was thrown out of the window. But what we didn’t know was that the i7 cannot scale itself down when it doesn’t even have a heat sink touching it to help keep it cool.

Hide your wife, hide your kids and go check to make sure your heat sink is properly attached before burning (<— like that pun?) through some 3D renders.

Seared i7

i7 showing some skin, errrr brown skin.


*No processors were harmed in this article.

PPP with Telit GM862 (AT&T)

Posted: April 8th, 2011 | Author: | Filed under: linux, wireless | Tags: , , | No Comments »

I thought I would share my experience with connecting to AT&T’s wireless network via Telit GM862 radio over PPP. It is safe to assume this will work for anyone else using another form of GSM device on AT&T’s network.

While there are a couple of posts and a couple of threads that explain what you will need to do to achieve this I decide that it would just be best if I flat out pasted my settings files and was verbatim about the entire situation as it was a headache for me to nail it down.

First step is to ensure you have PPP installed, if you do not you will need to download.

Install PPP

root:~# apt-get update
root:~# apt-get install ppp

Next navigate to your provider file, it should be located in /etc/ppp/peers/provider and edit it to contain the proper information. I have changed the serial device to reflect the proper device, mine was /dev/ttyS1 you might find yours to be mounted elsewhere. Also I have changed the call string to *99***1#”

/etc/ppp/peers/provider contents

# This is the default configuration used by pon(1) and poff(1).
# See the manual page pppd(8) for information on all the options.

# MUST CHANGE: replace myusername@realm with the PPP login name given to
# your by your provider.
# There should be a matching entry with the password in /etc/ppp/pap-secrets
# and/or /etc/ppp/chap-secrets.

# MUST CHANGE: replace ******** with the phone number of your provider.
# The /etc/chatscripts/pap chat script may be modified to change the
# modem initialization string.
connect "/usr/sbin/chat -v -f /etc/chatscripts/pap -T *99***1#"

# Serial device to which the modem is connected.

# Speed of the serial line.

# Assumes that your IP address is allocated dynamically by the ISP.
# Try to get the name server addresses from the ISP.
# Use this connection as the default route.

# Makes pppd "dial again" when the connection is lost.

# Do not ask the remote to authenticate.

Next let’s edit our pap file which is located in /etc/chatscripts/pap. Copy and paste, overwriting what is currently in there with what you see below.

/etc/chatscripts/pap contents

# You can use this script unmodified to connect to sites which allow
# authentication via PAP, CHAP and similar protocols.
# This script can be shared among different pppd peer configurations.
# To use it, add something like this to your /etc/ppp/peers/ file:
# connect "/usr/sbin/chat -v -f /etc/chatscripts/pap -T PHONE-NUMBER"
# noauth

# Uncomment the following line to see the connect speed.
# It will be logged to stderr or to the file specified with the -r chat option.

TIMEOUT         60
ABORT        "ERROR"
""        ATZ
OK              AT+CGDCONT=1,"IP","WAP.CINGULAR"
OK        ATD*99***1#

Next we are going to edit our pap-secrets file which can be found in/etc/ppp/pap-secrets. Here we are going to make sure our user has access to pppd, I am running on an embedded linux board that automatically boots to root so I have documented him out so I have access. Also we are going to add our user and password that we inserted into provider file. This must match for authentication to work.

/etc/ppp/pap-secrets contents

# /etc/ppp/pap-secrets
# This is a pap-secrets file to be used with the AUTO_PPP function of
# mgetty. mgetty-0.99 is preconfigured to startup pppd with the login option
# which will cause pppd to consult /etc/passwd (and /etc/shadow in turn)
# after a user has passed this file. Don't be disturbed therefore by the fact
# that this file defines logins with any password for users. /etc/passwd
# (again, /etc/shadow, too) will catch passwd mismatches.
# This file should block ALL users that should not be able to do AUTO_PPP.
# AUTO_PPP bypasses the usual login program so it's necessary to list all
# system userids with regular passwords here.
# ATTENTION: The definitions here can allow users to login without a
# password if you don't use the login option of pppd! The mgetty Debian
# package already provides this option; make sure you don't change that.

# INBOUND connections

# Every regular user can use PPP and has to use passwords from /etc/passwd
*	hostname	""	*

# UserIDs that cannot use PPP at all. Check your /etc/passwd and add any
# other accounts that should not be able to use pppd!
guest	hostname	"*"	-
master	hostname	"*"	-
#root	hostname	"*"	-
support	hostname	"*"	-
stats	hostname	"*"	-

# OUTBOUND connections

# Here you should add your userid password to connect to your providers via
# PAP. The * means that the password is to be used for ANY host you connect
# to. Thus you do not have to worry about the foreign machine name. Just
# replace password with your password.
# If you have different providers with different passwords then you better
# remove the following line.


Lastly we are going to edit our chap-secrets file, which can be found in the same directory as above. I have removed all other information found in here and added only the AT&T information necessary.

/etc/ppp/chap-secrets contents

# Secrets for authentication using CHAP
# client	server	secret			IP addresses

Now you are ready to rock and roll on AT&T’s 3G network using your GSM device. To initiate the connect you will issue the pon command from the terminal. To kill the connection you will issue the poff command from the terminal.

By typing plog you can see the last entries in the ppp log. This will help you to verify that it is working, or also to tell if there is an error occuring.

starting ppp and checking the ppp log

root:~# pon
root:~# plog
Apr  5 12:37:33 localhost pppd[1289]: pppd 2.4.4 started by root, uid 0
Apr  5 12:37:34 localhost chat[1290]: timeout set to 60 seconds
Apr  5 12:37:34 localhost chat[1290]: abort on (BUSY)
Apr  5 12:37:34 localhost chat[1290]: abort on (VOICE)
Apr  5 12:37:34 localhost chat[1290]: abort on (ERROR)
Apr  5 12:37:34 localhost chat[1290]: abort on (NO CARRIER)
Apr  5 12:37:34 localhost chat[1290]: abort on (NO DIALTONE)
Apr  5 12:37:34 localhost chat[1290]: abort on (NO DIAL TONE)
Apr  5 12:37:34 localhost chat[1290]: send (ATZ^M)
Apr  5 12:37:34 localhost chat[1290]: expect (OK)
Apr  5 12:37:34 localhost chat[1290]: ATZ^M^M
Apr  5 12:37:34 localhost chat[1290]: OK
Apr  5 12:37:34 localhost chat[1290]:  -- got it
Apr  5 12:37:34 localhost chat[1290]: send (AT+CGDCONT=1,"IP","wap.cingular","",0,0^M)
Apr  5 12:37:35 localhost chat[1290]: expect (OK)
Apr  5 12:37:35 localhost chat[1290]: ^M
Apr  5 12:37:35 localhost chat[1290]: AT+CGDCONT=1,"IP","wap.cingular","",0,0^M^M
Apr  5 12:37:35 localhost chat[1290]: OK
Apr  5 12:37:35 localhost chat[1290]:  -- got it
Apr  5 12:37:35 localhost chat[1290]: send (ATD*99***1#^M)
Apr  5 12:37:35 localhost chat[1290]: expect (CONNECT)
Apr  5 12:37:35 localhost chat[1290]: ^M
Apr  5 12:37:35 localhost chat[1290]: ATD*99***1#^M^M
Apr  5 12:37:35 localhost chat[1290]: CONNECT
Apr  5 12:37:35 localhost chat[1290]:  -- got it
Apr  5 12:37:35 localhost chat[1290]: send (^M)
Apr  5 12:37:35 localhost pppd[1289]: Serial connection established.
Apr  5 12:37:35 localhost pppd[1289]: Using interface ppp0
Apr  5 12:37:35 localhost pppd[1289]: Connect: ppp0 <--> /dev/ttyS1
Apr  5 12:37:36 localhost pppd[1289]: Remote message: Welcome!
Apr  5 12:37:36 localhost pppd[1289]: PAP authentication succeeded
Apr  5 12:37:40 localhost pppd[1289]: local  IP address
Apr  5 12:37:40 localhost pppd[1289]: remote IP address
Apr  5 12:37:40 localhost pppd[1289]: primary   DNS address
Apr  5 12:37:40 localhost pppd[1289]: secondary DNS address

You can also issue ifconfig to list all your network interfaces to double check that your ppp0 interface has received the proper addressing.

Remember, to kill this connection simply type poff at the terminal.

Side notes:

Some of you may have problems connecting to web resources and other web objects once establishing a connection even though you have the proper information. This could be due to information in your route, to ensure GPRS routing make sure that you don’t have any default gateways set up in your route. To find out type route in the terminal.

Removing default gateway

root:~# route
Kernel IP routing table
Destination     Gateway       Genmask         Flags Metric R  ef    Use   Iface     *      U      0        0      0    eth0
default         UG     0        0      0    eth0
root:~# route del default gw eth0