3

so I currently have a JavaScript code that I run on my iPhone to pull its Accelerometer data. What I would like to do is Pass this data to my Mac Book Pro and use the variables in A python Script. The Variables are changing multiple times a second so it would need to repeatedly send the Variables. I would greatly appreciate any help I can get. Thank you.

<html>
<body>
<div id="content">
    <h1>Accelerometer JavaScript Test</h1>
<ul>
    <li>acceleration x: <span id="accelerationX"></span></li>
    <li>acceleration y: <span id="accelerationY"></span></li>
    <li>Motor Speed: <span id="speed"></span></li>
</ul>
</div>
<script type="text/javascript">
window.ondevicemotion = function(e){
        var x = e.accelerationIncludingGravity.x;
        var y = e.accelerationIncludingGravity.y;
        var newx = x * 100
        var newy = y * 100
        var finalx = Math.round(x);
        var finaly = Math.round(y);
        document.getElementById("accelerationX").innerHTML = finalx
        document.getElementById("accelerationY").innerHTML = finaly
        speed = finalx * 10
        document.getElementById("speed").innerHTML = speed
    }
</script>
</body>
</html>
7
  • 2
    Have you already come up with something? You know you can send data through AJAX requests to a server running on the other side? Commented Dec 7, 2013 at 20:48
  • Thank you for responding and no I currently just have the javascript that picks up the variables, then am lost on how to get them to my mac . Commented Dec 7, 2013 at 20:53
  • Multiple times per second? Look into sockets & then web sockets. Commented Dec 7, 2013 at 21:00
  • Thank you for the idea I will definitely look into that! Commented Dec 7, 2013 at 21:01
  • Still not having any luck with this, any help would be appreciated. Commented Dec 7, 2013 at 21:24

1 Answer 1

3

You just need to do an ajax call. The first answer of this question may help you.

The answer says:

All you need is to make an ajax request to your pythoncode. You can do this with jquery http://api.jquery.com/jQuery.ajax/, or use just javascript

$.ajax({
  type: "POST",
  url: "~/pythoncode.py",
  data: { param: text}
}).done(function( o ) {
   // do something
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.