Remote Cellular Switch
The following commands are supported:
- On <switchID> < time> <duration>
- Turns <switchID> on in the future at
- On <switchID> <duration>
- Turns <switchID> on now for <duration> minutes
- Off <switchID>
- Turns <switchID> off
- Turns all switches off
- Returns the current temperature as measured by the external DS18B probe
- Returns the status of the switches, if they are on or scheduled to turn on.
Currently there are two switchIDs, 1 and 2. Duration is in minutes and the time format is hh:mm. Use 24hr time. If no time is specified the switch turns on immediately.
I based this on a raspberry PI. They have plenty of GPIO and a 3.3v level RS-232 port which is perfect for communicating with most of the GSM modem chips out there. After I started I found this little guy which plugs right into a raspberry PI no extra wiring necessary: http://imall.iteadstudio.com/raspberry-pi-gsm-add-on.html Some of the unused GPIO pins are brought out on that SIM900 breakout board so use ones that are convenient to get ahold of to plug the relays into.
The SIM900 has a pretty simple interface using the standard 'AT' commands. I wrote a pretty short Python program to set the SIM900 up and then react to the messages. The best way I found to do it is put the module in a sort of 'asynchronous' mode so incoming text messages are output as soon as they come in. It replies to valid commands with a confirmation message.
Relay board pinout
Each of the two relays can handle up to 30 amps and have 5v 200mA coils. To drive them I used 2n2222 transistors driven directly by the pi's 3.3v GPIO outputs with a 500 ohm resistor in series. This should only draw a few mA from the GPIO and gets the transistor into saturation. Put diodes backward across the coils to protect the transistors from voltage spikes when the relays turn off.
The python software is on github at the following link: https://github.com/AD7ZJ/GsmSwitch Put it wherever you like on the PI's filesystem, and then add a line to /etc/rc.local. Use the absolute path to the python script and be sure to put an & symbol afterwards so the rest of the boot process can proceed - the python script runs forever and never returns.
Edit /etc/inittab and remove the line that sets up /dev/ttyAMA0 to be a console device - this must be removed to open the port with a user process.