Skip to content

Instantly share code, notes, and snippets.

@kevinswiber
Created April 22, 2014 22:21
Show Gist options
  • Save kevinswiber/11196421 to your computer and use it in GitHub Desktop.
Save kevinswiber/11196421 to your computer and use it in GitHub Desktop.
Zetta iPhone App
<!doctype html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$(function() {
var x, y, z;
window.ondevicemotion = function(event) {
x = event.accelerationIncludingGravity.x;
y = event.accelerationIncludingGravity.y;
z = event.accelerationIncludingGravity.z;
$('#x').html(x);
$('#y').html(y);
$('#z').html(z);
};
setInterval(function() {
$.ajax({
url: 'http://192.168.1.18:3000/iphone-app/brians-iphone',
type: 'POST',
data: { action: 'change', x: x, y: y, z: z }
});
}, 2000);
$.ajax({
url: 'http://192.168.1.18:3000/registration',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({ target: 'iphone-app', device: { type: 'iphone', name: 'brians-iphone', state: 'on' } })
});
});
</script>
</head>
<body>
Hello, world!
<div>
X: <span id="x"></span>
</div>
<div>
Y: <span id="y"></span>
</div>
<div>
Z: <span id="z"></span>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment