Skip to content

Commit

Permalink
MVP
Browse files Browse the repository at this point in the history
  • Loading branch information
portasynthinca3 committed Apr 18, 2024
0 parents commit ef1871e
Show file tree
Hide file tree
Showing 18 changed files with 4,357 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
main/include/secrets.h
/build
/.vscode
/sdkconfig.old
/managed_components
/bracket.stl
/bracket.gcode
/flash_key.bin
/signing_key.pem
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "esp-idf-lib"]
path = esp-idf-lib
url = https://github.com/UncleRus/esp-idf-lib.git
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(EXTRA_COMPONENT_DIRS esp-idf-lib/components)
project(undef_rfid)
idf_build_set_property(COMPILE_OPTIONS "-Wno-error=format"
"-fsanitize=undefined" "-fno-sanitize=shift-base" APPEND)
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# undef_rfid
RFID-считыватель [undef.space](https://undef.club)

# Что делает?
Впускает админов в спейс по картам MIFARE. Аутентификация происходит по номеру
карты Тройка или по UID любой другой карты.

# Документация
Устройство состоит из:
- отладочной платы на базе ESP32-C3
- NFC-считывателя на базе PN532
- платы реле
- держателя

## Использование
Поднесите карту к считывателю. Если авторизация прошла успешно, светодиод
загорится зелёным, устройство откроет дверь и зафиксирует факт входа в админской
беседе. Если нет - светодиод загорится красным.

## Администрирование
Чтобы использовать встроенный REPL, подключите устройство по USB и откройте
монитор порта (например, при помощи `idf.py monitor`). Если любая из команд
`add`, `remove` или `list` используется впервые за последние пять минут, нужно
будет ввести пароль. Используйте `help`, чтобы узнать список команд с
аргументами.

Формат `credential`:
- `T<10 цифр>` - карта Тройка
- `U<8 hex-цифр>` - любая карта с 4-байтовым UID
- `U<14 hex-цифр>` - любая карта с 7-байтовым UID

## Сборка

### Держатель
TODO:

### Электроника
TODO:

### Прошивка
Написана на C с использованием ESP-IDF. Чтобы собрать прошивку:
- установите ESP-IDF
- склонируйте репозиторий
- скачайте зависимости: `git submodule update --recursive`
- создайте файл `main/include/secrets.h` со следующим содержанием:
```c
#pragma once
#define WIFI_SSID "название сети"
#define WIFI_PASS "пароль сети"
#define HASS_KEY "ключ API HomeAssistant"
#define REPL_PASS "пароль от REPL"
```
- получите ключи шифрования:
- если собираете новое устройство, сгенерируйте ключи:
`espsecure.py generate_flash_encryption_key flash_key.bin`,
`espsecure.py generate_signing_key --version 1 signing_key.pem`
- если работаете с уже собранным устройством, получите их от админов и
поместите в корень проекта (файлы `flash_key.bin` и `signing_key.pem`)
- соберите проект: `idf.py build`
- загрузите прошивку:
- в самый первый раз: `idf.py flash monitor`
- в последующие разы, в т.ч. для уже собранного устройства: `./flash.sh`
57 changes: 57 additions & 0 deletions bracket.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
$fn = 100;

pn532_w = 43;
pn532_h = 40.5;

pn532_screws_w = 28;
pn532_screws_h = 26;
pn532_screws_offs_x = 7.5;
pn532_screws_offs_y = 7.3;

pn532_pins_offs_x = 13.2;
pn532_pins_offs_y = 5.25;
pn532_pins_w = 21.5;
pn532_pins_h = 2.5;
pn532_pins_t = 1.5;

panel_t = 3;
side_panel_h = 15;
stiffener = 7;
thread_indent_t = 3.2;

// top panel
translate(v = [panel_t, 0, 0])
difference() {
cube(size = [pn532_w, pn532_h + (2 * panel_t), panel_t]);

translate(v = [0, panel_t, 0]) {
// pin cavity
translate(v = [pn532_pins_offs_x, pn532_pins_offs_y, 0])
cube(size = [pn532_pins_w, pn532_pins_h, pn532_pins_t]);

// thread indents
for(i = [0, 1])
translate(v = [pn532_screws_offs_x + (i * pn532_screws_w), pn532_screws_offs_y + (i * pn532_screws_h), 0])
cylinder(h = panel_t * 2, r = thread_indent_t / 2, center=true);
}
}

// side panel
side_panel_w = pn532_h + (2 * panel_t);
translate(v = [0, 0, -side_panel_h])
difference() {
cube(size = [panel_t, side_panel_w, side_panel_h + panel_t]);

// thread indents
for(i = [side_panel_w / 4, side_panel_w * 3 / 4])
translate(v = [0, i, side_panel_h / 2])
rotate(a = [0, -90, 0])
cylinder(h = panel_t * 2, r = thread_indent_t / 2, center=true);
}

// stiffeners
for(y = [0, pn532_h + panel_t])
translate(v = [panel_t, y, 0])
rotate(a = [-90, 0, 0])
linear_extrude(height = panel_t)
polygon(points=[[0, 0], [stiffener, 0], [0, stiffener]]);
6 changes: 6 additions & 0 deletions flash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh

idf.py build
espsecure.py encrypt_flash_data --aes_xts --keyfile flash_key.bin --address 0x10000 --output build/encrypted_app.bin build/undef_rfid.bin
esptool.py write_flash --force 0x10000 build/encrypted_app.bin
idf.py monitor
3 changes: 3 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(
SRCS "hass.c" "pn532.c" "main.c" "auth.c" "hass.c"
INCLUDE_DIRS "include/")
Loading

0 comments on commit ef1871e

Please sign in to comment.