-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmipi-1wire.pl
More file actions
68 lines (49 loc) · 1.35 KB
/
Copy pathmipi-1wire.pl
File metadata and controls
68 lines (49 loc) · 1.35 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /usr/bin/perl -w
use warnings;
use POSIX qw/strftime/;
#---------------------------Configure-----------------------------
#Put your web server directory here
$webdir = '/usr/share/nginx/www/';
#Max temp (C) - It will retry if higher than this
$maxtemp = 40;
#------------------------------------------------------------------
@list = `cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves`;
chomp(@list);
#Date/Time for manually seeing the file has been updated
$dt = strftime('%Y-%m-%d %H-%M',localtime);
$xml = "<a updated='$dt'>\n";
foreach $sen(@list) {
$c = 0;
#retry until we have a reasonable value
do {
#increase sleep with each retry
sleep $c;
$output = `cat /sys/bus/w1/devices/$sen/w1_slave`;
$output =~ /t=(?<temp>\d+)/;
$calc = $+{temp} / 1000;
$c += 1;
} while (($calc > $maxtemp || $calc == 0) && $c < 20);
#1 decimal place
$calc = sprintf("%.1f", $calc);
#Generate XML
$xml = $xml . "<owd>\n";
$xml = $xml . "<Name>DS18B20</Name>\n";
$xml = $xml . "<ROMId>$sen</ROMId>\n";
$xml = $xml . "<Temperature>$calc</Temperature>\n";
$xml = $xml . "</owd>\n";
sleep .1;
}
$xml = $xml . "</a>\n";
#debug mode
if ($#ARGV == 0) {
if ($ARGV[0] eq "-d") {
print $xml;
}
}
else
{
#write out the file
open DETAILS, '>', $webdir . 'details.xml';
print DETAILS $xml;
close DETAILS;
}