-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDS011_RPi_motta
More file actions
32 lines (24 loc) · 785 Bytes
/
SDS011_RPi_motta
File metadata and controls
32 lines (24 loc) · 785 Bytes
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
#!/usr/bin/env python3
#Dette programmet leser av innkommende bytes paa RPi serialport ttyAMA0,
#dekoder dataen og skriver den til en fil med et timestamp.
from time import gmtime, strftime
import serial
import time
f = open('sds011_logg.txt', 'w')
ser = serial.Serial("/dev/ttyAMA0", baudrate=9600, stopbits=1, parity="N", timeout=1)
while True:
tid = strftime("%Y-%m-%d %H:%M:%S")
in_data = ser.readline()
dekodet = in_data.decode('utf8')
#print ('Received: {0}\n'.format(str(in_data)))
#print(format(str(in_data)))
print(dekodet)
print(tid)
f.write(tid)
f.write(dekodet) #skriv til fil
f.write('\n\r')
f.close()
f=open('sds011_logg.txt', 'a')
ser.close()
ser.flush()
ser.open()