Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Μ
µtrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Teckids
Projekt Hack-n-Fun
Libs
µtrix
Commits
07e7d691
Verified
Commit
07e7d691
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Add doorbell example
parent
c8bb7edc
No related branches found
Branches containing commit
Tags
1.0
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/doorbell.py
+61
-0
61 additions, 0 deletions
examples/doorbell.py
with
61 additions
and
0 deletions
examples/doorbell.py
0 → 100644
+
61
−
0
View file @
07e7d691
# Copyright 2021 Benedict Suska <benedict.suska@teckids.org>
# Copyright 2021 Dominik George <dominik.george@teckids.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
time
from
machine
import
Pin
,
deepsleep
from
credentials
import
*
from
wifi
import
Wifi
from
mytrix
import
Matrix
# Define LEDs and pins
blueled
=
Pin
(
13
,
Pin
.
OUT
)
yellowled
=
Pin
(
12
,
Pin
.
OUT
)
greenled
=
Pin
(
14
,
Pin
.
OUT
)
# Switch off all LEDs
greenled
.
off
()
blueled
.
off
()
yellowled
.
off
()
# Connect to wifi
network
=
Wifi
(
SSID
,
PSK
)
network
.
connect
()
# Connect to Matrix server
matrix
=
Matrix
(
HOMESERVER
,
MATRIX_ID
,
ACCESS_TOKEN
)
# How long to wait for a reply
endtime
=
time
.
time
()
+
120
# On which texts to react and which LEDs to turn on
cases
=
{
"
come in
"
:
greenled
.
on
,
"
no
"
:
yellowled
.
on
}
if
network
.
is_connected
():
# If wifi is connected, turn on blue LED
blueled
.
on
()
# Send message that someone rang the bell
matrix
.
send_dm_message
(
DM_TARGET
,
"
Someone is at the door
"
)
# Wait for a reply
while
time
.
time
()
<
endtime
:
ret
=
matrix
.
react_dm_messages
(
DM_TARGET
,
cases
)
if
ret
:
# If there was a reply, wait 5 seconds and quit
time
.
sleep
(
5
)
break
time
.
sleep
(
2
)
# Turn off ESP until button is pressed again
deepsleep
()
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