<rdf:RDF
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    xmlns:s='http://snipsnap.org/rdf/snip-schema#'
    xml:base='http://www.mobile-j.de/snipsnap/rdf'>
    <s:Snip rdf:about='http://www.mobile-j.de/snipsnap/rdf#J2ME/Using+the+N95+accelerometer+in+Java+-+kind+of'
         s:cUser='bjoernQ'
         s:oUser='bjoernQ'
         s:mUser='bjoernQ'>
        <s:name>J2ME/Using the N95 accelerometer in Java - kind of</s:name>
        <s:content>I was very excited about the newly discovered accelerometer in the N95.&#xD;&#xA;Unfortunately there&apos;s no sensor API for us JME developers. But fortunately a Python module is available. (aXYZ module, see http://cyke64.googlepages.com/ ).&#xD;&#xA;&#xD;&#xA;So I decided to write a small socket server in Python which emits the raw sensor data. Then my midlet can connect to this Python server and use the provided data. Each dataset consists of the X,Y and Z values separated by &quot;,&quot; and a &quot;*&quot; to mark the end of the data tuple.&#xD;&#xA;&#xD;&#xA;The server has a number of limitations (single-threaded, stops after the client disconnects) because I&apos;m not a Python programmer. The JME code is also very inefficient but I think it&apos;s much easier to understand than if it were when it&apos;s more optimized.&#xD;&#xA;&#xD;&#xA;In order to try it out you have to start the server first and then you can use the MIDlet.&#xD;&#xA;&#xD;&#xA;{image:Screenshot0001.jpg}{image:Screenshot0002.jpg}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;Here is the code of the server&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;import socket&#xD;&#xA;import axyz&#xD;&#xA;&#xD;&#xA;clientSocket = None&#xD;&#xA;&#xD;&#xA;def printout(x,y,z):&#xD;&#xA;  if clientSocket:&#xD;&#xA;     clientSocket.sendall( &quot;%i,%i,%i*&quot;%(x,y,z) )&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;HOST = &apos;127.0.0.1&apos;&#xD;&#xA;PORT = 12008&#xD;&#xA;print &quot;define the socket&quot;&#xD;&#xA;s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)&#xD;&#xA;print &quot;bind the socket&quot;&#xD;&#xA;s.bind((HOST, PORT))&#xD;&#xA;s.listen(1)&#xD;&#xA;print &quot;waiting of the client to connect&quot;&#xD;&#xA;conn, addr = s.accept()&#xD;&#xA;print &apos;Connected by&apos;, addr&#xD;&#xA;clientSocket = conn&#xD;&#xA;axyz.connect(printout)&#xD;&#xA;while 1:&#xD;&#xA;    data = conn.recv(1024)&#xD;&#xA;    if not data: break&#xD;&#xA;    conn.send(data)&#xD;&#xA;clientSocket = None&#xD;&#xA;axyz.disconnect()&#xD;&#xA;conn.close()&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;On the Java side I have created the class &quot;XYZConnect&quot;. It extends the Thread-class and connects to the local server. You have to provide a callback which is called each time a dataset arrives.&#xD;&#xA;&#xD;&#xA;Example:&#xD;&#xA;{code:Java}&#xD;&#xA;if(connector==null){&#xD;&#xA;&#9;connector = new XYZConnect(new Callback(){&#xD;&#xA;&#9;&#9;public void callback(int x, int y, int z) {&#xD;&#xA;&#9;&#9;&#9;displayable1.update(x,y,z);&#xD;&#xA;&#9;&#9;}&#xD;&#xA;                        &#xD;&#xA;&#9;});&#xD;&#xA;&#9;connector.start();&#xD;&#xA;}&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;The full source code can be found {link:here|http://www.mobile-j.de/snipsnap/space/J2ME/Using+the+N95+accelerometer+in+Java+-+kind+of/XYZTest.zip}. (Python + Java source.)&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;</s:content>
        <s:mTime>2007-11-18 09:35:23.572</s:mTime>
        <s:cTime>2007-11-18 09:31:06.227</s:cTime>
        <s:comments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:snipLinks>
            <rdf:Bag>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Accelerometer BallGame code and binaries'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/MovingBall example ported to JME'/>
                <rdf:li rdf:resource='#J2ME'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#Products/GETrack'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Self signed midlets for the lazy bones'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#Products/POIXpress'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/System.out redirect on S60 3rd Edition'/>
                <rdf:li rdf:resource='#snipsnap-index'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Sending blinking sms to older Nokias ...'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Getting the IMEI or not ...'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/jCIFS port for JME'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Getting content from a MIDlet into the phone'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#Products/S60 Screensaver Maker Pro'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#start/2007-11-18/1'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Sending SMS from MIDlet without user intervention'/>
                <rdf:li rdf:resource='#snipsnap-notfound'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/How to verify the phone&apos;s MSISDN'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Putting together BlueCove and avetanaOBEX'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#PYTHON/Distributing Python apps'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Accelerometer BallGame code and binaries/'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Fun with sending mms from a midlet'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#start/2007-11-28/1'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Guessing the network operator'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Using the N95 accelerometer in Java - kind of/'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#start/2008-02-16/1'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Start Real One Player from J2ME'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#start/2007-12-01/1'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#J2ME/Accelerator BallGame code and binaries'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#start/2007-10-14/1'/>
                <rdf:li rdf:resource='http://www.mobile-j.de/snipsnap/rdf#start/2007-11-18/2'/>
                <rdf:li rdf:resource='#bjoernQ'/>
            </rdf:Bag>
        </s:snipLinks>
        <s:attachments>
            <rdf:Bag>
                <rdf:li>
                    <s:Attachment rdf:about='http://www.mobile-j.de/snipsnap/space/J2ME/Using+the+N95+accelerometer+in+Java+-+kind+of/Screenshot0001.jpg'
                         s:fileName='Screenshot0001.jpg'
                         s:contentType='image/jpeg'
                         s:size='108995'>
                        <s:date>Sun Nov 18 09:32:34 GMT 2007</s:date>
                    </s:Attachment>
                </rdf:li>
                <rdf:li>
                    <s:Attachment rdf:about='http://www.mobile-j.de/snipsnap/space/J2ME/Using+the+N95+accelerometer+in+Java+-+kind+of/Screenshot0002.jpg'
                         s:fileName='Screenshot0002.jpg'
                         s:contentType='image/jpeg'
                         s:size='33168'>
                        <s:date>Sun Nov 18 09:32:45 GMT 2007</s:date>
                    </s:Attachment>
                </rdf:li>
                <rdf:li>
                    <s:Attachment rdf:about='http://www.mobile-j.de/snipsnap/space/J2ME/Using+the+N95+accelerometer+in+Java+-+kind+of/XYZTest.zip'
                         s:fileName='XYZTest.zip'
                         s:contentType='application/zip'
                         s:size='18907'>
                        <s:date>Sun Nov 18 09:32:15 GMT 2007</s:date>
                    </s:Attachment>
                </rdf:li>
            </rdf:Bag>
        </s:attachments>
    </s:Snip>
</rdf:RDF>
