update scrittura file
This commit is contained in:
+29
-9
@@ -14,12 +14,17 @@ redSrv0 = redis.Redis(
|
||||
port=REDIS_PORT,
|
||||
db=0)
|
||||
|
||||
#funzione per leggere e decodificare da redis
|
||||
def getRedisVal(redisKey):
|
||||
return redSrv0.get(redisKey).decode('utf-8')
|
||||
|
||||
|
||||
redSrv0.set('SETTINGS:LOG:STATUS',0)
|
||||
|
||||
#se non c'è un valore nei campi di redis, popolo il db
|
||||
|
||||
LOG_path = "/home/pi/Flythis/logger/log/"
|
||||
DATA_path = "/home/pi/Flythis/logger/data/"
|
||||
DATA_path = "/home/pi/data/"
|
||||
|
||||
if redSrv0.get('SETTINGS:SELECTED_CH') is None:
|
||||
redSrv0.set('SETTINGS:SELECTED_CH',0)
|
||||
@@ -52,16 +57,30 @@ try:
|
||||
for chIndex in range(0,8,+1):
|
||||
print("CH "+str(chIndex)+"= %lf"%(CHvalue[chIndex]*5.0/0x7fffff))
|
||||
|
||||
#funzione salva time+data e otto valori letti su file
|
||||
#funzione salva time+data e otto valori letti su file (SE LOG è 1)
|
||||
def fileSave(CHvalue):
|
||||
csvDataFormat = "%Y/%m/%d %H:%M:%S"
|
||||
dataFileName = getRedisVal('RTDATA:SESSION:NAME')
|
||||
try:
|
||||
logFile = open(LOG_path, "a")
|
||||
outFile = open(DATA_path+"/"+dataFileName, "a")
|
||||
except FileNotFoundError:
|
||||
print("Creating new PyLog.txt")
|
||||
logFile = open(LOG_path, "w+")
|
||||
logFile.write("\nTime: "+str(now))
|
||||
for chIndex in range(0,8,+1):
|
||||
logFile.write(" | CH "+str(chIndex)+" = %lf"%(CHvalue[chIndex]*5.0/0x7fffff))
|
||||
print("Creating new data.csv")
|
||||
outFile = open(DATA_path+"/"+dataFileName, "w+")
|
||||
outFile.write("# LOG started at " + str(now))
|
||||
|
||||
# dichiaro una stringa in cui accumulo i valori
|
||||
lastDate = datetime.now()
|
||||
csvRow = str(now) +","
|
||||
for chIndex in range(0,2,+1):
|
||||
channelOut = getRedisVal('RTDATA:OUT:'+str(chIndex))
|
||||
csvRow += channelOut+","
|
||||
|
||||
# tolgo ultimo ","
|
||||
l = len(csvRow)
|
||||
csvRow = csvRow[:l-1]
|
||||
# scrivo in blocco la riga dei valori
|
||||
outFile.write(csvRow +"\r\n")
|
||||
outFile.close()
|
||||
|
||||
#funzione salva time+data di log e otto valori su redis
|
||||
def redisSave(CHvalue):
|
||||
@@ -118,7 +137,8 @@ try:
|
||||
#if logStatus == "1" :
|
||||
CHvalue = CH.ADS1256_GetAll()
|
||||
#videoPrint(CHvalue)
|
||||
#fileSave(CHvalue)
|
||||
if(getRedisVal('SETTINGS:LOG:STATUS') == "1"):
|
||||
fileSave(CHvalue)
|
||||
redisSave(CHvalue)
|
||||
time.sleep(int(redSrv0.get(redSampleFreq))/1000)
|
||||
|
||||
|
||||
@@ -21,3 +21,17 @@
|
||||
2021-03-29 13:12:47.701751 Program end. Ctrl+C from user
|
||||
2021-03-29 14:49:22.191222 Program end. Ctrl+C from user
|
||||
2021-03-29 15:04:18.258773 Program end. Ctrl+C from user
|
||||
2021-03-30 08:54:50.480755 Program end. Ctrl+C from user
|
||||
2021-03-30 08:55:09.628193 Program end. Ctrl+C from user
|
||||
2021-03-30 08:57:11.032414 Program end. Ctrl+C from user
|
||||
2021-03-30 08:57:17.269880 Caught error: can only concatenate str (not "bytes") to str
|
||||
2021-03-30 08:58:02.637416 Caught error: can only concatenate str (not "bytes") to str
|
||||
2021-03-30 08:59:26.917913 Caught error: can only concatenate str (not "bytes") to str
|
||||
2021-03-30 09:00:48.338924 Caught error: can only concatenate str (not "bytes") to str
|
||||
2021-03-30 09:01:36.599414 Caught error: can only concatenate str (not "bytes") to str
|
||||
2021-03-30 09:02:03.091920 Caught error: can only concatenate str (not "bytes") to str
|
||||
2021-03-30 09:02:58.740174 Program end. Ctrl+C from user
|
||||
2021-03-30 09:10:26.654282 Program end. Ctrl+C from user
|
||||
2021-03-30 09:10:32.675386 Caught error: strftime() argument 1 must be str, not builtin_function_or_method
|
||||
2021-03-30 09:11:57.923154 Caught error: module 'datetime' has no attribute 'now'
|
||||
2021-03-30 09:13:27.237961 Caught error: module 'datetime' has no attribute 'now'
|
||||
|
||||
@@ -167,7 +167,7 @@ def start_log():
|
||||
#data e time ora
|
||||
lastDate = datetime.now()
|
||||
#formato per data e time: dd/mm/YYYY H:M:S
|
||||
format = "%d/%m/%Y_%H:%M:%S"
|
||||
format = "%Y%m%d_%H%M%S"
|
||||
#format date e time adando strftime()
|
||||
nameDate = lastDate.strftime(format) + ".csv"
|
||||
redSrv0.set('RTDATA:SESSION:NAME', nameDate)
|
||||
|
||||
Reference in New Issue
Block a user