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
c3a42049
Verified
Commit
c3a42049
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add sensor test
parents
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
+109
-0
109 additions, 0 deletions
temp.py
with
109 additions
and
0 deletions
temp.py
0 → 100755
+
109
−
0
View file @
c3a42049
# import necessary modules
import
json
import
sys
import
os
import
time
import
datetime
import
numpy
import
requests
from
gpiozero
import
Button
BASE_URL
=
"
http://energie.intern/api/
"
def
temp_it
():
while
True
:
if
not
os
.
path
.
exists
(
"
/sys/bus/w1/devices/
"
):
print
(
"
The iterator is not executed on a Raspberry Pi
"
)
sys
.
exit
(
-
1
)
# open 1-wire slaves list for reading
file
=
open
(
'
/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves
'
,
'
r
'
)
# read 1-wire slaves list
w1_slaves
=
file
.
readlines
()
# close 1-wire slaves list
file
.
close
()
temp_count
=
0
temps
=
[]
# repeat following steps with each 1-wire slave
for
line
in
w1_slaves
:
# extract 1-wire slave
w1_slave
=
line
.
split
(
"
\n
"
)[
0
]
# open 1-wire slave file
file
=
open
(
'
/sys/bus/w1/devices/
'
+
str
(
w1_slave
)
+
'
/w1_slave
'
)
# read content from 1-wire slave file
file_content
=
file
.
read
()
# close 1-wire slave file
file
.
close
()
# extract temperature string
str_value
=
file_content
.
split
(
"
\n
"
)[
1
].
split
(
"
"
)[
9
].
split
(
"
=
"
)[
1
]
# convert temperature value
temp
=
float
(
str_value
)
/
1000
# temp = float("%.2f" % temp)
temps
.
append
(
temp
)
++
temp_count
yield
((
temps
,
temp_count
))
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
=
[
12
,
13
]
buttons
=
{}
for
window
in
windows
:
print
(
f
"
Window
{
window
}
"
)
buttons
[
window
]
=
Button
(
window
)
for
temps
,
temp_count
in
temp_it
():
########
# TEMP #
########
# Calculate average
avg_temp
=
numpy
.
mean
(
temps
)
avg_temp
=
float
(
"
%.2f
"
%
avg_temp
)
# Log average and time to console
print
(
"
Measured temperatures:
"
+
str
(
temps
))
print
(
"
Logged data:
"
+
str
(
datetime
.
datetime
.
now
())[
0
:
10
]
+
"
,
"
+
str
(
datetime
.
datetime
.
now
())[
11
:
-
10
]
+
"
,
"
+
str
(
avg_temp
)
+
"
°C
\n
"
)
##########
# WINDOW #
##########
# Get windows status
window_data
=
{}
for
window
in
windows
:
# Add one window to data
window_data
[
window
]
=
buttons
[
window
].
is_pressed
# log.log(window["button"].is_pressed)
# Log window data
print
(
str
(
window_data
))
# Wait for next data
# time.sleep(7.675)
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