You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
629 B
21 lines
629 B
import csv
|
|
import datetime
|
|
import random
|
|
|
|
# definice senzorů
|
|
senzory = ["DHT11 vlhkost", "DHT11 teplota","HC-SR04 vzdálenost"]
|
|
|
|
#otevření souboru
|
|
with open("data.csv","a",newline="") as csvfile:
|
|
writer = csv.writer(csvfile) #zapisovatel
|
|
now = datetime.datetime.now() #aktualni datum a cas
|
|
if csvfile.tell() == 0:
|
|
writer.writerow(["Datum a cas"]+[senzor for senzor in senzory])
|
|
|
|
hodnoty = [
|
|
random.randint(30,80), #vlhkost
|
|
random.randint(20,28), #teplota
|
|
random.randint(20,200) #vzdalenost
|
|
]
|
|
#zapis dat
|
|
writer.writerow([now.strftime("%Y-%m-%d %H:%M:%S")] + hodnoty)
|