You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Filip B P e6c39afe7f Added challenges 2 years ago
README.md Added challenges 2 years ago

README.md

Alarm system

Problemformulering

We want to make an alarm system. The system must be able to control locks, react to motion sensors, sound an alarm, flash a LED and be unlocked with a key card and a simple web interface for locking and unlocking.

Challenges

TLS encryption

We tried implementing TLS encryption on the MQTT connection. It worked great between the MQTT broker and the controller, but the ESP's had some difficulty validating the brokers certificate. This was probably caused because of the MQTT library we used, which doesn't natively support TLS, but relies on the platforms implementation of TLS, which didn't work great together.

If more effort and a bigger willingness to rewrite big parts of the device code it could be achieved. But we didn't prioritize it, because it isn't necessary for a working prototype.

Network

Of course we had problems with the network. As the schools network was very unreliable, or even nonexisting at times. This was mostly just a point of frustration, but didn't really cause any real challenges as we solved it by running our own hotspots.

Devices

Card reader

The card reader consists of an ESP8266 Wemos D1 Mini board and a PN-5180-NFC reader. When a card is read the device sends a MQTT message to the broker. The controller runnning on the Pi subscribes on the event and unlocks the door and if the alarm is armed disarms it.

The NFC reader reads the serial number of the NFC card or tag and transmits it, the controller checks the serial against a list of known serial numbers.

Source code

The source code can be found at https://git.bpfilip.dk/HFJ/alarm-card-reader

Hardware connections

ESP8266 PN-5180-NFC
3.3v 3.3v
5v 5v
D1 RST
D2 NSS
D7 MOSI
D6 MISO
D5 SCK
D0 BUSY
GND GND

Display

The display module consists of a ESP8266 NodeMCU, a 16x2 character LCD Display, a buzzer, a rotary encoder with an embedded button and a button. The display subscribes to the alarm/state topic on MQTT and by default displays the current state. When the rotary encoder is pressed you are asked to enter your pin code. When entered the door is unlocked and the alarm either arms or disarms depending on the previous state.

When the alarm is triggered the buzzer is triggered.

Source code

The source code can be found at https://git.bpfilip.dk/HFJ/alarm-display

Hardware connections

ESP8266 16x2 LCD Display Buzzer Button Rotary encoder
3.3v 3.3v V V
GND GND G G GND
D2 SDA
D1 SCL
D0 S
D3 S
D5 Button
D6 Rotary #1
D7 Rotary #2

Door Sensor

The door sensor module consists of a ESP8266 Wemos D1 Mini board, a reed switch (Magnetic switch) and a relay.

The relay emulates a door lock, where when the relay is turned on the door would be locked.

The reed switch should be mounted together with a magnet on the door to detect when the door is opened.

When a card or tag is read on the card reader the door is opened either for 5 seconds or until the door is closed again.

Source code

The source code can be found at https://git.bpfilip.dk/HFJ/alarm-door-sensor

Hardware connections

ESP8266 Relay Reed switch
GND GND G
3.3v V
5v V
D6 S
D5 S

Motion Sensor

The motion sensor consists of an ESP32 NodeMCU, an analog temperature sensor, a microphone, an analog ambient light sensor, a PIR (Passive InfraRed) motion sensor and a LED.

When motion is detected on the motion sensor a message is sent via MQTT. If the alarm is armed the alarm will trigger.

When the alarm is triggered the LED will flash continually. While the system is arming while flash two consecutive pulses indicating it's currently arming. When the system is disarmed it will flash a single time.

When the microphone detects a high sound when the system is armed it will trigger the alarm. This is to detect a window breaking or an explosion.

The data from the light and temperature sensor is currently just being stored in the database, but no further analysis it performed.

Source code

The source code can be found at https://git.bpfilip.dk/HFJ/alarm-motion-sensor

Hardware connections

ESP8266 Temperature Microphone Light Motion LED
GND G G G G G
3.3v V V V
5v V V V
D34 S
D35 S
D32 S
D33 S
D25 S

Controller

The controller consist of a Raspberry Pi running a MQTT broker, a PostgreSQL database and a NodeJS application.

The database and MQTT broker is setup in Docker containers. This makes setup and management of configuration files easier.

The NodeJS application is the brain of the whole alarm system. It listens for events from all the devices using MQTT and the broker. It fx. handles when a card is read and checks it against the list of known cards and if it's known sends the messages to the other devices of what to do next. The controller is also in charge of managing the current state of the whole system, each device can be restarted and keeps no state stored.

The controller is also in charge of hosting a REST API and a web interface for controlling the system. Currently the only function on the web interface is to arm and disarm the system. Future improvements could include user management, access control, a history of events, changing user pins and access cards and tags. Currently a history of all events is written to the database, but as of now it isn't exposed anywhere.

Temperature and light data is written to the database, but is currently not shown anywhere. This could also be integrated into the web interface for graphs of the data.

Documentation of all the different topics the controller sends and listens on can be found here https://git.bpfilip.dk/HFJ/alarm-controller/src/branch/main/API.md