Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import cgi, rrdtool, os
- import cgitb; cgitb.enable() # for troubleshooting
- print "Content-type: text/html"
- print
- print """
- <html>
- <head><title>Sensor data</title></head>
- <body>
- <h3>Sensor data</h3>
- """
- form = cgi.FieldStorage()
- sensor = form.getvalue("sensor")
- temp = form.getvalue("temp")
- hum = form.getvalue("hum")
- vbat = form.getvalue("vbat")
- if (sensor == "mobile"):
- tempstring = "N:"+temp+":"+hum+":"+vbat
- tempdata = temp+"\n"+hum+"\n"+vbat+"\n"
- rrdfile = "/var/www/rrd/mobile.rrd"
- tempfile = "/var/www/rrd/temp_mobile.txt"
- print 'Sensor:'+sensor+': '+temp+' deg. C, '+hum+' rh, Voltage '+vbat+' V.<br>'
- elif (sensor == "bedroom"):
- tempstring = "N:"+temp+":"+hum
- tempdata = temp+"\n"+hum+"\n"
- rrdfile = "/var/www/rrd/bedroom.rrd"
- tempfile = "/var/www/rrd/temp_bedroom.txt"
- print 'Sensor:'+sensor+': '+temp+' deg. C, '+hum+' rh.<br>'
- elif (sensor == "livingroom"):
- tempstring = "N:"+temp+":"+hum
- tempdata = temp+"\n"+hum+"\n"
- rrdfile = "/var/www/rrd/livingroom.rrd"
- tempfile = "/var/www/rrd/temp_livingroom.txt"
- print 'Sensor:'+sensor+': '+temp+' deg. C, '+hum+' rh.<br>'
- elif (sensor == "workroom"):
- tempstring = "N:"+temp+":"+hum
- tempdata = temp+"\n"+hum+"\n"
- rrdfile = "/var/www/rrd/workroom.rrd"
- tempfile = "/var/www/rrd/temp_workroom.txt"
- print 'Sensor:'+sensor+': '+temp+' deg. C, '+hum+' rh.<br>'
- elif (sensor == "bath"):
- tempstring = "N:"+temp+":"+hum
- tempdata = temp+"\n"+hum+"\n"
- rrdfile = "/var/www/rrd/bath.rrd"
- tempfile = "/var/www/rrd/temp_bath.txt"
- print 'Sensor:'+sensor+': '+temp+' deg. C, '+hum+' rh.<br>'
- elif (sensor == "kitchen"):
- tempstring = "N:"+temp+":"+hum
- tempdata = temp+"\n"+hum+"\n"
- rrdfile = "/var/www/rrd/kitchen.rrd"
- tempfile = "/var/www/rrd/temp_kitchen.txt"
- print 'Sensor:'+sensor+': '+temp+' deg. C, '+hum+' rh.<br>'
- elif (sensor == "outdoor"):
- tempstring = "N:"+temp+":"+hum
- tempdata = temp+"\n"+hum+"\n"
- rrdfile = "/var/www/rrd/outdoor.rrd"
- tempfile = "/var/www/rrd/temp_outdoor.txt"
- print 'Sensor:'+sensor+': '+temp+' deg. C, '+hum+' rh.<br>'
- rrdtool.update(rrdfile, tempstring)
- tempfile=open(tempfile, "wb")
- tempfile.write(tempdata)
- tempfile.close()
- print """
- </body>
- </html>
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement