Jump to content

Python: Sensorwerte in CSV Datei ausgeben


FD

Recommended Posts

Hallo zusammen,

anbei mein Code zur Erstellung einer CSV Datei, in der die Luftfeuchtigkeit jede 5 min abgespeichert werden soll. Lass ich den Code so laufen, wird bei mir im Ordner eine CSV Datei erstellt in der die Werte abgespeichert werden. Nun meine Frage:

 

Ist es möglich, dass ich diesen Code als Porgramm auf den Red Brick hoch lade und mir die CSV Dateien auf dem Red gespeichert werden? Und wenn ja wie? (Ich möchte nicht den Brick Logger nutzen)

 

Vielen Dank euch.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from time import *

HOST = "localhost"
PORT = 4223

UID_Hum = "Hu"

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_humidity import BrickletHumidity


if __name__ == "__main__":
    
    #Verbindung zu Bricklets wird aufgebaut.
    ipcon = IPConnection()
    
    Hum = BrickletHumidity(UID_Hum, ipcon)   
    ipcon.connect(HOST, PORT) # Connect to brickd
   
    # Don't use device before ipcon is connected
    
    t = time()
    flag = False
    j = True
    
    while True:
    
        Time_akt = localtime()
        
        if ((Time_akt[4] == 0 or Time_akt[4] == 5 or Time_akt[4] == 10 or Time_akt[4] == 15 or Time_akt[4] == 20 or Time_akt[4] == 25 or Time_akt[4] == 30 or Time_akt[4] == 35 or Time_akt[4] == 40 or Time_akt[4] == 45 or Time_akt[4] == 50 or Time_akt[4] == 55)\
             and flag == False):
    
            flag = True
            print('Flag: ' + str(flag))
            #Sensoren auslesen alle 5min
            
            Luftfeuchtigkeit =  Hum.get_humidity()
            
                        
            #Akutelle Systemzeit auslesen
            Jahr = str(Time_akt[0])
            Monat = str(Time_akt[1])
            Tag = str(Time_akt[2])
            Stunde = str(Time_akt[3])
            Minute = str(Time_akt[4])
    
            #Sensordaten konvertieren und speichern
           
            Hum_str = str(Luftfeuchtigkeit)
           
            
            
            Ausgabe =   (Jahr+'.'+Monat+'.'+Tag+';'\
                        +Stunde+':'+Minute+';'\                        
                        +Hum_str+';'\                                               
                        +'\n')    
    
            filename = (Jahr+'_'+Monat+'_'+Tag+'_schnell'+'_'+'Data.csv')    
    
            data = open(filename,'a')    
            data.write(Ausgabe)
            data.close()
        
               
        if ((Time_akt[4] >= 1 and Time_akt[4] < 5) or\
             (Time_akt[4] >= 6 and Time_akt[4] < 10) or\
             (Time_akt[4] >= 11 and Time_akt[4] < 15) or\
             (Time_akt[4] >= 16 and Time_akt[4] < 20) or\
             (Time_akt[4] >= 21 and Time_akt[4] < 25) or\
             (Time_akt[4] >= 26 and Time_akt[4] < 30) or\
             (Time_akt[4] >= 31 and Time_akt[4] < 35) or\
             (Time_akt[4] >= 36 and Time_akt[4] < 40) or\
             (Time_akt[4] >= 41 and Time_akt[4] < 45) or\
             (Time_akt[4] >= 46 and Time_akt[4] < 50) or\
             (Time_akt[4] >= 51 and Time_akt[4] < 55) or\
             (Time_akt[4] >= 56 and Time_akt[4] < 60)):
                 
            flag = False   
        
        t = time()        
        
        if j == False:
            break    
    
    ipcon.disconnect()

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...