Thanks for response. I read something and here I am now.
this is ajax that call python
Code: Select all
function sensor(){
$.ajax({
type:"POST",
url:"/python/sensor.py",
dataType:"text",
success: function(msg){
alert("script returned:" + msg)
}
});
}
my python script that read temperature and pressure from sensor:
Code: Select all
#!/usr/bin/env/ python
import Adafruit_BMP.BMP0855 as BMP085
import cgitb
cgitb.enable()
sensor = BMP085.BMP085()
temp = sensor.read_temperature()
pressure = sensor.read_pressure()
print ("Content-Type: text/html;charset=utf-8")
print ('Temp ={0:0.2f} *C'.format(temp))
print ('Pressure = {0:0.1f} kPa'.format(pressure/1000))
when i call function sensor() I get this :
Code: Select all
script returned#!/usr/bin/env/ python
import Adafruit_BMP.BMP0855 as BMP085
import cgitb
cgitb.enable()
sensor = BMP085.BMP085()
temp = sensor.read_temperature()
pressure = sensor.read_pressure()
print ("Content-Type: text/html;charset=utf-8")
print ('Temp ={0:0.2f} *C'.format(temp))
print ('Pressure = {0:0.1f} kPa'.format(pressure/1000))
So it seems like ajax just take code from python script and save it to variable msg
