Jump to content
  • entries
    31
  • comments
    44
  • views
    22,632

Powershell to set clock on SonyEricsson phone via Bluetooth


blog-0581306001552364226.png

SonyEricsson's PC Suite had a nice feature which would synchronize your phone's clock to your PC's clock when establishing a connection. I found more often than not my frequently-synchronized computer time differed by a minute or more from the Cingular/AT&T network time.

(quick bitching about Sony)


SonyEricsson discontinued the PC Suite (sad, since it could also compose and send MMS messages) for the PC Companion. Sony has since discontinued the PC Companion in favor of its Android-only software for its Xperia line of mobiles. Fair enough, since the SonyEricsson phones are, while functional, defunct. Two problems arise for me: first, that while I can install the PC Companion software, none of its modules are part of the installer and are downloaded from the Sony website upon first use, including text messaging and PC synchronization. I long ago null-routed the Sony website from which PC Companion downloads its modules because it would also determine a new program was available and prevent you from using the PC Companion, thus forcing the upgrade.

F.U. Sony.

At this point, once I move to a new machine I have limited options for continuing to use the PC Companion software, meaning I will lose my ability to synchronize Outlook with my phone and use my laptop to send and receive text messages via the phone. Why I stick to my old SonyEricsson phone is a discussion for later and I have wandered off-point.



Since PC Companion no longer synchronizes my phone's clock with my PC, using the SonyEricsson AT Commands reference guide I wrote a Powershell script to take up the slack. The script opens the Bluetooth COM port set in the first line (no error checking, sorry so lazy) which is COM14 on my laptop, then sends the AT*EDST and AT+CCLK commands to set daylight saving time status and the clock, respectively. Setting DST is extremely important for setting appointments as I do not enjoy being an hour late or early.

Since Get-Date returns the local time adjusted for DST, the time submitted to the phone must compensate. The IsDaylightSavingTime() return from the Get-Date object is perfect for this as it returns 0 for "not DST" and 1 for "DST," so this is subtracted from the current hour. The important here trick is to clear DST before setting the time. Otherwise, the phone accepts the given time as the current time including DST, but since DST has already been accounted for the time gets set an hour off.

*EDST is sent to the phone first, per SE recommendations, then +CCLK. $seTZ holds the time zone offset, which is the offset from UTC in quarter-hours, calculated by comparing the local time to UTC, adjusting for local DST, then multiplying by 4. Finally, the real DST setting is sent.

I put one-second pauses between sending each of the three commands to the phone. Without this pause commands will sometimes get missed. I suspect this is due to not reading the phone's responses which I do not try to read. This is a very primitive script which does not check to make sure the port is even open, so why even bother registering an event for reading the port? ;)


$sePort = new-Object System.IO.Ports.SerialPort COM14,9600,None,8,one$sePort.Open()$sePort.WriteLine("at*edst=0`r")Start-Sleep -Seconds 1$seTime = Get-Date$seEDST = If ($seTime.IsDaylightSavingTime()) { 1 } else { 0 }$seTZ = (($seTime-$seTime.ToUniversalTime()).Hours-$seEDST) * 4$seCommand = "at+cclk=`"$($seTime.AddHours(-$seEDST).ToString("yy/MM/dd,HH:mm:ss"))$($seTZ)`""$sePort.WriteLine($seCommand+"`r")Write-Host Time command $seCommand sent to SonyEricsson phone.Start-Sleep -Seconds 1Write-Host Setting DST on SonyEricsson phone to `"$seEDST`"$sePort.WriteLine("at*edst=$($seEDST)`r")Start-Sleep -Seconds 1$sePort.Close()Write-Host ** DONE **

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...