I have a toggle button on a page 'index.html'. When I click on it, it executes a python cgi script that changes the state of something on my raspberry.
To do so, I do this :
HTML :
<form id="tgleq" method="POST" action="/cgi-bin/remote.py" target="python_result">
<input id="toggle-eq" type="checkbox" data-toggle="toggle" name="toggle-eq" value="">
<script>
$(function() {
$('#toggle-eq').change(function() {
tgl_state = $('#toggle-eq').prop("checked")
var toggle = document.getElementById("toggle-eq");
toggle.value = tgl_state;
document.getElementById("tgleq").submit();
})
})
</script>
CGI :
#!/usr/bin/env python
import cgi
import cgitb
cgitb.enable()
print "Content-type: text/html\n\n"
print
form=cgi.FieldStorage()
arg1 = form.getvalue('toggle-eq')
And then I do what I want to do with my arg1.
Now, what I want is, when you open the web interface page, to get the state of the raspberry component to initialize the toggle on the right position.
To do so I send a form on page load that launch a script looking at the state of the component. But how can I get it back in the html ?
I tried urllib and httplib2 but nothing worked for me... Any suggestions ?
Thanks