Quantcast
Channel: Biobug.org » iPhone

iPhone dev: SMSresponder

$
0
0

I’ve built a perl script to enable SMS remote start of my car. The script checks the SMS database for new messages and if the message meets the criteria, it will send a command out the serial port, log the event and send a reply sms for confirmation.

Everything is done in perl! My script directly reads the SQLite sms database, writes to the serial port via Serial::Device, sends confirmation SMS messages via sendSMS and logs to a log file with a quick and dirty file write routine. I’d like to add a serial port logger for convenient data logging from my hardware interface as well as some feedback info for the reply sms: cabin temperature will be the easiest to add…

First, the phone needed some packages. Here’s my current install list:

iPhone:/var/log root# dpkg --get-selections
adv-cmds                    install
apr-lib                        install
apt7                        install
apt7-key                    install
apt7-lib                    install
apt7-ssl                    install
base                        install
bash                        install
berkeleydb                    install
bzip2                        install
ch.ringwald.springboardaccess            install
com.saurik.iphone.ske                install
com.saurik.substrate.safemode            install
coreutils-bin                    install
curl                        install
cy+cpu.arm                    install
cy+kernel.darwin                install
cy+lib.corefoundation                install
cy+model.iphone                    install
cy+os.ios                    install
cydia                        install
cydia-lproj                    install
darwintools                    install
debianutils                    install
diffutils                    install
diskdev-cmds                    install
dpkg                        install
essential                    install
expat                        install
findutils                    install
firmware                    install
firmware-sbin                    install
gcrypt                        install
git                        install
gnupg                        install
grep                        install
gsc.accelerometer                install
gsc.all-features                install
gsc.any-telephony                install
gsc.app-store                    install
gsc.application-installation            install
gsc.armv6                    install
gsc.bluetooth                    install
gsc.cellular-data                install
gsc.contains-cellular-radio            install
gsc.gps                        install
gsc.hw-encode-snapshots                install
gsc.hw-snapshots-need-purplegfx            install
gsc.international-settings            install
gsc.location-services                install
gsc.microphone                    install
gsc.mms                        install
gsc.music-store                    install
gsc.not-green-tea                install
gsc.opengles-1                    install
gsc.peer-peer                    install
gsc.proximity-sensor                install
gsc.ringer-switch                install
gsc.sms                        install
gsc.stand-alone-contacts            install
gsc.still-camera                install
gsc.telephony                    install
gsc.telephony-maximum-generation        install
gsc.unified-ipod                install
gsc.voip                    install
gsc.volume-buttons                install
gsc.wifi                    install
gsc.youtube                    install
gsc.youtube-plugin                install
gzip                        install
jp.ashikase.mousesupport            install
jpeg                        install
libgpg-error                    install
libstatusbar                    install
libvncserver                    install
lzma                        install
minicom                        install
mobilesubstrate                    install
ncurses                        install
openssh                        install
openssl                        install
org.thebigboss.repo.icons            install
p5-archive-extract                install
p5-archive-tar                    install
p5-archive-zip                    install
p5-attribute-handlers                install
p5-autodie                    install
p5-autoloader                    install
p5-b-debug                    install
p5-b-lint                    install
p5-bignum                    install
p5-cgi.pm                    install
p5-class-isa                    install
p5-compress-bzip2                install
p5-compress-raw-bzip2                install
p5-compress-raw-zlib                install
p5-constant                    install
p5-cpan                        install
p5-cpan-checksums                install
p5-cpan-meta-yaml                install
p5-cpanplus                    install
p5-cpanplus-dist-build                install
p5-data-compare                    install
p5-data-dumper                    install
p5-db-file                    install
p5-dbd-sqlite                    install
p5-dbi                        install
p5-devel-ppport                    install
p5-device-serialport                install
p5-digest                    install
p5-digest-md5                    install
p5-digest-sha                    install
p5-encode                    install
p5-encode-locale                install
p5-encoding-warnings                install
p5-exporter                    install
p5-extutils-cbuilder                install
p5-extutils-command                install
p5-extutils-install                install
p5-extutils-makemaker                install
p5-extutils-manifest                install
p5-extutils-parsexs                install
p5-fcgi                        install
p5-file-fetch                    install
p5-file-find-rule                install
p5-file-homedir                    install
p5-file-listing                    install
p5-file-path                    install
p5-file-remove                    install
p5-file-temp                    install
p5-file-which                    install
p5-filter                    install
p5-filter-simple                install
p5-getopt-long                    install
p5-html-parser                    install
p5-html-tagset                    install
p5-http-cookies                    install
p5-http-daemon                    install
p5-http-date                    install
p5-http-message                    install
p5-http-negotiate                install
p5-http-tiny                    install
p5-io                        install
p5-io-compress                    install
p5-io-zlib                    install
p5-ipc-cmd                    install
p5-ipc-run3                    install
p5-ipc-sysv                    install
p5-json                        install
p5-json-pp                    install
p5-lib                        install
p5-libnet                    install
p5-libwww-perl                    install
p5-locale-codes                    install
p5-locale-maketext                install
p5-locale-maketext-simple            install
p5-log-message                    install
p5-log-message-simple                install
p5-lwp-mediatypes                install
p5-math-bigint                    install
p5-math-bigint-fastcalc                install
p5-math-bigrat                    install
p5-math-complex                    install
p5-mime-base64                    install
p5-module-build                    install
p5-module-corelist                install
p5-module-install                install
p5-module-load                    install
p5-module-load-conditional            install
p5-module-loaded                install
p5-module-pluggable                install
p5-module-scandeps                install
p5-module-signature                install
p5-net-http                    install
p5-next                        install
p5-number-compare                install
p5-object-accessor                install
p5-par-dist                    install
p5-params-check                    install
p5-parse-cpan-meta                install
p5-pathtools                    install
p5-pod-escapes                    install
p5-pod-parser                    install
p5-probe-perl                    install
p5-safe                        install
p5-storable                    install
p5-switch                    install
p5-sys-syslog                    install
p5-term-ansicolor                install
p5-term-ui                    install
p5-test-harness                    install
p5-test-script                    install
p5-test-simple                    install
p5-text-balanced                install
p5-text-glob                    install
p5-tie-refhash                    install
p5-time-local                    install
p5-time-piece                    install
p5-unicode-collate                install
p5-unicode-normalize                install
p5-uri                        install
p5-version                    install
p5-www-robotrules                install
p5-xsloader                    install
p5-yaml                        install
p5-yaml-libyaml                    install
p5-yaml-syck                    install
p5-yaml-tiny                    install
pam                        install
pam-modules                    install
pcre                        install
perl                        install
perl-base-modules                install
preferenceloader                install
profile.d                    install
readline                    install
saurik                        install
sed                        install
sendsms                        install
shell-cmds                    install
system-cmds                    install
tar                        install
top                        install
uikittools                    install
ultrasn0w                    install
veency                        install
vim                        install

I highly reccommend installing apt strict – you can install needed packages via apt-get install bleh on the command line.

I’m still tweaking the script, but the first working version loads on phone startup vi starup plist. So far it seems to be somewhat robust. Testing will tell.


SMS Remote Start – working prototype

$
0
0

A quick update on the SMS remote start using my old iPhone… It works! I can now start my Subaru outback via SMS command from wherever I am.

I used an older Arduino simply because I wanted a quick and dirty 3.3v source for the iphone to arduino serial interface. The perfboard has a tip120 to drive the remote start, all the interface wiring for the car, power supply and the iphone interface. I tossed in a .01 cap at the power source just for extra filtering. The power supply is a switching charger from a broken iphone car charger. Efficient and free!

This is my quick build schematic. (Click to see the entire thing) The voltage divider on the left is so that the arduino can report the system voltage. it’s made of 3 10k resistors since I always have those on hand. The result is 1/3 of the 12-14v DC that the car has. From this, we can infer the state of the car: >13 is started. I plan to toss in a ds180 1 wire temp sensor later on as well. The pink highlighter was used as I wired things up.

Important: There’s an error in the schematic – I fixed it on my board but forgot to update it! The diode should connect on the other side of the resistor that connects the iphone serial RX and the Arduino 3.3v source. If you connect it this way, you won’t get any serial input on the iphone. It’s not lethal, just important!

(update 2: You can get the clean version of the schematic here: )

Requirements:

An old jailbroken iPhone, an Arduino, iphone breakout board (I used a PodBreakout Mini) 4x 10k resistors, 1x TIP120, a 5 volt switching supply cell charger (easier than building one), some wiring ability and a general understanding of unix/perl/arduino. (See the packages on my dev phone in this post.

The code:

You can get the code to make it all work here. (SMSresponder.pl, com.SMSresponder.startup.plist and

SMSresponder is a perl script that runs in a loop. Every 30 seconds it checks for a new message since the last time it ran. place it in /var/root/bin/ (you’ll need to create that directory) as this is where the startup system looks for it. You can put it somewhere else, just edit the plist to match.

Make it work all the time:

Copy com.SMSresponder.startup.plist to /System/Library/LaunchDaemons on the phone. This will start the script at boot.

The Arduino:

RemoteStartController.pde is a quick program that I wrote based on all sorts of other source I already had on hand. Notably, most of the code was adapted from Motokomp. I’ve added hooks for additional commands, but haven’t updated the iPhone perl script to do anything with the output.

How it works in real life:

I send a text message from my phone with the phrase: “Start 1234″ (1234 would be the password in the phone script). The phone gets the text then tells the arduino via serial interface to start. The arduino grounds the wire to the remote start that activates it. Meanwhile, the phone sends back a SMS saying ‘Executed’ to let me know that it got the message and is acting on it. In the future it’ll send back a message confirming that the start was executed as opposed to the I told him to do it method.

Project comments:

This thing works very well. I can probably get away with reducing the polling time on the iPhone, but I wanted to conserve resources. I spent two weeks testing the SMSresponder script running on the phone with perfect results every time. I still need to add some handshaking between the iphone and arduino, (iPhone: start dude. Arduino: OK!, iPhone: great let me sms that back to the man in charge.) Right now, the iphone sends the command and prays that the arduino got the message.

The remote start I’m using is an Avatal 3117 purchased via Amazon. (There are additional things added to make the subaru’s computer happy about missing the key) the main reason I bought this remote start is that it has an input wire for starting! When you ground it, the remote start will start the car. If you ground it again, the car will turn off. That’s how the arduino activates the remote start. In reality, there’s also a serial interface on most RS units today, but getting documentation on them seemed difficult. Besides, who wants to implement a new protocol just for a one-off build?

I’m seriously considering building a kit version of this hardware. It would include the iphone dock connector, programmed atmega, etc: it would tie all the prototype hardware into a single build – and maybe add a nice box and harness to make it work. (I used extra wiring bits from my remote start install to add a nice modular connector to the prototype)

SMSresponder interface schematic

$
0
0

I whipped up a clean schematic for my current version of the SMS responder. I left out the iphone dock connector because I used a breakout board – and really, it’s easier that way, you can cable over to the iphone. Click to view the entire schematic – my blog trims the images (I don’t like scaling them!)

SMS remote start usability update

$
0
0

Ok, so it’s been a week since I installed the SMS interface. I took the car out to Winter Park for a week of sliding down the mountain and gave the system a real world test. (Tried it from my hotel room while the car was outside) and it worked!

I just gave it another test run and the car started perfectly. Now that the system has stayed working, I’m planning to develop the backend code a bit more. In addition, I have some more tricks up my sleeve… :)

Cheap Wifi Thermostat with a JSON API

$
0
0

I updated my thermostat to one of these. It’s made by Homewerks (Home depot sells a filtrete branded version.) It’s not as cool as the NEST, but it’ll do the job of controlling a furnace/AC. The interesting part of this device is that the wifi interface can be cloud managed, making it possible to control the thermostat via my iPhone, iPad (or android) from anywhere with data connectivity.

It’s actually a fairly decent device for the money. It has a JSON api that allows you to get and set variables via web interface. There’s a fantastic PDF on the API that shows examples using curl (available on linux, mac, etc). What’s really interesting is that with a JSON interface, you could easily write your own application for mobile phones or just script up some commands from your choice of computing platform.

Wiring was interesting. On my ancient furnace (built by chrystler) I discovered some new details. The fan wire wasn’t connected at all! At some point, some A/C tech had installed a honeywell fan controller and the fan is activated by either the cooling or heating wires being engaged. (there is a manual switch inside the furnace. Argh!) However, I was able to re-use the fan wire as a C wire to deliver both sides of the 24v a/c transformer power to the thermostat. Wifi eats more power, and you need an external supply to feed that radio.

Setup is pretty neat. I loaded the radio thermostat App on my iPad, and once it discovered the thermostat, I had to join the ‘stats wifi network. Then I could configure my WPA2 network (excellent! Thanks for supporting proper protocols!) as well as a dynamic or static ip address. I opted for static the last time I configured it. –I reconfigured it a few times while I played around with wiring options.

The hardware in the device is rather interesting. It’s the first one I’ve seen with a wifi USNAP module. I’d expect to see more of these devices on the market. The price point is fairly low and the curl api is ideal. Hmm, arduino USNAP shield, anyone?

Resources:

Wiki (unknown owner) for developing: http://central.isaroach.com/wiki/index.php/Main_Page

PDF Documenting the Thermostat API. (local copy here) This is the interesting one.





Latest Images