I'm using nippleJS: link
I'm not 100% sure if it's possible to send the joystick information but I'd say yes. I want to send an AJAX form with the position of the joystick and I want it to be in real time to control some engines. I can not send the information. I'm using this:
<script type="text/javascript">
$(document).ready(function() {
$('#static').onclick(function(evento){
/* Cancelamos el envío del formulario */
evento.stopPropagation();
evento.preventDefault();
var dataString = $('#static').serialize()
$.ajax({
type: "POST",
url: "/cgi-bin/motorcontrol.py",
data: dataString,
dataType: "json",
success: function(data) {
}
});
});
});
</script>
<div id="static"></div>
<script src="./dist/nipplejs.min.js"></script>
<script>
var static = nipplejs.create({
zone: document.getElementById('static'),
mode: 'static',
position: {left: '75%', top: '50%'},
color: 'black'
});
</script>
I'm using .onclick to only work when I'm pressing the joystick. The script to which it is addressed is this:
#! /usr/bin/python
import cgi, cgitb
import socket
cgitb.enable()
form = cgi.FieldStorage()
searchterm = form.getvalue('static')
socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sent = socket.sendto(str(searchterm) + "3", ('127.0.0.1', 31113))
And this:
#! /usr/bin/python
import serial, socket
ser = serial.Serial('/dev/ttyACM0',9600)
socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
socket.bind(('127.0.0.1', 31113))
print "Esperando conexion"
while True:
# Recibimos hasta 200 caracteres en un paquete UDP
datos, remoto = socket.recvfrom(200)
print("Datos recibidos de " + str(remoto) + " - " + str(datos))
ser.write(str(datos))
# Devolvemos los datos recibidos a modo de "ACK" (opcional)
sent = socket.sendto(datos, remoto)
I use them to see the data that arrives but nothing comes of anything.