FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nestgraph/insert.php at master · mycon/nestgraph · GitHub
mycon
/
nestgraph
Public
forked from
oyarzun/nestgraph
Notifications
You must be signed in to change notification settings
Fork
3
Star
11
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
nestgraph
/
insert.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (40 loc) · 1.87 KB
Breadcrumbs
nestgraph
/
insert.php
Copy path
File metadata and controls
47 lines (40 loc) · 1.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
require
'
inc/config.php
'
;
require
'
inc/class.db.php
'
;
require
'
collect.php
'
;
require
'
yahoo-api-master/YahooWeather.class.php
'
;
try
{
$
db
=
new
DB
(
$
config
);
$
temperature_units
=
strtolower
(
$
config
[
'
temperature_units
'
]);
//Yahoo now needs Oauth1 to get weather... fix later.
$
yahoo
=
new
YahooWeather
(
$
config
[
'
yh_consumerKey
'
],
$
config
[
'
yh_consumerKeySecret
'
],
$
config
[
'
yh_applicationId
'
], (
int
)
$
config
[
"
local_woeid
"
],
$
temperature_units
);
$
temperature
=
sprintf
(
"
%.02f
"
,
$
yahoo
->
getTemperature
(
false
));
$
humid
=
sprintf
(
"
%.02f
"
,
$
yahoo
->
getHumidity
(
false
));
$
pressure
=
sprintf
(
"
%.02f
"
,
$
yahoo
->
getPressure
(
false
));
//echo "Temperature:" . $temperature . "\n";
if
(
$
result
=
$
db
->
res
->
query
(
"
SELECT id, serial FROM devices
"
)) {
while
(
$
row
=
mysqli_fetch_row
(
$
result
)) {
$
data
=
get_nest_data
(
$
row
[
1
]);
//print_r($data);
if
(!
empty
(
$
data
[
'
timestamp
'
]))
{
if
(
$
stmt
=
$
db
->
res
->
prepare
(
"
REPLACE INTO data (device_id, timestamp, heating, cooling, fan, autoAway, manualAway, leaf, target, target2, current, humidity, outsideTemperature,outsideHumidity,outsidePressure, updated)
"
.
"
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())
"
))
{
$
stmt
->
bind_param
(
"
isiiiiiidddiiii
"
,
$
row
[
0
],
$
data
[
'
timestamp
'
],
$
data
[
'
heating
'
],
$
data
[
'
cooling
'
],
$
data
[
'
fan
'
],
$
data
[
'
autoAway
'
],
$
data
[
'
manualAway
'
],
$
data
[
'
leaf
'
],
$
data
[
'
target_temp
'
],
$
data
[
'
target_temp2
'
],
$
data
[
'
current_temp
'
],
$
data
[
'
humidity
'
],
$
temperature
,
$
humid
,
$
pressure
);
if
(!
$
stmt
->
execute
())
{
echo
"
Execute failed: (
"
.
$
stmt
->
errno
.
"
)
"
.
$
stmt
->
error
;
}
$
stmt
->
close
();
}
}
}
mysqli_free_result
(
$
result
);
}
$
db
->
close
();
}
catch
(
Exception
$
e
) {
$
errors
[] = (
"
DB connection error! <code>
"
.
$
e
->
getMessage
() .
"
</code>.
"
);
}
?>
Back
|
FazBrowse Home
|
New Git URL