I have the following website:
<html>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#boton1').click(function(){
var dataString = $('#form1').serialize();
alert('Datos serializados: '+dataString);
$.ajax({
type: "POST",
url: "/cgi-bin/script.py",
data: dataString,
dataType: "json",
success: function(data) {
}
});
});
});
</script>
<body>
<form id="form1" data-ajax="false">
<label for="slider-fill">Input slider:</label>
<input type="range" name="slider-fill" id="slider-fill" value="90" min="0" max="180" data-highlight="true">
<input type="submit" value="Submit" id="boton1">
</form>
</body>
</html>
As you can see what it does is send information to /cgi-bin/script.py
and that information is serialized. The problem is that I do not know how to collect it in the script and later send it to an Arduino. This is what I have written in Python:
import cgi, cgitb
import serial
cgitb.enable()
ser=serial.Serial('/dev/ttyACM0',9600)
form = cgi.FieldStorage()
searchterm = form.getvalue('form1')
ser.write(str(searchterm) + "1")
It does not work for me and I do not know what to do.