Skip to content
Snippets Groups Projects
Verified Commit 07e7d691 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Add doorbell example

parent c8bb7edc
No related branches found
Tags 1.0
No related merge requests found
# 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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment