Setting linux time from your Cell Phone

I have a Sony z610 cell hooked up to my wgt634u via usb running openwrt. As this box has no internet connection, on power failure it has the wrong date/time.

As the z610 has it's own battery I wish to set my system time based on the z610 clock.

the z610 has no support for NITZ or getting it's time from the cell provider, but this is ok.

the z610 appears as ttyACM0 and ttyACM1. I use smsd pointing at ttyACM1 , so my clock script is free to use ttyACM0.

As this is openwrt, and mipsel based, perl modules like serialport.pm are broken (termios.h etc.) so instead I use ser2net to share the port via tcp, then use perl sockets to access the serial port. This is actually deceptively easy. In perl I used Net::Telnet instead of sockets as this was even easier ! (I didn't get the expected results with sockets either).

Perl Script is easy
----------
use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10);
$t->open(Host => "localhost", Port => 2008);
@lines = $t->print("AT+CCLK?");
$line = $t->getline;
$line = $t->getline;
print $line;
-----------

to set system date with the shell and this script

date -s "20`perl /etc/getcelltime.pl | grep CCLK | cut -b 9-25 |tr "," " " | tr "/" "-"`"

Comments

Popular posts from this blog

Baileys liquor Chocolate Chip and Cream desert

nginx decode base64 url for use with imgproxy

Resol VBUS success