• Stars
    star
    238
  • Rank 163,574 (Top 4 %)
  • Language
    Perl
  • Created about 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

notes and code for my payphone project

Payphone Project

These are some notes from my project to install a working payphone in my home and configure it to make and receive calls through an Asterisk PBX.

The Phone

This is a Western Electric/AT&T 1D2 single-slot "dumb" payphone, popular in the 1980s. It came with a T-key but no upper or lower locks or keys. The handset was pretty gross and there were no upper or lower instruction cards. Shipping was a bit expensive since the phone weighs nearly 50 pounds.

I purchased a new handset, mounting backplate, and mounting studs. I located some old instruction cards on eBay and upper and lower locks with key sets.

The instruction cards install by unscrewing a very tiny allen bolt in the front of the housing to allow the card to slide up and then back down.

The replacement handset was wired differently than the handset that came with the phone, which initially caused the mouthpiece not to transmit any audio. By touching a AA battery to the wires of the disconnected handset, I was able to figure out which wires went to the earpiece and which to the mouthpiece. The handset's red wire is connected to terminal 3, yellow to 4, green to 6, and black to 8.

Mounting

To mount the phone to my wall, I drilled 5 holes into a wall stud and secured the backing plate to the wall with 2 1/4" screws. The mounting studs hand-screwed into the back of the phone which allowed the phone to easily hang on the backplate, aligning the 12 holes in the back of the phone to the 1/4x20 threaded holes in the backplate.

The phone is mounted at the recommended height of 63" from the floor to the top of the housing.

Connectivity

Back when all payphones were owned by the phone company, a POTS line provisioned for a payphone provided dialtone to the phone. When coins were inserted, the phone's totalizer sent simultaneous 1700+2200 Hz tones down the line for each 5 cents (nickel = one 66 ms tone, dime = two 66 ms tones with a 66 ms pause in between, quarter = five 33 ms tones with 33 ms pauses).

The phone company's Automated Coin Toll Service (ACTS) would respond to the tones generated by the phone (or your red box) and allow the dialed phone number to connect for a certain amount of time.

Newer "smart" (Elcotel-style) payphones are commonly owned by private companies (Customer Owned Coin Telephones - COCOTs) and don't require a specially-provisioned phone line. The phone has an embedded circuit board that has to be programmed with rate information, allowing the phone itself to determine whether the call is allowed to go through based on the number dialed and the amount of coins inserted. These phones would have to get reprogrammed every so often by a company that calls into the pay phone and uploads new rate information to it. (If you're looking to acquire a payphone for personal use, avoid these "smart" phones. An easy way to tell them apart from the outside is that "dumb" phones have the coin slot on the left side and "smart" phones usually have it on the right. Inside it's easy to tell; just look for a big modern-looking circuit board.)

Since this phone has always worked with a normal POTS line, making it work now just requires hooking up the red and green wires of an RJ11 cable to the Ring and Tip terminals in the phone. It rings, dials, and otherwise functions just like a normal analog telephone.

I connected the phone to a Grandstream HT701 SIP ATA and was able to make and receive calls through an Asterisk soft PBX, with dialtone coming from the ATA. I registered an inbound number through Twilio (appropriately enough, one ending in -2600) and routed it to the Asterisk server via SIP.

Since this a payphone, after all, it should require depositing coins to make a call. Much older phones (like 3-slot rotary phones) required coins to be deposited before hearing a dial tone. These were mostly phased out by the 1970s and replaced with phones that provided a dial tone first, allowing emergency calls without depositing coins as well as depositing extra coins for long-distance calls. Using Asterisk, this payphone will be configured to provide a dial tone first and allow free emergency calls, but require 25 cents to call any other number.

Sending Coin Tones to Asterisk

Since the ATA only establishes audio between the phone and Asterisk after a recognizable pattern of digits has been dialed (and sent to Asterisk all at once in one INVITE request), Asterisk would not be able to respond to coin tones generated before dialing.

Using the ATA's "Offhook Auto-Dial" feature, I configured it to automatically (silently) dial 0 as soon as the handset was picked up. An AGI script on the Asterisk server would then take over, generating its own dialtone and responding to any tones sent by the phone.

Relevant Asterisk sip.conf configuration for the ATA:

[2600]
canreinvite=no
callerid=<...>
context=payphone-totalizer
dtmfmode=inband
host=dynamic
nat=yes
progressinband=no
qualify=3000
secret=...
type=friend
disallow=all
allow=ulaw
allow=alaw

Relevant Asterisk extensions.conf configuration to take over the call as soon as 0 is dialed by the ATA:

[payphone-totalizer]
exten => 0,1,Answer
exten => 0,2,AGI(payphone.agi)
exten => 0,3,Hangup

Recognizing Coin Tones

Now that Asterisk is receiving the 1700+2200 Hz tones generated when coins are inserted, some code is needed to actually recognize them. Using Asterisk EAGI would allow a program to read the raw audio stream and analyze it for the proper tone frequencies using the Goertzel algorithm, but doing so would be pretty complicated.

Since Asterisk is already doing in-band dual-tone multi-frequency (DTMF) detection for numerical digits, modifying it to recognize the coin tones is much less complicated. This patch to Asterisk's DSP module recognizes the 1700+2200 Hz tone and turns it into a $ digit, allowing any AGI or other code handling numeric digits to easily recognize coin tones.

A small AGI script to recognize and accumulate inserted coin amounts, printing it to the Asterisk console:

#!/usr/bin/perl

use Asterisk::AGI;
use strict;

my $inserted = 0;
my $dialed = "";
my $AGI = new Asterisk::AGI;

# generate dialtone while we wait for coins
$AGI->exec("Playtones", "dial");

while (1) {
    my $digit = $AGI->wait_for_digit(1000);
    next if ($digit <= 0);

    if ($digit == ord('$')) {
        $inserted += 5;
        $AGI->verbose("got 5-cent tone (now " . $inserted . " cents)", 5);
    }
    else {
        $dialed .= chr($digit);
        $AGI->verbose("dialed " . chr($digit) . " (now " . $dialed . ")", 5);
    }
}

Now that the amount of inserted coins can be recognized, along with any digits dialed, it's possible to make a full script that can refuse to connect calls and play an error message until a certain amount of money is inserted. Toll-free numbers, 911, etc. can be connected before any coins are collected.

My routing script is under development here.

TODO

  • Make the coin hopper queue up coins when inserted rather than immediately dropping them into the coin box, to allow for refunding. This requires sending high voltage (2) to the coin relay, and would have to be done out-of-band.

More Repositories

1

xbanish

Hide the mouse cursor when typing and show it again when the mouse moves
C
499
star
2

endless

iOS web browser with a focus on security and privacy
Objective-C
260
star
3

sdorfehs

A tiling window manager
C
238
star
4

no_color

Website data for no-color.org
HTML
230
star
5

progman

progman.exe^H^H^H^H
C
184
star
6

dotfiles

ftp -o - https://jcs.org/move_in | sh -
Vim Script
133
star
7

login_duress

A BSD authentication module for duress passwords
C
102
star
8

ansiterm

dos 437 fonts and configs for viewing ANSI art in xterm
Shell
60
star
9

ssh-agent-card-prompt

A prompt for ssh-agent(1) when your Yubikey needs poking
C
43
star
10

spoonfish

Lua
33
star
11

msTERM

Terminal program for MailStation devices
Assembly
32
star
12

xdimmer

lightweight X11 utility to dim the screen and/or keyboard backlight when idle
C
30
star
13

ratpoison

jcs ratpoison hax
C
30
star
14

blueping

C
18
star
15

adium-pipeevent

Adium plugin to pipe events/messages to an external program
Objective-C
18
star
16

WiFiStation

Bringing WiFi to the Cidco Mailstation
C++
17
star
17

vmwh

vmware userland helper
C
15
star
18

sockhole

Ruby
14
star
19

halfmoon

a tiny mvc framework for php using php-activerecord
PHP
14
star
20

mailstation-tools

Tools for working with Cidco Mailstations
Assembly
14
star
21

classic-mac-fonts

Classic Mac OS Fonts in BDF and TTF format
14
star
22

twitframe

Website data for twitframe.com
HTML
13
star
23

notes

Ruby
13
star
24

mp3chap

command line tool for adding ID3 chapters to an MP3 file
Go
13
star
25

sdorfehs-bar

A bar script for sdorfehs
Ruby
12
star
26

xweathericon

C
11
star
27

xbatticon

Battery/charge status for progman
C
10
star
28

tpadnav

C
9
star
29

pullup-counter

A program to read a Phidget IR sensor and log pull-ups with Fitbit's API
Ruby
9
star
30

pce

fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
C
8
star
31

openbsd-ports

/usr/ports/mystuff
Makefile
8
star
32

sinatree

A skeleton web application configured to use Sinatra and ActiveRecord
Ruby
8
star
33

itunes-rsync

utility to sync an itunes playlist to a directory (like a mounted sd card/phone)
Ruby
7
star
34

qconsole

quake-style console with xterm
C
7
star
35

siriproxy-ecobee

SiriProxy plugin for controlling an Ecobee thermostat
Ruby
6
star
36

shadowebkit

an experiment in making a cocoa webkit browser manageable under X11
Objective-C
6
star
37

xcalicon

Calendar/time for progman
C
6
star
38

MailStation-Example

Example program for the Cidco MailStation Z80 computer
Assembly
6
star
39

arduboy-1010

1010 for Arduboy
C++
5
star
40

WiFiPPP

ESP8266-based WiFi serial modem emulator ROM
C++
5
star
41

pixelclock

a small clock for X11 that displays time as pixels
C
5
star
42

mutt

mutt stable branch with some hacks
C
4
star
43

garbagefm

CMS for the late garbage.fm
PHP
4
star
44

eyetunes

a tiny webserver used to display the current itunes song
Ruby
4
star
45

logicmail

git clone of logicmail with some fixes/features added
Java
3
star
46

itrc

fork of iTunes Remote Control with bugfixes and enhancements
C
3
star
47

openbsd-commitid

script to retroactively add commitids to past openbsd commits
Shell
3
star
48

swoopowned

swoopo.com bid watcher and automated bidder
JavaScript
3
star
49

slock

slock with dpms and other tweaks
C
2
star
50

chibug.org

Website content for chibug.org
CSS
2
star
51

pflightbar

Flash the Chrome EC lightbar when pf blocks a packet
C
2
star
52

adafruit_fourscreen

Utilities for drawing on 4 Adafruit 8x8 LED Backpack displays as one
Ruby
1
star
53

minivmac

C
1
star
54

chronosync

Utility to set the time on a Hayes Stack Chronograph
C
1
star
55

qemu

C
1
star