For only a handful of sensors (20 or so) would not be a performance issue, even for a model A. You would still have a large overhead to work with.murkata86 wrote:Thank you for your response!
I was thinking about this as well, but won't this cause some performance issues as Python will be writing to the database while the app is running and with AJAX will be querying all the time as well.
I've shared my problem with a friend of mine and he mentioned something about sockets and I've checked in the Internet (as I'm not aware of the sockets at all), but all the examples were not working for me...
Code: Select all
<?php $output = shell_exec("your_script.py"); echo "output :".$output.; ?>
Code: Select all
#!/usr/bin/python import os import time import datetime import glob import MySQLdb from time import strftime #Uncomment for Live Temp Sensors os.system('modprobe w1-gpio') os.system('modprobe w1-therm') #Live Temp Sensors poolTempSensor = '/sys/bus/w1/devices/28-0214632d15ff/w1_slave' outsideTempSensor = '/sys/bus/w1/devices/28-03146315efff/w1_slave' #Test Temp Sensors #poolTempSensor = '/opt/code/tempSensor/devices/28-000003cee4ca/w1_slave' #outsideTempSensor = '/opt/code/tempSensor/devices/28-000003cee5ca/w1_slave' # Variables for MySQL db = MySQLdb.connect(host="localhost", user="XXXXXX",passwd="XXXXXX", db="XXXXXX") cur = db.cursor() #Reading Pool Temp Data def readPoolTempRaw(): pt = open(poolTempSensor, 'r') lines = pt.readlines() pt.close() return lines def readPoolTemp(): lines = readPoolTempRaw() while lines.strip()[-3:] != 'YES': time.sleep(0.2) lines = readPoolTempRaw() poolTemp = lines.find('t=') if poolTemp != -1: tempString = lines[poolTemp+2:] poolTempC = float(tempString) / 1000.0 poolTempF = poolTempC * 9.0 / 5.0 + 32.0 return ("%.f" %poolTempF) #Reading Outside Temp Data def readOutsideTempRaw(): ot = open(outsideTempSensor, 'r') lines = ot.readlines() ot.close() return lines def readOutsideTemp(): lines = readOutsideTempRaw() while lines.strip()[-3:] != 'YES': time.sleep(0.2) lines = readOutsideTempRaw() outsideTempOutput = lines.find('t=') if outsideTempOutput != -1: tempString = lines[outsideTempOutput+2:] outsideTempC = float(tempString) / 1000.0 outsideTempF = outsideTempC * 9.0 / 5.0 + 32.0 return ("%.f" %outsideTempF) while True: #print (readPoolTemp()) #print (readOutsideTemp()) poolTemp = readPoolTemp() outsideTemp = readOutsideTemp() datetimeWrite = (time.strftime("%Y-%m-%d ") + time.strftime("%H:%M:%S")) # SQL Statement sql = ("""INSERT INTO tempLog (dateTime,poolTemp,outsideTemp) VALUES (%s,%s,%s)""",(datetimeWrite,poolTemp,outsideTemp)) # Execute the SQL command cur.execute(*sql) # Commit your changes in the database db.commit() #cur.close() #db.close() time.sleep(3600)
The Foundations weather station does exactly what you want - you'll need to change it for the particular sensors you are using of course.murkata86 wrote:Hi All,
I have Raspberry Pi 2 with Raspbian OS. Recently I've purchased the Adafruit MCP9808 temperature sensor and wired it to the Pi. I've downloaded the library Adafruit has provided:
https://learn.adafruit.com/mcp9808-temp ... y/software
Everything is working fine, but I want to display the sensor readings in a web page and temperatur should be dynamically updated.
Does anyone know how this can be done or is there a similar example?
Thanks for your help!