831e4aa2593ec0912607278c910cbdd482088fd0
6 from time
import strftime
9 os
.system('modprobe w1-gpio')
10 os
.system('modprobe w1-therm')
12 base_dir
= '/sys/bus/w1/devices/'
13 device_folder
= glob
.glob(base_dir
+ '28*')[0]
14 device_file
= device_folder
+ '/w1_slave'
17 f
= open(device_file
, 'r')
23 lines
= read_temp_raw()
24 while lines
[0].strip()[-3:] != 'YES':
26 lines
= read_temp_raw()
27 equals_pos
= lines
[1].find('t=')
29 temp_string
= lines
[1][equals_pos
+2:]
30 temp_c
= float(temp_string
) / 1000.0
31 temp_f
= temp_c
* 9.0 / 5.0 + 32.0
32 temp_c_2dec
= f
"{temp_c:.5f}" # https://stackoverflow.com/a/15263885/10850071
33 #return temp_c, temp_f
37 myHostname
= socket
.gethostname()
40 nowTimeIso8601
= strftime("%Y%m%dT%H%M%S%z")
41 nowTimeUE
= strftime("%s")
43 print(str(nowTimeIso8601
) + ',' + str(nowTimeUE
) + ',' + str(myHostname
) + ',' + str(nowTemp
))