-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (50 loc) · 1.8 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ライブラリのインポート
import os
import sys
import datetime
import RPi.GPIO as GPIO
#自作ライブラリの場所を追加
sys.path.append(os.path.join(os.path.dirname(__file__),'./lib'))
sys.path.append(os.path.join(os.path.dirname(__file__),'./config'))
#自作ライブラリのインポート
import SoilMoisture as soil_moisture
import config_data as config_data
#処理概要 測定データをテキストファイルに書き出す
#引数 measured_data:測定データ、data_point:測定点数
#戻り値 なし
def Record_MeasurementData(measured_data):
data_point = config_data.MEASUREMENT_POINT
#書き込み先のファイル名を取得
now = datetime.datetime.now()
file_name = format(now.year,"#04d") \
+ format(now.month,"#02d") \
+ format(now.day,"#02d") + "_" \
+ format(now.hour,"#02d") \
+ "00.txt"
#ファイルがなければ新規作成
if not os.path.isfile("./raw_data/" + file_name):
f = open("./raw_data/" + file_name,"w")
f.write("date,t(ns)\r\n")
f.close()
#書き込みデータを作成
f = open("./raw_data/" + file_name,"a")
f.write(now.strftime('%04Y/%m/%d %H:%M:%S') + str("\n"))
for i in range(len(measured_data)):
f.write(str(measured_data[i]) + "\n")
f.close()
#処理概要 測定実行
#引数 data_point:測定点数
#戻り値 測定成否(0:成功、1:失敗)
def Execute():
#土壌水分の測定
ans,measured_data = soil_moisture.Get_SoilMoisture()
if ans == 0:
#土壌水分の記録
Record_MeasurementData(measured_data)
return(ans)
if __name__ == '__main__':
try:
ans = Execute()
sys.stdout.write(str(ans))
except KeyboardInterrupt:
pass