2015-07-28 26 views
0

我有這樣的代碼,獲取溫度傳感器在Python(樹莓PI)傳遞Python數據到PHP的Web服務器Apache的

import time 
def getTemp(str): 
     tempfile = open("/sys/bus/w1/devices/28-00000dw4adcc/w1_slave") 
     thetext = tempfile.read() 
     tempfile.close() 
     tempdata = thetext.split("\n")[1].split(" ")[9] 
     temperature = float(tempdata[2:]) 
     temperature = temperature/1000 
     print temperature 
getTemp(0) 

現在我該怎樣把它傳遞到index.php文件是在Apache服務器?

回答

0

您可以使用python將其寫入數據庫,並使用PHP讀取它。 最簡單的方法可能是在一個文件中寫:

的Python:

f = open('/tmp/temperature.txt', 'w') 
f.write(temperature) 
f.close() 

PHP:

$temperature = file_get_contents('/tmp/temperature.txt'); 
+0

OMG,我甚至沒有想到這一點。謝謝! – GProduct

+0

它不會工作,我們需要先將它轉換爲字符串,先溫度, – GProduct

+0

z = str(溫度),然後寫出 – GProduct

相關問題