Merci a tous Super ça fonctionne .
J'ai bricolé ce code que j'ai posté , pour essayé de comprendre le fonctionnement de la création et de l’écriture du fichier histINT.
je pensais pouvoir me débrouiller seul pour adapter ça a mon fichier howonpi .Mais ce n'est pas du tout le cas .
sensorInfo n'est pas bon , je récupère trop d'information .
Sat Apr 25 13:10:04 2015 /[['TDS1', '28-000005239592', 'T\xb0Interieure', 19.0]]
#!/usr/bin/env python# -*- coding: utf-8 -*-""" Scan all sensors from DS18B20.conf store data into rrdtool database export chart data """importlocaleimportdatetimeimporttimeimportsubprocessimportosimportsysimportshleximportDS18B20fromreimportsearchDS=DS18B20.DS18B20()#fonction pour changer le language de la date en anglaisdefget_c_locale_abbrev():lc=locale.setlocale(locale.LC_TIME)try:locale.setlocale(locale.LC_TIME,"C")returntime.strftime("%a %b %d %H:%M:%S %Y")finally:locale.setlocale(locale.LC_TIME,lc)#first read configuration to get DS18B20 ID and label infotry:fileH=open("/home/www/Graph/DS18B20.conf")text=fileH.read()fileH.close()sensorInfo=[s.strip().split(',')forsintext.splitlines()]except:print("Unable to read 'DS18B20.conf'")quit()NumberOfSensor=len(sensorInfo)ifNumberOfSensor==0:print("No sensor in configuration file 'DS18B20.conf'. Exit!")quit()#get Temperature of each sensor#add add it up into the sensor InfoforiinsensorInfo:i.append(DS.read(i[1]))#let's update the current status file#if the value is None just put ---defvalidatePrint(value):ifvalue==None:return"---"else:return"{}".format(value)#if the value is None tell rrdtool that the value is unknowndefvalidateRRD(value):ifvalue==None:return":U"else:return":{}".format(value)''' ********** Ici c'estlefichierhist-INTcefichierestcrééavecunmodulus%5delaminute.Donc5fichierenalternanceetledernierseraunlinksurhist-INTpourpermettred'utiliser hist-INT sans avoir de problème de lecture lorsque le fichier ce fait écrire '''#current timecurrent_time=datetime.datetime.now()histINT="/home/www/logs/hist-INT"#Nom des fichierTemp_histINT=histINT+"{}".format(current_time.minute%5)+".txt"Link_histINT=histINT+".txt"#creation du fichier modulus#try:ifTrue:sfile=open(Temp_histINT,'w')sfile.write(get_c_locale_abbrev()+" /"+validatePrint(sensorInfo))sfile.close()#creation du link os.symlink ne marche pas si le fichier est déja linké#os.symlink(Temp_histINT,Link_histINT)subprocess.Popen(["/bin/ln","-fs",Temp_histINT,Link_histINT])#except:# print("unable to create {}".format(Temp_histINT)) webdata="/home/www/Graph/webdata/"currentStatus=webdata+"DS18B20Status.txt"try:sfile=open(currentStatus,'w')forsensorinsensorInfo:sfile.write(sensor[0])sfile.write(","+sensor[1])sfile.write(","+sensor[2])sfile.write(","+validatePrint(sensor[3])+"\n")sfile.close()except:print("unable to create '/home/www/Graph/webdata/DS18B20Status.txt'")#now let's insert the result into rrdtool databasefileRrdTool="/home/www/Graph/data_DS18B20.rrd"#let's fill the command line with the #Current time (Right now)rdata="N"#add the sensors resultforsensorinsensorInfo:rdata=rdata+validateRRD(sensor[3])#now update the databasesubprocess.Popen(["/usr/bin/rrdtool","update",fileRrdTool,rdata])#data Extraction to create data point for the charts.#create a function with start and step parameters#this way we could create chart with different timingdefrrdExport(start,step,XMLfile):texte="rrdtool xport -s {0} -e now --step {1} ".format(start,step)#let's populate for each sensorforiinrange(NumberOfSensor):texte+="DEF:{}={}:{}:AVERAGE ".format(chr(ord('a')+i),fileRrdTool,sensorInfo[i][0])texte+="XPORT:{}:""{}"" ".format(chr(ord('a')+i),sensorInfo[i][2])fileout=open(webdata+XMLfile,"w")args=shlex.split(texte)subprocess.Popen(args,stdout=fileout)fileout.close()# ok extact 3 hours datarrdExport("now-3h",300,"temperature3h.xml")#ok 24 hoursrrdExport("now-24h",900,"temperature24h.xml")#ok 48 hoursrrdExport("now-48h",1800,"temperature48h.xml")#ok 1 weekrrdExport("now-8d",3600,"temperature1w.xml")#ok 1 monthrrdExport("now-1month",14400,"temperature1m.xml")#ok 3 monthrrdExport("now-3month",28800,"temperature3m.xml")#ok 1 yearrrdExport("now-1y",43200,"temperature1y.xml")#ok just print on the screen what we haveforsensorinsensorInfo:print("{}:{}".format(sensor[2],validatePrint(sensor[3])))#done
[^] # Re: Est-ce que tu as un message d'erreur ?
Posté par b.gwen . En réponse au message Ecriture fichier txt. Évalué à 1.
Merci a tous Super ça fonctionne .
J'ai bricolé ce code que j'ai posté , pour essayé de comprendre le fonctionnement de la création et de l’écriture du fichier histINT.
je pensais pouvoir me débrouiller seul pour adapter ça a mon fichier howonpi .Mais ce n'est pas du tout le cas .
Pour écrire dans histINT j'ai fais ca .
sensorInfo n'est pas bon , je récupère trop d'information .
Sat Apr 25 13:10:04 2015 /[['TDS1', '28-000005239592', 'T\xb0Interieure', 19.0]]