Wednesday, October 15, 2008

Mesh4x SMS Adapter Desktop PC

Introduction

What happens when we need to synchronize data and the Internet connection is not available?

In this scenario an alternative channel needs to be used to send and receive changes. SMS via a mobile phone is one possible alternative channel.

The idea is to share data between two PCs with the mobile phone plugged in. The application uses the phone as a modem.

 

Mesh4x's SMS Adapter allows 2-way synchronization over SMS messages, optimizing the number of messages sent both ways.

 

The following picture shows this idea in detail. The data in this example are KML file elements:

 image

Packaging and Configuration

The application is distributed by a zip file.

After unzipping the file some configuration changes need to be made.

 image

To configure the application we will edit the mesh4j_sms.properties file. The default configuration looks like this:

default.kml.file=c:\\Clarius\\mesh4x\\test\\example.kml
default.feed.url=http://sync.instedd.org/Service.svc/feeds/Default
sync.identity.provider=org.mesh4j.sync.security.LoggedInIdentityProvider
default.base.directory=c:\\Clarius\\mesh4x\\test\\
default.sms.phone.number.destination=01136544867



Here, the default KML file and the default SMS phone number can be changed.



The default.base.directory property defines the directory where the application stores the SMS Adapter information. If a '#' is added before the property, the value is replaced with the current directory (where the application was installed):




sync.identity.provider=org.mesh4j.sync.security.LoggedInIdentityProvider
#default.base.directory=c:\\Clarius\\mesh4x\\test\\
default.sms.phone.number.destination=01136544867



As the application is using the mobile as a modem, the modem port must be configured. Although the automatic discovery of modem is possible, it is a pending issue in the TODO list :)



Don't forget to enter the properties default.sms.port and default.sms.baud.rate !




default.sms.port=COM23
default.sms.baud.rate=115200
default.sms.sender.delay=0
default.sms.receiver.delay=0
default.sms.read.delay=60000
default.sms.channel.delay=1000
default.sms.max.message.length=100
default.sms.compress.method=org.mesh4j.sync.message.encoding.CompressBase64MessageEncoding
default.sms.use.asynchronous.connection=true



Obtaining the Modem Port



There are several ways to obtain the modem port. In Windows Vista, the DeviceManager application can be used:



 image



Running the Demo





To run the demo, double-click over the mesh4j-SMS-DemoApp.jar file. To use it, you must have java JDK installed in your PC. The following window will be shown:



image



To synchronize a KML with other KML files or with a Sync Server via HTTP you can use the "KML synchronization Group".



You should enter the endpoint1 and endpoint2 using a KML file or a sync server URL.



The button named "Synchronize" starts the synchronization process. Partial information is shown in the console view.



 image



When the KML file is newer the file needs to be prepared for the process of synchronization. The KML Adapter adds the sync information to the KML file.



For this process you should press the "Prepare file to sync" button. If you do not prepare the file but you run the synchronization process, the KML adapter always prepares the file before the synchronization process is run.



 image



The KML file with and without Sync Information are very similar.



KML File without Sync Information:





   1: <?xml version="1.0" encoding="UTF-8"?>


   2:  


   3: <kml xmlns="http://earth.google.com/kml/2.2">  


   4:   <Document> 


   5:     <name>default.kml</name>  


   6:     <Style id="sn_ylw-pushpin"> 


   7:       <IconStyle> 


   8:         <scale>1.1</scale>  


   9:         <Icon> 


  10:           <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href> 


  11:         </Icon>  


  12:         <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/> 


  13:       </IconStyle> 


  14:     </Style>  


  15:     <Style id="sh_ylw-pushpin"> 


  16:       <IconStyle> 


  17:         <scale>1.3</scale>  


  18:         <Icon> 


  19:           <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href> 


  20:         </Icon>  


  21:         <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/> 


  22:       </IconStyle> 


  23:     </Style>  


  24:     <StyleMap id="msn_ylw-pushpin"> 


  25:       <Pair> 


  26:         <key>normal</key>  


  27:         <styleUrl>#sn_ylw-pushpin</styleUrl> 


  28:       </Pair>  


  29:       <Pair> 


  30:         <key>highlight</key>  


  31:         <styleUrl>#sh_ylw-pushpin</styleUrl> 


  32:       </Pair> 


  33:     </StyleMap>  


  34:     <Placemark> 


  35:       <name>My City - Brandsen</name>  


  36:       <description>My city...</description>  


  37:       <LookAt> 


  38:         <longitude>-58.23648800008881</longitude>  


  39:         <latitude>-35.17488100021453</latitude>  


  40:         <altitude>0</altitude>  


  41:         <range>1000.000703843458</range>  


  42:         <tilt>0</tilt>  


  43:         <heading>9.54166404439055e-015</heading> 


  44:       </LookAt>  


  45:       <styleUrl>#msn_ylw-pushpin</styleUrl>  


  46:       <Point> 


  47:         <coordinates>-58.23648800008881,-35.17488100021453,0</coordinates> 


  48:       </Point> 


  49:     </Placemark>  


  50:     <ExtendedData></ExtendedData> 


  51:   </Document> 


  52: </kml>




KML File with Sync Information:





   1: <?xml version="1.0" encoding="UTF-8"?>


   2:  


   3: <kml xmlns="http://earth.google.com/kml/2.2">  


   4:   <Document> 


   5:     <name>default.kml</name>  


   6:     <Style id="sn_ylw-pushpin_a981af11-d58e-413d-8f4e-3438c61a3c28" xml:id="a981af11-d58e-413d-8f4e-3438c61a3c28" xmlns:mesh4x="http://mesh4x.org/kml" mesh4x:originalId="sn_ylw-pushpin"> 


   7:       <IconStyle> 


   8:         <scale>1.1</scale>  


   9:         <Icon> 


  10:           <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href> 


  11:         </Icon>  


  12:         <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/> 


  13:       </IconStyle> 


  14:     </Style>  


  15:     <Style id="sh_ylw-pushpin_b21297e9-4efd-42fe-be7f-289f862b5fba" xml:id="b21297e9-4efd-42fe-be7f-289f862b5fba" xmlns:mesh4x="http://mesh4x.org/kml" mesh4x:originalId="sh_ylw-pushpin"> 


  16:       <IconStyle> 


  17:         <scale>1.3</scale>  


  18:         <Icon> 


  19:           <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href> 


  20:         </Icon>  


  21:         <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/> 


  22:       </IconStyle> 


  23:     </Style>  


  24:     <StyleMap id="msn_ylw-pushpin_f1c450c2-0b9c-4b1f-a6b8-559809f7e327" xml:id="f1c450c2-0b9c-4b1f-a6b8-559809f7e327" xmlns:mesh4x="http://mesh4x.org/kml" mesh4x:originalId="msn_ylw-pushpin"> 


  25:       <Pair> 


  26:         <key>normal</key>  


  27:         <styleUrl>#sn_ylw-pushpin_a981af11-d58e-413d-8f4e-3438c61a3c28</styleUrl> 


  28:       </Pair>  


  29:       <Pair> 


  30:         <key>highlight</key>  


  31:         <styleUrl>#sh_ylw-pushpin_b21297e9-4efd-42fe-be7f-289f862b5fba</styleUrl> 


  32:       </Pair> 


  33:     </StyleMap>  


  34:     <Placemark xml:id="5a4fe143-35d6-41c4-9907-fb39f11e0cba"> 


  35:       <name>My City - Brandsen</name>  


  36:       <description>My city...</description>  


  37:       <LookAt> 


  38:         <longitude>-58.23648800008881</longitude>  


  39:         <latitude>-35.17488100021453</latitude>  


  40:         <altitude>0</altitude>  


  41:         <range>1000.000703843458</range>  


  42:         <tilt>0</tilt>  


  43:         <heading>9.54166404439055e-015</heading> 


  44:       </LookAt>  


  45:       <styleUrl>#msn_ylw-pushpin_f1c450c2-0b9c-4b1f-a6b8-559809f7e327</styleUrl>  


  46:       <Point> 


  47:         <coordinates>-58.23648800008881,-35.17488100021453,0</coordinates> 


  48:       </Point> 


  49:     </Placemark>  


  50:     <ExtendedData xmlns:mesh4x="http://mesh4x.org/kml">


  51:       <mesh4x:hierarchy xml:id="45ec93d6-0690-40ad-890b-edde0e921fad" mesh4x:childId="a981af11-d58e-413d-8f4e-3438c61a3c28"/>


  52:       <mesh4x:sync version="2024263971">


  53:         <sx:sync xmlns:sx="http://feedsync.org/2007/feedsync" id="45ec93d6-0690-40ad-890b-edde0e921fad" updates="1" deleted="false" noconflicts="false">


  54:           <sx:history sequence="1" when="2008-10-14T21:02:50Z" by="vcc-PC_jtondato"/>


  55:         </sx:sync>


  56:       </mesh4x:sync>


  57:       <mesh4x:sync version="542466287">


  58:         <sx:sync xmlns:sx="http://feedsync.org/2007/feedsync" id="a981af11-d58e-413d-8f4e-3438c61a3c28" updates="1" deleted="false" noconflicts="false">


  59:           <sx:history sequence="1" when="2008-10-14T21:02:50Z" by="vcc-PC_jtondato"/>


  60:         </sx:sync>


  61:       </mesh4x:sync>


  62:       <mesh4x:hierarchy xml:id="81a9522c-6881-4d5f-a080-aba688f0e8b9" mesh4x:childId="b21297e9-4efd-42fe-be7f-289f862b5fba"/>


  63:       <mesh4x:sync version="-188474479">


  64:         <sx:sync xmlns:sx="http://feedsync.org/2007/feedsync" id="81a9522c-6881-4d5f-a080-aba688f0e8b9" updates="1" deleted="false" noconflicts="false">


  65:           <sx:history sequence="1" when="2008-10-14T21:02:50Z" by="vcc-PC_jtondato"/>


  66:         </sx:sync>


  67:       </mesh4x:sync>


  68:       <mesh4x:sync version="-1089580191">


  69:         <sx:sync xmlns:sx="http://feedsync.org/2007/feedsync" id="b21297e9-4efd-42fe-be7f-289f862b5fba" updates="1" deleted="false" noconflicts="false">


  70:           <sx:history sequence="1" when="2008-10-14T21:02:50Z" by="vcc-PC_jtondato"/>


  71:         </sx:sync>


  72:       </mesh4x:sync>


  73:       <mesh4x:hierarchy xml:id="040b2f2f-b7ee-45d2-b087-685764632dcd" mesh4x:childId="f1c450c2-0b9c-4b1f-a6b8-559809f7e327"/>


  74:       <mesh4x:sync version="-432306466">


  75:         <sx:sync xmlns:sx="http://feedsync.org/2007/feedsync" id="040b2f2f-b7ee-45d2-b087-685764632dcd" updates="1" deleted="false" noconflicts="false">


  76:           <sx:history sequence="1" when="2008-10-14T21:02:50Z" by="vcc-PC_jtondato"/>


  77:         </sx:sync>


  78:       </mesh4x:sync>


  79:       <mesh4x:sync version="-541558727">


  80:         <sx:sync xmlns:sx="http://feedsync.org/2007/feedsync" id="f1c450c2-0b9c-4b1f-a6b8-559809f7e327" updates="1" deleted="false" noconflicts="false">


  81:           <sx:history sequence="1" when="2008-10-14T21:02:50Z" by="vcc-PC_jtondato"/>


  82:         </sx:sync>


  83:       </mesh4x:sync>


  84:       <mesh4x:hierarchy xml:id="8daad571-5866-4baa-a62f-42bff6e12e8a" mesh4x:childId="5a4fe143-35d6-41c4-9907-fb39f11e0cba"/>


  85:       <mesh4x:sync version="2019814375">


  86:         <sx:sync xmlns:sx="http://feedsync.org/2007/feedsync" id="8daad571-5866-4baa-a62f-42bff6e12e8a" updates="1" deleted="false" noconflicts="false">


  87:           <sx:history sequence="1" when="2008-10-14T21:02:50Z" by="vcc-PC_jtondato"/>


  88:         </sx:sync>


  89:       </mesh4x:sync>


  90:       <mesh4x:sync version="1141301425">


  91:         <sx:sync xmlns:sx="http://feedsync.org/2007/feedsync" id="5a4fe143-35d6-41c4-9907-fb39f11e0cba" updates="1" deleted="false" noconflicts="false">


  92:           <sx:history sequence="1" when="2008-10-14T21:02:50Z" by="vcc-PC_jtondato"/>


  93:         </sx:sync>


  94:       </mesh4x:sync>


  95:     </ExtendedData>


  96:   </Document> 


  97: </kml>




The "Purge" button removes all the sync history with exception of the latest one.

The button "clean" removes all the sync information (clean up everything).



When the application starts up, it verifies if the modem has been plugged in (using the value in the property default.sms.port). If the modem has been plugged in the modem's name is shown in the field named "Phone". Otherwise, the word "Demo" is shown.



image 



To synchronize a KML file with another PC via SMS, the next step is to enter the KML file to synchronize (the file must be located in the mobile phone directory, this will be discussed more in detail later in this post) and the phone number of the counterpart.



The button "Synchronization" start the synchronization process. This process could take time, but it works as an asynchronous process.



The console view shows all messages traffic, and you can see high level notifications too.



You could simulate the process with the button "Simulate" which lets you see in the console view the complete traffic of the protocol messages (no SMS messages are sent).



For test purposes you can send a message manually. First you enter the phone number and the message to send, and then press the button "send".



image



The console view shows notification messages of all processes running in the application (file to file synchronization, file to URL synchronization or file to file SMS synchronization).



 image



The protocol is based on a SyncSession concept. A sync session is a session that maintain the information of the synchronization process.



A new directory for the mobile phone plugged in the PC is created on the default.base.directory. In this directory the SmsAdapter stores the sync session information. (*1)



 image



For each session there are 2 RSS Feed files: the current session and the last session snapshot.


The file are named  [sessionId]_current.xml and [sessionId]_snapshot.xml.


Current Session Feed Example :




   1: <?xml version="1.0" encoding="UTF-8"?>


   2:  


   3: <rss xmlns:sx="http://feedsync.org/2007/feedsync" version="2.0">


   4:   <channel>


   5:     <session sessionId="8eee69f6-3421-459a-8ee9-35147f2c1ae4" sessionVersion="1" 


   6:             sourceId="abc.kml" endpointId="01136544867" lastSyncDate="" 


   7:             full="true" open="true" cancelled="false">


   8:       <ack>5b8b3589-6f07-4913-b058-eb6d840a90e0</ack>


   9:       <ack>390f3dfc-b18a-4ef9-9cb4-6b80c2663c88</ack>


  10:     </session>


  11:     <item>


  12:       <title>hierarchy</title>


  13:       <description>Id: 5b8b3589-6f07-4913-b058-eb6d840a90e0 


  14:         version: 47379581</description>


  15:       <mesh4x:hierarchy xmlns:mesh4x="http://mesh4x.org/kml" 


  16:         xml:id="5b8b3589-6f07-4913-b058-eb6d840a90e0" 


  17:         mesh4x:childId="89d714e8-b1e5-4d85-876f-fe3971cc6e68"/>


  18:       <author>


  19:         <name>52-0950011-91_Deloluis</name>


  20:       </author>


  21:       <sx:sync id="5b8b3589-6f07-4913-b058-eb6d840a90e0" updates="1" 


  22:             deleted="false" noconflicts="false">


  23:         <sx:history sequence="1" when="Wed, 27 Aug 2008 06:33:52 GMT" 


  24:             by="52-0950011-91_Deloluis"/>


  25:       </sx:sync>


  26:     </item>


  27:     </channel>


  28: </rss>



Snapshot Session Feed Example:



   1: <?xml version="1.0" encoding="UTF-8"?>


   2:  


   3: <rss xmlns:sx="http://feedsync.org/2007/feedsync" version="2.0">


   4:   <channel>


   5:     <session sessionId="6aa2c381-d716-487f-bc43-50828f7338da" sessionVersion="1" 


   6:         sourceId="a.kml" endpointId="01136544867" lastSyncDate="Sat, 11 Oct 2008 03:52:00 GMT" 


   7:         full="true" open="false" cancelled="false"/>


   8:     <item>


   9:       <title>hierarchy</title>


  10:       <description>Id: 8976b491-b5c8-43bb-8393-395be6853155 version: 419821444</description>


  11:       <mesh4x:hierarchy xmlns:mesh4x="http://mesh4x.org/kml" 


  12:         xml:id="8976b491-b5c8-43bb-8393-395be6853155" 


  13:         mesh4x:childId="6aff55c2-2c0a-4756-a2ec-c97fea8a35bc"/>


  14:       <author>


  15:         <name>vcc-PC_jtondato</name>


  16:       </author>


  17:       <sx:sync id="8976b491-b5c8-43bb-8393-395be6853155" updates="2" 


  18:             deleted="false" noconflicts="false">


  19:         <sx:history sequence="2" when="Wed, 30 Jul 2008 15:55:40 GMT" by="vcc-PC_jtondato"/>


  20:         <sx:history sequence="1" when="Wed, 30 Jul 2008 15:55:40 GMT" by="vcc-PC_jtondato"/>


  21:       </sx:sync>


  22:     </item>


  23:   </channel>


  24: </rss>




Each protocol message to be sent is divided in a batch of compressed messages. For assurance of the reliability of the protocol two queues are used to store in/out messages. Each queue is persisted as a Feed.



In Queue Feed Example (smsChannel_incomming.xml):





   1: <?xml version="1.0" encoding="UTF-8"?>


   2:  


   3: <SmsChannel> 


   4:   <IncommingOngoing/>


   5:   <IncommingCompleted>


   6:     <Batch batchId="381d5" protocol="^" messages="1" sms="01136544867" 


   7:             sessionId="8eee69f6-3421-459a-8ee9-35147f2c1ae4">


   8:       <BatchMessage sequence="0" lastModDate="Sat, 11 Oct 2008 03:56:12 GMT">


   9:         ^381d510bf52e8eee69f6-3421-459a-8ee9-35147f2c1ae4n21


  10:         </BatchMessage>


  11:     </Batch>


  12:   </IncommingCompleted>


  13:   <IncommingDiscarded/>


  14: </SmsChannel>






Out Queue Feed Example (smsChannel_outcomming.xml) :





   1: <?xml version="1.0" encoding="UTF-8"?>


   2:  


   3: <SmsChannel> 


   4:   <Outcomming> 


   5:     <Batch batchId="60c17" protocol="^" messages="1" sms="01136544867" sessionId="8eee69f6-3421-459a-8ee9-35147f2c1ae4"> 


   6:       <BatchMessage sequence="0" lastModDate="Sat, 11 Oct 2008 03:56:45 GMT">^60c1710381d58eee69f6-3421-459a-8ee9-35147f2c1ae4n61&amp;Te08c0500-a42f-4d35-b595-d2eb94f9fc0bT1219818832000admin</BatchMessage> 


   7:     </Batch>  


   8:     <Batch batchId="78964" protocol="^" messages="1" sms="01136544867" sessionId="8eee69f6-3421-459a-8ee9-35147f2c1ae4"> 


   9:       <BatchMessage sequence="0" lastModDate="Sat, 11 Oct 2008 03:57:25 GMT">^7896410381d58eee69f6-3421-459a-8ee9-35147f2c1ae4n61&amp;T9c6a1bae-1ce8-4c19-a3e3-47bdcdab4c8bT1219818832000admin</BatchMessage> 


  10:     </Batch>  


  11:   </Outcomming>  


  12:   <OutcommingCompleted>


  13:     <Batch batchId="bf52e" protocol="^" messages="1" sms="01136544867" sessionId="8eee69f6-3421-459a-8ee9-35147f2c1ae4">


  14:       <BatchMessage sequence="0" lastModDate="Sat, 11 Oct 2008 03:56:11 GMT">^bf52e10000008eee69f6-3421-459a-8ee9-35147f2c1ae4n11&amp;abc.kml</BatchMessage>


  15:     </Batch>


  16:   </OutcommingCompleted>


  17: </SmsChannel>




Requirements



The smslib java library is used to send and receive SMS messages.



The application requires the "Java Communications Library" installed in your PC. smsLib uses the serial port cable to communicate with the mobile phone to send and receive messages. Please check the following installation instructions (only Java Communications Library section).



Please check if your mobile phone is in the Compatible GSM Modems/Phones list.



Download desktop application



I hope that it can help you !!!



JMT