forked from omron-devhub/d7s-grove-raspberrypi
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main_sample.py
59 lines (44 loc) · 1.43 KB
/
main_sample.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
59
# coding: utf-8
# Sample that outputs the value acquired by D7S.
from __future__ import print_function
import os
import time
import datetime
import grove_d7s
from ambient_connector import AmbientConnector
# sensor instance
sensor = grove_d7s.GroveD7s()
# ambientをラップしたAmbientConnectorを使います
am = AmbientConnector()
def main():
while sensor.isReady() == False:
print('.')
time.sleep(1.0)
print("start")
while True:
# 1秒間隔でデータを取得する
time.sleep(1.0)
# センサーデータの取得
si = sensor.getInstantaneusSI()
pga = sensor.getInstantaneusPGA()
now = datetime.datetime.today()
eq = sensor.isEarthquakeOccuring()
# デバッグ用にデータを標準出力(本当は不要)
print(now.strftime("[%Y/%m/%d %H:%M:%S]"),
"SI={}[Kine]".format(si),
"PGA={}[gal]".format(pga),
"EQ=%s" % eq)
# センサーの初期化中は値がNoneになるので処理をスキップ
if si == None and pga == None:
continue
# Ambientに送信するペイロードを作成
payload = {
"d5": int(eq),
"d1": si,
"d2": pga,
"created": now.strftime("%Y/%m/%d %H:%M:%S")
}
# データをバッファーする
am.buffer(payload)
if __name__ == '__main__':
main()