Message Boards Message Boards

Using your smart phone as the ultimate sensor array for Mathematica

POSTED BY: Marco Thiel
15 Replies

I no longer see the sensor data app on the IOS store. But see a few other new ones. Is there one that you recommend?

POSTED BY: Jack I Houng

IS there a way to associate the WM code to the phone running on a separate network? Let say that the Phone is running using its own Data Service but my computer is in a separate network. Where do I place the IP in the code since I do not see this address anywhere in the code.

POSTED BY: Jose Calderon

Marco, excellent ideas and thanks for sharing, I've noticed that after some of the modules executed, they seem to keep running in my application (I am using Mathematica v10 in a OSx) is this expected?

Again thanks,

Salva

POSTED BY: Salvador Romo

How does socket get associated with 192.168.1.95:54388? socket is instanced on Port 10552, but what does that have to do with anything?

Thanks for any hint to get me started.

Fred

POSTED BY: Fred Klingener
Posted 9 years ago

Marco,

Can you explain this code fragment from your JLink processing?

packet = JavaNew["java.net.DatagramPacket", JavaNew["[B", 1024], 1024];
POSTED BY: David G

Hi,

"packet" in this case is an object created from the class"java.net.DatagramPacket". The arguments "JavaNew["[B", 1024]" and "1024" depend on the class you are dealing with. For example, I can have a class "ConnectionUDPClient.class" which I can call by obj = JavaNew["ConnectionUDPClient"].

Furthermore, it is possible to access methods inside the class. For the class above, I can have a method "sendMessage" which I can invoke by "obj@sendMessage". Finally, depending on the implemented method, it could also be possible to pass additional arguments. Hope this helps.

Kind regards,

Ricardo

Posted 9 years ago

Ricardo,

I'm a little foggy on the "[B" argument of the nested JavaNew. I think I've seen that before, but I don't recall that notation. I assume it's specifying a buffer of some sort?

Thanks for the help.

David

POSTED BY: David G
POSTED BY: Kathryn Cramer
POSTED BY: Kathryn Cramer

Dear Kathryn,

I am sorry if this didn't work for you. I am attaching the code that works for me and some students of mine. I am very sorry for not annotating it correctly, but I need to prepare a presentation for tomorrow and wanted to reply as swiftly as possible. I ran this piece of code on a couple of independent OSX machines and it appears to be working fine on all of them. I tested it on everything from iPhone 4 to iPhone 6. You are saying that you ran it in the Cloud, which I did not do. I ran it on a local machine, and laptop and iPhone were in the same network. I have not used the Wolfram Cloud app, but an iOS app from the app store that is called "Sensor Data". I think that it is expected that it will not work in the Cloud/Wolfram Development platform.

I just ran that code on MMA10.3 on OSX.

enter image description here

Note that when I run it, there are several functions in blue (e.g. setSoTimeout[10], receive, getData[]) but InstallJava[], LoadJavaClass[], JavaNew[] are black. Here's a screenshot.

enter image description here

As you work at Wolfram I suppose that you also are running MMA10.3. Which operating system are you using? I have asked a colleague of mine at our institute to post his code, which is a self-written code for Androids.

I think that it would be possible to make this "work" in the cloud. If you use, for example, DataDrop you can achieve something similar, with the exception that the update rate of data drop is nominally 2 Hz, so you would not be much faster than that.

If you cannot make it work I would be happy to screen-share and demonstrate how the program works.

Best wishes from Aberdeen,

Marco

Attachments:
POSTED BY: Marco Thiel
Posted 9 years ago

Is there an analog of the Sensor Data utility (with the data streaming capability) for Android smart phones?

POSTED BY: Alexey Popkov

Hi Alexey,

yes there are loads. We also wrote a little piece of code for Androids. It is somewhere on the Android Store. I will try to "extract" the program from a Post-Doc and post it here.

Cheers,

Marco

POSTED BY: Marco Thiel

Hi Marco and Alexey,

The app is called "Sensors Prototype" and it can be found in Google Play. We have tried it on the samsung S3 and S4 without issues. We wrote the following code in Java (server side) to test the data streaming:

import java.io.*;
import java.net.*;

    class serverUDP
    {   
        public static void main(String argv[]) throws Exception,IOException {
        System.out.println("    Server is Running ");       
        System.out.println("    In port :" + argv[0]);
        DatagramSocket serverSocket = new DatagramSocket(Integer.parseInt(argv[0]));
        byte[] receiveData = new byte[1024];

        while(true)
        {
            System.out.println("-----------------------");
            DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
            serverSocket.receive(receivePacket);
            String output = new String(receivePacket.getData());
            System.out.println("Received: " + output);
            System.out.println("-----------------------");
        }
       }
    }

Of course, both mobile and server should be on the same network

Regards Ricardo

Posted 9 years ago

okey, the Mathematica code is written to get the streaming data for any source connected into that ip address and port?

By the way, this will help me out...

Thanks

POSTED BY: Fabio Burgos
Posted 10 years ago

Such a big and informative info.

POSTED BY: Benjamin Stuart
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract