Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PIoT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Volkor Barbarian Warrior
PIoT
Commits
1cc8d763
Commit
1cc8d763
authored
6 years ago
by
rmit-s3661720-daniel-linford
Browse files
Options
Downloads
Patches
Plain Diff
Added verification of climate results
parent
067efc72
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
monitor_and_notify.py
+10
-7
10 additions, 7 deletions
monitor_and_notify.py
with
10 additions
and
7 deletions
monitor_and_notify.py
+
10
−
7
View file @
1cc8d763
...
...
@@ -44,10 +44,14 @@ class MonitorNotifier:
# Record the current temp data into database
def
recordClimate
(
self
):
# Update current climate information
# TODO make readings more accurate, perhaps put in own methods
temperature
=
self
.
__sense
.
get_temperature
()
humidity
=
self
.
__sense
.
get_humidity
()
# Get and validate current climate information
try
:
temperature
=
float
(
self
.
__sense
.
get_temperature
())
humidity
=
float
(
self
.
__sense
.
get_humidity
())
except
ValueError
:
print
(
"
Warning: Invalid climate data recorded,
\
stopping climate monitor
"
)
SystemExit
()
# Record climate information in database and send notification
with
self
.
__database
:
cursor
=
self
.
__database
.
cursor
()
...
...
@@ -57,8 +61,6 @@ class MonitorNotifier:
self
.
__database
.
commit
()
# Check if notification sould be sent
self
.
__checkAndNotify
(
temperature
,
humidity
)
# End of function
return
# Sends a pushbullet notification if temperature is out of range
# and a notification has not already been sent today
...
...
@@ -101,6 +103,7 @@ class MonitorNotifier:
cursor
=
self
.
__database
.
cursor
()
cursor
.
execute
(
"
INSERT INTO Notifications (timesent)
\
VALUES (DATETIME(
'
now
'
,
'
localtime
'
))
"
)
self
.
__database
.
commit
()
# Returns true if able to connect to pushbullet API, otherwise false
def
__checkConnection
(
self
):
...
...
@@ -120,7 +123,7 @@ if __name__ == "__main__":
databaseName
=
"
climate_data.db
"
# Initialize monitor class
monitor
=
MonitorNotifier
(
databaseName
)
# Check climate conditions every minute
# Check
and record
climate conditions every minute
while
True
:
monitor
.
recordClimate
()
time
.
sleep
(
60
)
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