Ich bin stark versucht, komplett von PHP auf Python umzustellen. Für die Erstellung von Graphen sind die Vorteile massiv. Hier ein Paar 1-wire Temperaturauslesungen. Ich lasse IPS die Werte in Postgres speichern, aber es würde auch mit SQLite ganz ähnlich gehen.
#!/usr/bin/python3.4
import psycopg2, numpy as np
import pylab as plt
import datetime
import matplotlib.pyplot as plt
def thermometerQuery(thermoID):
try:
conn = psycopg2.connect("dbname='IpsLogging' user='***' host='*.*.*.*' password='***'")
except:
try:
conn = psycopg2.connect("dbname='IpsLogging' user='ips' host='***.com' password='IPS'")
except:
print ("I am unable to connect to the database")
cur = conn.cursor()
sqlStatement = """SELECT * \
FROM
"ips_integerWithObjectName"
WHERE
(varid = %d)
; """ \
% thermoID
cur.execute(sqlStatement)
return np.asarray(cur.fetchall())
thermoID_Alarmschrank= "placeholder"
thermoID_ProjectorNiche= [["", 17884], ["", 55437], ["", 34637],["", 17333]] # IDs of Thermoprobes in Projectorniche
thermoIDs_Ankleide = [["temp_lancom_switch", 21633],["temp_led_trafo", 54268],["temp_pokey_case", 34850]] # IDs of Thermoprobes in Ankleideschrank
mappedcolor = 0
for thermoID in thermoIDs_Ankleide:
mappedcolor = mappedcolor + 0.2
thermoValues = thermometerQuery(thermoID[1])
# make plots
plt.figure(1)
plt.rcParams.update({'font.size': 8})
plt.subplots_adjust(left=0.07, bottom=0.08, right=.9, top=.81, wspace=.77, hspace=1)
plotTimeRange = [1,10,100,365] # date range of subplots (days)
for subplotnumber in range(0,4):
plt.subplot(411+subplotnumber)
ax = plt.gca()
if (subplotnumber==0):
plt.scatter(thermoValues[:,1], thermoValues[:,2],
label=thermoID[0], s=1.5, color=plt.cm.hot(mappedcolor))
ax.legend(loc='upper center', bbox_to_anchor=(0.5, 2), fancybox=True, shadow=True)
else:
plt.plot(thermoValues[:,1], thermoValues[:,2], label=thermoID[0])
ax.set_autoscale_on(False)
plt.grid()
plt.ylim((1500, 4000)) #temperature range of ordinate (y axis)
plt.xlim((datetime.datetime.now()
-datetime.timedelta(days=plotTimeRange[subplotnumber]),
datetime.datetime.now()))
# beautify the x-labels
plt.setp(plt.xticks()[1], rotation=30, ha='right') # ha is the same as horizontalalignment
#plt.show()
plt.savefig('C:/Users/***/Google Drive/python/thermoplot_projniche.png',
dpi=600, facecolor='w', edgecolor='g',
orientation='portrait', papertype=None, format=None,
transparent=True, bbox_inches=None, pad_inches=0.1,
frameon=None)