31 July 2011

Reading date/time from GSM network

Still playing with the serial GSM modem to send SMSes, I investigated a way to obtain a timestamp from the network. Just in case I want to record an event and place it on the time line.
It turns out that the GSM network does not (always?) carry date/time information and the extended GSM AT command set does not provide a way to read that information. So, a workaround is needed.

All received SMSes contain a timestamp, usually set by the originating network. This is an example:
+CMGL: 5,"REC UNREAD","4130",,"11/07/07,18:07:19+08"
message body
The timestamp is in the first line in the format yy/mm/dd,hh:mm:ss+tz . Well, don't ask me what +08 stands for, but 18:07 was local Summer time.

My trick is: find out if your operator has a service that auto-replies with an SMS to SMSes or calls to a special number. Italian operators have such a service to inform the subscriber of the amount of credit left. When you need a timestamp, let your device query the proper network service via SMS or call; wait for the SMS to come; read the datetime string. Don't forget to delete the SMS so that your SIM/MT memory fills up.

This procedure will not provide a precise timestamp down to 1" resolution, but it will put your application in the right ballpark, usually within a minute (which is more than enough for my remote thermometer!).

Of course an RTC chip can be added for as little as 2EUR/2USD, but you need a way to initialize it and board space too.