Quozl's Desk Charger Timer

| quozl@us.netrek.org | up |

2010-02-05
Gadgets Don't Need Power Always

Task

Computer control of a rack of device chargers, for mobile phones, amateur radio transceivers, a torch, and occasionally a laptop.

Materials

The wiring from the RS-232 connector to the solid state relay was done so that the relay would only energise if RTS was off and DTR was on.

The reason for this was that the two signals are normally found either both on or both off, except in rare circumstances. It is this rare circumstance which is desirable. We don't want activation during boot.

condition DTR RTS difference
system power off unpowered unpowered none
system booting off off none
system booted off off none
serial port opened by conventional software on on none
serial port closed by conventional software off off none
serial port opened by software designed to lower RTS on off full swing

Since control signals such as RTS and DTR are logically inverted, a positive voltage with respect to ground occurs when the signal is on. So with RTS off the signal has a voltage of -5V to -15V depending on the serial port internal power supply. With DTR on the signal has a voltage of 5V to 15V. Therefore the difference will be between 10V and 30V, current limited.

Software

/usr/local/bin/charger

A Python program that opens a serial port, lowers RTS in order to energise the relay, and then waits for a signal. Once a signal is received, it raises RTS, then closes the port.

Depends on the Debian package python-serial.

#!/usr/bin/python
import sys, serial, signal

# raises DTR and RTS, null effect
device = serial.Serial('/dev/ttyS2')

# lowers RTS, powers charger
device.setRTS(0)

# pause until signal received, e.g. from parent
signal.pause()

# raises RTS, depowers charger
device.setRTS(1)

# lowers DTR and RTS, null effect
device.close()

sys.exit(0)

/usr/local/bin/charger-off

A shell script that stops the charger. Useful in the context of a task scheduler like cron.

#!/bin/sh
killall --signal SIGUSR1 charger

/usr/local/bin/charger-hour

A shell script that runs the charger for an hour. Depends on the Debian package timeout, which is a program that runs a command for a given number of seconds then sends a signal. In this case we send SIGUSR1, also known as 10.

#!/bin/sh
timeout -10 3600 charger

| quozl@us.netrek.org | up |