-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphreader.php
More file actions
92 lines (70 loc) · 2.68 KB
/
phreader.php
File metadata and controls
92 lines (70 loc) · 2.68 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
pHpReader - reading pH values from atsci_ph.
Copyright (C) 2017 Ole-Henrik Jakobsen
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This is a PHP-CLI script made to pick up values from AtlasScientific program.
Configure config.ini to choose which sensor to use.
Requirements: php-cli atlas_scientific (git clone https://github.com/jvsalo/atlas_scientific.git)
Last updated: 2018-03-19
*/
chdir(dirname(__FILE__));
$ini_file = "config.ini";
$ini_array = parse_ini_file($ini_file, true);
// get temperature
if(@$ini_array["tempreader"]["TEMPREADERPATH"] && @is_file("" . @$ini_array["tempreader"]["TEMPREADERPATH"] . "/tempreader.php")) {
$argv1 = @$argv[1]; // save argv[1]
$argv[1] = ""; // reset argv[1] - conflicts with tempreader
$tempreadersensor = $ini_array["tempreader"]["TEMPREADERSENSOR"];
$tempreaderserial = $ini_array["tempreader"]["TEMPREADERSENSORSERIAL"];
chdir($ini_array["tempreader"]["TEMPREADERPATH"]);
include_once("" . $ini_array["tempreader"]["TEMPREADERPATH"] . "/tempreader.php");
$tempreader = tempreader();
$temperature = round(@$tempreader[$tempreadersensor]["data"][$tempreaderserial], 1);
// get back to current directory
chdir(dirname(__FILE__));
// restore argv[1]
$argv[1] = $argv1;
// get the config again because of tempreader
$ini_array = parse_ini_file($ini_file, true);
}
else {
$temperature = @$ini_array["settings"]["TEMPERATURE"];
}
// put array data into variables
$test = @$ini_array["settings"]["TEST"];
$sensor = @$ini_array["settings"]["SENSOR"];
function phreader($temperature = 25) {
global $ini_array;
global $sensor;
global $test;
if(!$test) { $test = 0; }
// get readings from sensor
include("sensors/" . $sensor . ".php");
if($phreader) {
return $phreader_value;
}
else {
return false;
}
}
if(!@$test && @$argc && @is_file("" . @dirname(__FILE__) . "/sensors/" . $argv[1] . ".php")) {
$phreader_cli = phreader($temperature);
print(@$phreader_cli); print("\n");
}
else if(!@$test) {
die("\nError: please specify a valid pH sensor. You typed: $argv[1]\n");
}
if($test) {
phreader($temperature);
}
?>