php, python, cgi, apache - Raspberry Pi Forums


hello everyone
followed tutorial http://www.raspberrypi-spy.co.uk/2013/1 ... n-mcp3008/
got working thank god, took me while came through.
question .i have server set on raspberry pi. how can make data running python script visible on webserver.
code working

code: select all

#!/usr/bin/python   import spidev import time import os   # open spi bus spi = spidev.spidev() spi.open(0,0)   # function read spi data mcp3008 chip # channel must integer 0-7 def readchannel(channel):   adc = spi.xfer2([1,(8+channel)<<4,0])   data = ((adc[1]&3) << 8) + adc[2]   return data   # function convert data voltage level, # rounded specified number of decimal places. def convertvolts(data,places):   volts = (data * 3.3) / float(1023)   volts = round(volts,places)   return volts   # function calculate temperature # tmp36 data, rounded specified # number of decimal places. def converttemp(data,places):     # adc value   # (approx)  temp  volts   #    0      -50    0.00   #   78      -25    0.25   #  155        0    0.50   #  233       25    0.75   #  310       50    1.00   #  465      100    1.50   #  775      200    2.50   # 1023      280    3.30     temp = ((data * 330)/float(1023))-50   temp = round(temp,places)   return temp   # define sensor channels light_channel = 0 temp_channel  = 1   # define delay between readings delay = 5   while true:     # read light sensor data   light_level = readchannel(light_channel)   light_volts = convertvolts(light_level,2)     # read temperature sensor data   temp_level = readchannel(temp_channel)   temp_volts = convertvolts(temp_level,2)   temp       = converttemp(temp_level,2)     # print out results   print "--------------------------------------------"   print("light: {} ({}v)".format(light_level,light_volts))   print("temp : {} ({}v) {} deg c".format(temp_level,temp_volts,temp))     # wait before repeating loop   time.sleep(delay)
again

for displaying python data on webpage, can use cgi. ;)

laurens


raspberrypi



Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support