This "project" exists, because the only way to connect my Powerbook G3 to Internet is via its 56k modem; I like to browse old sites via Wayback Machine proxy for fun. Its Ethernet chip has disappeared and Airport card isn't here yet. However, hauling a PBX between lab at work and home sucks, and I'm getting low speeds around 20 kbps via Grandstream GXW4004 ATA box, which also has direct dial (=dial ***7x where x is port number 1-4) function, but for some reasons modems won't do their handshake.

I already had Orange Pi Zero as dial-up server (set up using this guide), and a four-channel relay board was laying around in junk drawer, so what if you could switch the phone lines to cut off the ATA box and let modems talk directly to each other?

Wiring is simple, I'll let the picture explain it.

This isn't a beauty contest, it's a modem speed contest.

Anyway, wires from modems go to middle terminal of relays and wires from ATA box ports go to rightmost terminal of relays. When relays are off, modems are connected to ATA box. When all relays are turned on, jumper wires will connect modems to each other.

Now that I think of it, the jumper wires should be crossed, but apparently it does not matter. Phone cables between modems and ATA box were crossover cables, so I used straight-through cables from this relay mess to ATA box -- I mean, two crossovers in a row would be straight-through then. Anyway, I dunno, works for me, but you might want to swap jumper wires if it doesn't for you.

The relay board is connected to Orange Pi Zero: VCC connected to +5V pin, ground to obviously ground pin and CH1-4 pins connected to pin 3 (PA12/GPIO12). One pin on OPZ controls all relays at once.


How do we control the relays? How do we know when modems are connecting?

The mgetty config file (/etc/mgetty/mgetty.config) has debug setting, which is set to 9 in the Doge Microsystems guide, but I commented it out since it was quite chatty. Mentioning this because the default is apparently just fine for this.

Mgetty logs its stuff to file /var/log/mgetty/mg_ttyUSB0.log (ttyUSB0 if you're using USB serial adapter, something else if you're not) so a simple Bash script is enough to monitor mgetty and control relays.

Notice: this runs on Orange Pi Zero / Armbian, so you might need to adapt the GPIO commands a bit for RaspPi.

#!/bin/bash
if [[ ! -d "/sys/class/gpio/gpio12/" ]];
then
        echo GPIO not initialized, initializing...
        echo 12 > /sys/class/gpio/export
        echo out > /sys/class/gpio/gpio12/direction
fi
echo 1 > /sys/class/gpio/gpio12/value
echo Watching mgetty log file...
tail -Fn0 /var/log/mgetty/mg_ttyUSB0.log | \
while read line ; do
        echo "$line" | grep "send: ATA" > /dev/null
        if [ $? = 0 ]
        then
                echo Modem told to answer, relay turned on.
                echo 0 > /sys/class/gpio/gpio12/value
        fi
        echo "$line" | grep "mgetty: stable" > /dev/null
        if [ $? = 0 ]
        then
                echo Mgetty restarted, relay turned off.
                echo 1 > /sys/class/gpio/gpio12/value
        fi
done

The script keeps an eye on the mgetty log file. If it sees a line 'send: ATA', which means the mgetty asks the modem to answer the incoming call, it flicks the relays on. If it sees a line 'mgetty: stable', which you'll see when mgetty starts (after user disconnects the call, PPP quits and mgetty jumps back in), it flicks the relays off.

You might want to set up a service to run the script. There's tons of guides to do that.


Wait, but wouldn't the call disconnect because we're messing with the line? Nope. At least my modems don't care about it. Maybe the ATA box might be confused, but that's fine.

Anyway, you mileage may vary.

Speeeeeeeeed! 33600 bps up, 33600 bps down.