The workflow I'm trying to accomplish is as follows.
- There is a jQuery Mobile UI with a bunch of range slider elements. Each one is for controlling a different function.
- When a user moves and releases any one of these sliders, a jQuery event should be triggered that makes an AJAX call (I don't care if it uses JSON, XML, POST, etc - fastest is best)
- The Ajax call contains info about what slider was moved, and what its new value is (ex: id=slider1, value=215)
- The Ajax executes a python script in the CGI bin that reads the ID and value and controls some hardware connected to my Raspberry Pi via Serial (the Raspberry pi also running the webserver).
I have a JQuery UI with a bunch of sliders. Each slider code looks like this:
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<div class="rgbw_label"><label for="red_slider">
Red:
</label></div>
<input type="range" id="red_slider" name="red_slider" value="0" min="0" max="255" data-highlight="true" />
</fieldset>
</div>
There needs to be some accompanying JQuery that does something like this:
$(document).ready(function () {
$.ajax({
type: "POST",
url: "cgi-bin/command.py",
success: function (msg)
{
alert("Data Saved: " + msg);
}
});
});
Obviously two major things have to change about the JS. First, it needs to execute when the slider is released (not on page load), and second it needs to actually pass the value of the slider to the Python script some how. I set it up like this just to test. When I load the page, this tester python script is executed correctly, and some hardware connected to the Raspberry Pi is controlled properly. I know I should be using the slidestop event, but I can't get it to work. I'm also not sure of what is the BEST way to send some variables to the python script.
My python script looks like this, right now: #!/usr/bin/python
import cgi
import serial
ser = serial.Serial('/dev/ttyUSB0', 57600)
ser.write("Hello, this is a command!\n") # write a string
ser.close()
So, it's not looking for any kind of incoming data, it just gets called and writes some Serial data. It should be able to receive data from the AJAX call, and adjust the Serial writing command based on the info it receives. I need help getting that info into variables that I can work with. I assume I should also pass back some kind of "I'm done" message back to the JavaScript calling function.
I'm looking forward to any insight that folks might have on either high level issues, or ways to solve more specific problems that I've listed here.
Thanks!