-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfplug_log.py
More file actions
executable file
·50 lines (37 loc) · 1.01 KB
/
fplug_log.py
File metadata and controls
executable file
·50 lines (37 loc) · 1.01 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
F-Plug Logger
Copyright (C) 2014 SUNAGA Takahiro
This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
"""
import pyfplug
import sys
import threading
import time
duration = 2.0
fdev = pyfplug.FPlugDevice('/dev/rfcomm0')
fdev.led_on()
time.sleep(0.5)
fdev.led_off()
def print_now_data():
print "{time},{temperature},{humidity},{illuminance},{power}".format(time = time.time(), **fdev.get_data_dict())
sys.stdout.flush()
def main():
assert duration >= 1.0
next_time = time.time()
while True:
try:
print_now_data()
except UnknownState:
time.sleep(duration)
fdev.clear()
next_time = next_time + duration
next_time = next_time + duration
if next_time - time.time() < 0:
print >>sys.stderr, "Error: Too short duration"
continue
time.sleep(next_time - time.time())
if __name__ == '__main__':
main()