Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import tornado.ioloop
- import tornado.web
- MIN_TEMP = 0
- ERROR_TEMP = -999.99
- TEMP_SENSORS = {
- "28-00043a4518ff" : {"label":"A","location":"Server-1-Front","temperature":None},
- "28-00043b61b4ff" : {"label":"B","location":"Server-1-Back","temperature":None},
- "28-00043e827cff" : {"label":"C","location":"Server-2-Front","temperature":None},
- "28-00043a52a1ff" : {"label":"D","location":"Server-2-Back","temperature":None},
- "28-00043b6803ff" : {"label":"E","location":"Server Room Ambient","temperature":None},
- }
- def read_temperature(sensor):
- tfile = open("/sys/bus/w1/devices/{0}/w1_slave".format(sensor))
- text = tfile.read()
- tfile.close()
- lines = text.split("\n")
- if lines[0].find("YES") > 0:
- temp = float((lines[1].split(" ")[9])[2:])
- temp /= 1000
- return temp
- return ERROR_TEMP
- class MainHandler(tornado.web.RequestHandler):
- def get(self):
- self.write("Hello, world")
- class TempHandler(tornado.web.RequestHandler):
- def get(self):
- temps = {}
- for rrd in TEMP_SENSORS:
- #temp = read_temperature(TEMP_SENSORS[rrd])
- TEMP_SENSORS[rrd]['temperature'] = read_temperature(rrd)
- response = { 'controller':{'location': 'Server Room','hardware':'raspberrypib+'},
- 'sensors': TEMP_SENSORS,}
- self.write(response)
- application = tornado.web.Application([
- (r"/", MainHandler),
- (r"/temperatures", TempHandler),
- ])
- if __name__ == "__main__":
- application.listen(8888)
- tornado.ioloop.IOLoop.instance().start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement