Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sensor-class
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonathan Weth
sensor-class
Commits
34c53953
Verified
Commit
34c53953
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add Influx to temp
parent
06a75712
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
temp.py
+39
-12
39 additions, 12 deletions
temp.py
with
39 additions
and
12 deletions
temp.py
+
39
−
12
View file @
34c53953
...
@@ -7,10 +7,20 @@ import datetime
...
@@ -7,10 +7,20 @@ import datetime
import
numpy
import
numpy
import
requests
import
requests
from
gpiozero
import
Button
from
gpiozero
import
Button
from
influxdb
import
InfluxDBClient
BASE_URL
=
"
http://energie.intern/api/
"
BASE_URL
=
"
http://energie.intern/api/
"
client
=
InfluxDBClient
(
'
srv.jonathanweth.de
'
,
8086
,
'
root
'
,
'
root
'
,
'
room_sensors
'
)
client
.
create_database
(
'
room_sensors
'
)
tags
=
{
"
room
"
:
"
012
"
,
"
scenario
"
:
"
ventilate-20
"
}
def
temp_it
():
def
temp_it
():
while
True
:
while
True
:
...
@@ -57,16 +67,6 @@ def temp_it():
...
@@ -57,16 +67,6 @@ def temp_it():
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
# Load config
# conf_file = open("config.json", "r")
#config = json.load(conf_file)
#conf_file.close()
#room = config.get("room_id")
#api_key = config.get("room_api_key")
# Log config
#log.log("Read data for room: " + room + "\n")
windows
=
[
20
,
26
]
windows
=
[
20
,
26
]
buttons
=
{}
buttons
=
{}
...
@@ -76,14 +76,34 @@ if __name__ == "__main__":
...
@@ -76,14 +76,34 @@ if __name__ == "__main__":
buttons
[
window
]
=
Button
(
window
)
buttons
[
window
]
=
Button
(
window
)
for
temps
,
temp_count
in
temp_it
():
for
temps
,
temp_count
in
temp_it
():
json_body
=
[]
########
########
# TEMP #
# TEMP #
########
########
for
i
,
temp
in
enumerate
(
temps
):
json_body
.
append
({
"
measurement
"
:
f
"
temp_
{
i
}
"
,
"
tags
"
:
tags
,
"
fields
"
:
{
"
value
"
:
temp
}
})
# Calculate average
# Calculate average
avg_temp
=
numpy
.
mean
(
temps
)
avg_temp
=
numpy
.
mean
(
temps
)
avg_temp
=
float
(
"
%.2f
"
%
avg_temp
)
avg_temp
=
float
(
"
%.2f
"
%
avg_temp
)
json_body
.
append
({
"
measurement
"
:
"
avg_temp
"
,
"
tags
"
:
tags
,
"
fields
"
:
{
"
value
"
:
avg_temp
}
})
# Log average and time to console
# Log average and time to console
print
(
"
Measured temperatures:
"
+
str
(
temps
))
print
(
"
Measured temperatures:
"
+
str
(
temps
))
print
(
"
Logged data:
"
+
str
(
datetime
.
datetime
.
now
())[
0
:
10
]
+
"
,
"
+
print
(
"
Logged data:
"
+
str
(
datetime
.
datetime
.
now
())[
0
:
10
]
+
"
,
"
+
...
@@ -96,14 +116,21 @@ if __name__ == "__main__":
...
@@ -96,14 +116,21 @@ if __name__ == "__main__":
# Get windows status
# Get windows status
window_data
=
{}
window_data
=
{}
for
window
in
windows
:
for
i
,
window
in
enumerate
(
windows
)
:
# Add one window to data
# Add one window to data
json_body
.
append
({
"
measurement
"
:
f
"
window_
{
i
}
"
,
"
tags
"
:
tags
,
"
fields
"
:
{
"
value
"
:
buttons
[
window
].
is_pressed
}
})
window_data
[
window
]
=
buttons
[
window
].
is_pressed
window_data
[
window
]
=
buttons
[
window
].
is_pressed
# log.log(window["button"].is_pressed)
# Log window data
# Log window data
print
(
str
(
window_data
))
print
(
str
(
window_data
))
# Wait for next data
# Wait for next data
# time.sleep(7.675)
# time.sleep(7.675)
client
.
write_points
(
json_body
)
time
.
sleep
(
3
)
time
.
sleep
(
3
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment