forked from MarcDorval/TeleinfoLinky
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteleinfo.py
More file actions
53 lines (48 loc) · 1.49 KB
/
teleinfo.py
File metadata and controls
53 lines (48 loc) · 1.49 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
51
#!/usr/bin/python
import serial
import time
import sys
baudrate=9600
ser = serial.Serial('/dev/ttyAMA0', baudrate, bytesize=7, timeout=1)
ser.isOpen()
count=0
looping = 1
results_table=""
try:
# print "...demarrage du mode standard a "+str(baudrate)+"... "
while looping:
response = ser.readline()
localtime = time.asctime( time.localtime(time.time()) )
# print "count "+str(count)
count = count + 1
if count >= 100:
looping = 0
if response != "":
count = count - 1
# The line is not empty, let's go on...
items = response.split()
splitLen = len(items)
if splitLen >= 2:
# There are 3 items in the line, as expected, let's go on...
print str(splitLen)+" items : "+response
item = items[0]
value = items[splitLen-2]
if item in sys.argv or "all" in sys.argv:
if value.isdigit():
# Remove leading zeros from numerical values
value_int = int(value)
value = str(value_int)
if not "all" in sys.argv:
print " "+item+" "+value
filename = "/home/pi/teleinfo/"+item
file_object = open(filename, 'w')
result = localtime + " " + item + " " + value
file_object.write(result)
file_object.close( )
if "all" not in sys.argv:
if "loop" not in sys.argv:
sys.argv.remove(item)
if len(sys.argv) == 1:
break;
except KeyboardInterrupt:
ser.close()