{"id":27650485,"url":"https://github.com/kenken64/iot-door-sensor","last_synced_at":"2025-10-22T10:54:18.059Z","repository":{"id":50702539,"uuid":"164233006","full_name":"kenken64/iot-door-sensor","owner":"kenken64","description":"Door and Window sensor Project - Sigfox/LoraWan/ESP32/ESP8266 -  Arduino , Angular , Material Design. Blynk, AWS Iot, TheThingNetwork, Sigfox Backend","archived":false,"fork":false,"pushed_at":"2020-09-10T15:15:46.000Z","size":36282,"stargazers_count":11,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-24T03:39:55.670Z","etag":null,"topics":["angular","arduino","aws","blynk","eagle","esp8266","firebase","fritzing","websocket","wifimanager"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kenken64.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-05T16:41:19.000Z","updated_at":"2022-08-30T12:07:27.000Z","dependencies_parsed_at":"2022-09-18T06:55:28.802Z","dependency_job_id":null,"html_url":"https://github.com/kenken64/iot-door-sensor","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/kenken64/iot-door-sensor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenken64%2Fiot-door-sensor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenken64%2Fiot-door-sensor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenken64%2Fiot-door-sensor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenken64%2Fiot-door-sensor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kenken64","download_url":"https://codeload.github.com/kenken64/iot-door-sensor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenken64%2Fiot-door-sensor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280424215,"owners_count":26328462,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","arduino","aws","blynk","eagle","esp8266","firebase","fritzing","websocket","wifimanager"],"created_at":"2025-04-24T03:39:51.621Z","updated_at":"2025-10-22T10:54:18.045Z","avatar_url":"https://github.com/kenken64.png","language":"TypeScript","readme":"# Door/Window Sensor - Internet of Things\n\n## Tindie Store - Order the device here https://bit.ly/2L2vBSy \n\n### If you would like to see further enhancement of this whole iot platform kindly donate to my BTC account\n\n\u003cimg src=\"docs/btc.png\" width=\"300px\" height=\"300px\"\u003e\n\n[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/pYRvByaGBP0/0.jpg)](https://www.youtube.com/watch?v=pYRvByaGBP0)\n\n[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/cuYwMgwrSvQ/0.jpg)](https://youtu.be/cuYwMgwrSvQ)\n\nNothing spells security than being notified or alerted if somebody has entered your premises without your permission. It also helps when even before someone can gain entry, you already know who he or she is. The main idea of this door/window sensor is to simply provide you information if someone has gone through any of your property entry points.\n\n## Works with Many Entry Points\n\nThe door/window sensor is primarily used to detect people or objects that have passed through the doors, but it’s also compatible to windows and any enclosures that could be opened.\n\n## Small to Notice\n\nThe door/window sensor is a very unassuming device so it blends well with the rest of the commonly found items or appliances in your home. It is also quite small you can easily hide it well, away from the prying eyes of potential intruders, and it doesn’t get in the way with the actual functions of the entry points.\n\nThe device is a magnetic switch that allows it to accurately determine location and direction. In other words, there are no false alarms and leads.\n\n## Very Easy and Fast Installation\n\nAs a magnetic device, it doesn’t require any intricate tools to install. In fact, you simply need to snap it into any metal part of your entryway, and you can already properly and quickly configure the door sensor. If not, you can conveniently attached even a small piece of metal at any part of the door and window.\n\n## Works on the cloud\n\nA connected home brings devices and services together for an integrated, autonomous experience that improves a consumer’s life. Connected home experiences include everything from window/door sensor , voice-controlled lights, house-cleaning robots, machine learning-enabled security cameras, and WiFi routers that troubleshoot for you. Thanks to decreasing costs and increasing options for connectivity, these smart home devices, sensors, and tools can be interlinked to create real-time, contextual, and smart experiences for consumers.\n\nIoT powers the connected home by bringing new features and capabilities to smart devices, like interconnectivity, security, offline communication, predictive maintenance, analytics for consumer insights, and machine learning. Each of these capabilities play a different role in key connected home use cases such as home automation, home security and monitoring, and home networking.\n\n\n# Multiple version\n- Wifi version\n- Sigfox version\n- Lorawan version require an existing lorawan gateway (Prototype, too expensive)\n\n# Pre-requisite Lora Gateway\n- Use the raspi-config tool (with sudo raspi-config) to enable SPI on the Raspberry Pi\n- Install wiringpi (sudo apt-get install wiringpi)\n\n# Pre-requisite microcontroller and parts\n- Adafruit Huzzah ESP8266/TTGO ESP32 Wifi/Arduino UNO\n- 2-way connector\n- LED\n- 47k Ohm Resistor\n- 10k Ohm Resistor\n- 220 Ohm Resistor\n- Magnetic Door Sensor\n- Jumper\n- Custom made PCB by kenken64\n- Lipo Battery/ 18650 battery\n- Headers \n- UnaShield Sigfox for Arduino UNO\n\n## 3D printed Casing/Housing\n- ESP8266/ESP32 STL 3d Design\n- Sigfox STL 3d Design\n\n\n# PCB Design (Eagle and Fritzing)\n- WIFI Version 1 (Custom made PCB)\n\u003cbr\u003e\n\u003cimg src=\"docs/pcb3.jpg\" width=\"300px\" height=\"300px\"\u003e\n\n- WIFI Version 2 (Custom made PCB)\n\u003cbr\u003e\n\u003cimg src=\"docs/pcb_design.png\" width=\"300px\" height=\"400px\"\u003e\n\n\u003cimg src=\"docs/pcb_design2.png\" width=\"500px\" height=\"400px\"\u003e\n\n- Sigfox version (Shield from UnaBiz)\n\n\n# Pre-requisite software \u0026 library\n\n- Microsoft Visual Studio Code\n- Node JS\n- Ubuntu/Windows 10 ( 2 CPU and 2GB ram )\n- Angular 7 Cli\n- Arduino IDE\n- ESPBattery\n- ESP 8266/32 Arduino library\n- Unashield Sigfox library\n\n# Pre-requisite Cloud account\n\n- Twilio (require your own credit to send out SMS/WhatsApp)\n- Gmail https://mail.google.com/mail/u/0/\n- Google Firebase Realtime Database https://console.firebase.google.com/u/0/?pli=1\n- Blynk Cloud Service ( Mobile App) \n\n# Twilio - SMS and WhatsApp Notification\n\n- Create a twilio account and top up with the credits.\n- Note down the twilio SSID and AUTH TOKEN.\n- Purchase a number from Twilio\n- Also note down the WhatsApp from number\n\n![Image of Twilio](docs/twilio.png)\n\n# SMTP or Gmail account Email notification\n\n- Create gmail account. Please do not use personal gmail account for this.\n- Enable unsecure access to this account [Gmail API setting](https://support.google.com/accounts/answer/6010255?hl=en)\n\n# Backend Server Side (AWS Lightsail/ DO / Azure / Google Cloud)\n- Detect door is open and closed.\n- Send SMS using twilio to the configure recipient mobile number\n- Send notification email to the configure recipient email address\n- Detect battery is low send notification via SMS and email\n- Log all events to the door's device\n- Provide exportable reporting of all doors \n\n# Environment variable\n\n| Env variables        | Description           | \n| ------------- |:-------------:| \n| SMTP_GMAIL_ACC      | Gmail SMTP account that use to send email to security guard  | \n| SMTP_GMAIL_PASSWORD     | Password for the above email account      |  \n| TWILIO_SSID | SSID for the twilio sms APIs      |   \n| TWILIO_AUTH_TOKEN | Security token for the twilio sms APIs      | \n| TWILIO_NUMBER | You need a twilio phone number in order to send SMS to the receipient      | \n| FIREBASE_DB_URL | NoSQL Database url     | \n| JOB_INTERVAL | Interval period where the job poll for the changes from firebase and the blynk APIs      | \n| JOB_TIMEOUT | Tiemout period where the job poll for the changes from firebase and the blynk APIs      | \n| NOTIFICATION_ENABLE | Disable and enable notification when door is open and closed      | \n| FIREBASE_SVC_ACC_FILE | Firebase credential file to perform admin operations e.g.  https://door-sensor-proj.firebaseio.com  | \n| CLEAN_UP_SCHEDULE | Schedule timing to cleanup events logs     | \n| BLYNK_API_URL | Blynk IOT API URL  e.g. http://blynk-cloud.com/   | \n| SIGFOX_SERVER_PORT | Sigfox callback backend server port number     |\n| TWILIO_WHATSAPP_NO | Twilio WhatsApp from number     |\n\n# Door/Window sensor Web App\n\n## List of door/window installed with sensor\n\n![List of doors](docs/list.png)\n\n## Add new door/window sensor\n\u003cimg src=\"docs/add_new_door_sensor.png\" width=\"400px\" height=\"600px\"\u003e\n\n## Add new security personel to the system\n![Add guard to the system](docs/associate_guard_to_sensor.png)\n\n## Associate multiple security guard to the sensors\n![Associate guard to the door sensors](docs/configure_guard_door.png)\n\n\n## Provide feedback on door/window events\n![feedback on events](docs/feedback_door_closed.png)\n\n## SMS Notification\n\u003cimg src=\"docs/screenshot_7.png\" width=\"400px\" height=\"600px\"\u003e\n\n## Email Notification\n\u003cimg src=\"docs/screenshot_8.png\" width=\"400px\" height=\"600px\"\u003e\n\n## WhatsApp Notification\n\u003cimg src=\"docs/twilio_whatsapp.png\" width=\"400px\" height=\"600px\"\u003e\n\n## Export as Excel Spreadsheet\n\u003cimg src=\"docs/spreadsheet.png\" width=\"400px\" height=\"600px\"\u003e\n\n# Setup Instructions for the PWA Web App and Backend\n\nKindly create a Azure/AWS/Google Cloud account to deploy all this component on a Ubuntu 18.04 distribution\n\nAfter creating a cloud instance, ssh/login into the instance install git software and node js. Please follow the links below with all the installation steps \n\nhttps://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04-quickstart\n\nhttps://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04\n\n\nThis project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.1.4.\n\n## Logon to the newly created cloud server and pull down the github source codes using the below linux command\n\n```\ncd ~\ngit clone https://github.com/kenken64/iot-door-sensor.git\n```\n## Development server\n\nRun `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.\n\n## Code scaffolding\n\nRun `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.\n\n## Build\n\nRun `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.\n\n## Running unit tests\n\nRun `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).\n\n## Running end-to-end tests\n\nRun `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).\n\n## Further help\n\nTo get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).\n\n## Install PWA from dist directory to Nginx \n\nUse the link below for the nginx installation\n\nhttps://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-18-04\n\nRight after the web server is installed, install free SSL certificate using Let's Encrypt \n\nhttps://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04\n\nLastly, copy all the files from the angular app /dist directory to the nginx web server root directory e.g. /var/www/html\n\n## Google Firebase\n\nIt is must to have Google account in order to create a firebase account for this project\n\n1. Create a firebase real time database project following this link https://firebase.google.com/\n\n## Install and start redis server\n\n1. Install redis server\n\n```\nsudo apt-get update\nsudo apt-get install redis\n```\n\n2. Start Redis server\n\n```\nsudo service redis-server start\n```\n3. Check redis server status\n```\nsudo service redis-server status\n```\n\n4. if only there is a crash on the worker process then run flush\n\n```\nredis-cli FLUSHALL\n```\n\n## Start Backend server\nHow to start the sms and email backend server that poll the devices.\n\n```\n$ cd server/\n$ npm i \n$ pm2 start server.js --name server --max-memory-restart 1G --restart-delay 10000 --node-args=\"--expose-gc --max-old-space-size=4096\"\n```\n\n## Start Door Sensor Worker Engine to poll door's state\nWorker consumes the job from the delegator to check the door sensors and send out notification via SMS/WhatsApp/Email.\n\nEach worker is configured with its own designated door sensor's blynk auth key. Refer to the server/worker-config.json\n\n```\n[\n    {\n        \"workerName\": \"worker1\",\n        \"doors\": [\"b40605f4f5d5484bbe7b9a3cb78f1376\",\n                \"962d1f57311e47c7bb71697b8051de30\",\n                \"980f92ef13db430594a89315d86dd37b\"\n                \n                \n        ]\n    },\n    {\n        \"workerName\": \"worker2\",\n        \"doors\": [ \"185333bfb0d14a2a9365fdc3bd37966a\",\n                \"953b351b1ba4428bb781c40bec29a300\",\n                \"194eab22d2bd49c0a580c01d7d19ce34\"\n        ]\n    },\n    {\n        \"workerName\": \"worker3\",\n        \"doors\": [ \"166fff24ab4f4a52a31a936369d3a1cc\",\n                \"2dde80b00cf342c1b6977e91dd9b6039\"\n        ]\n    },\n    {\n        \"workerName\": \"worker4\",\n        \"doors\": [ \"c56c9a1ab4b1415998c06173786354f2\",\n                \"2f0b7bd399a54a839e976a09bee2463a\"\n        ]\n    }\n]\n```\n\n```\n$ cd server/\n$ pm2 start worker.js --name worker --max-memory-restart 500M -- --workername=worker1 --node-args=\"--expose-gc\n$ pm2 start worker.js --name worker2 --max-memory-restart 500M -- --workername=worker2 --node-args=\"--expose-gc\n$ pm2 start worker.js --name worker3 --max-memory-restart 500M -- --workername=worker3 --node-args=\"--expose-gc\n$ pm2 start worker.js --name worker4 --max-memory-restart 500M -- --workername=worker4 --node-args=\"--expose-gc\n```\n\n## Blynk Configuration\n\nGo to your Google App Store/Apple store search for Blynk, install it\n\nRegister an account with Blynk\n\nCreate a new project, choose device as ESP8266 WIFI send the auth key to your email address\n\n\n\u003cimg src=\"docs/Blynk2.jpg\" width=\"400px\" height=\"600px\"\u003e\n\n\u003cimg src=\"docs/Blynk3.jpg\" width=\"400px\" height=\"600px\"\u003e\n\n\u003cimg src=\"docs/Blynk4.jpg\" width=\"400px\" height=\"600px\"\u003e\n\n\u003cimg src=\"docs/Blynk5.jpg\" width=\"400px\" height=\"600px\"\u003e\n\n\u003cimg src=\"docs/Blynk6.jpg\" width=\"400px\" height=\"600px\"\u003e\n\n## Restful API for Blynk\n\nBelow is the link to test out the API using your REST client\nhttps://blynkapi.docs.apiary.io/#\n\n\u003cimg src=\"docs/blynk1.png\" width=\"400px\" height=\"600px\"\u003e\n\n\n\u003cimg src=\"docs/blynk2.png\" width=\"400px\" height=\"700px\"\u003e\n\n\n\u003cimg src=\"docs/blynk3.png\" width=\"400px\" height=\"600px\"\u003e\n\n\n\n## Install firmware to the ESP8266/ESP32\n\n1. Plug the ESP8266 to your computer\n2. Launch Arduino IDE , open up the Arduino sketch from the directory /firmware/door_sensor/door_sensor.ino\n3. Search for the codes, replace the double quote values according to the auth code from the blynk email from your mailbox\n```\nchar blynk_token[33] = \"166fff24ab4f4a52a31a936369d0a1cc\";\n```\n4. Make sure ESP8266 board are installed using the board manager.\n\n![arduino board](docs/arduino_1.jpg)\n\n5. Select the configuration properly before compiling and flashing the ESP8266. Take note the flash size and port.\n\n![config](docs/arduino_3.jpg)\n\n5. The following libraries is amust to be installed before sync the firmware to the ESP8266 board\n  - ArduinoJson (Take note do not use the latest version)\n  ![arduino Json](docs/arduino_6.jpg)\n\n  - FS\n  ![SPI Flash](docs/arduino_4.jpg)\n  ![unified sensor](docs/arduino_5.jpg)\n\n  - ESPBattery (https://github.com/LennartHennigs/ESPBattery)\n  - Blynk\n  ![blynk](docs/arduino_7.jpg)\n\n  - WifiManager\n  ![wifimanager](docs/arduino_8.jpg)  \n\n\n6. Compile and sync the firmware to the microcontroller board\n\n![compile sync](docs/arduino_2.jpg)\n\n\n## Once everything is setup and up running on the cloud\n\n\nLast thing to do is to power up the door sensor using a micro usb cable, at first if there isn't any wifi setting being configure. the device  will act as an wireless access point with the SSID stated as \"AutoAPDoorSensor\" Access the portal via the following web address htttp://192.168.244.1\n\nConfigure the door sensor device to connect to your own wifi router with credential. Do not change the blynk auth key.\n\n\u003cimg src=\"docs/ap_wifi.jpg\" width=\"400px\" height=\"600px\"\u003e\n\n\u003cimg src=\"docs/ap_wifi3.jpg\" width=\"400px\" height=\"600px\"\u003e\n\n\u003cimg src=\"docs/ap_wifi2.jpg\" width=\"400px\" height=\"600px\"\u003e\n\n\n\n## Check the health of all processes\n```\npm2 list\n```\n![pm2 list](docs/pm2list.png)\n\n## Debug memory leakage\n- Use ChromeDev Tools\n- Dynatrace (https://www.dynatrace.com/)\n- Sentry io (https://sentry.io/welcome/)\n\n## Future work - Integrate with ElectricMagnetic lock \n\nMost of the EM lock in the market uses 12v AC likely need to enhance the PCB board\n\nhttps://shopee.sg/Hot-DC-DC-Converter-Output-Power-Adapter-24V-12V-To-5V-USB-Step-Down-Module-i.10885840.691201434?gclid=Cj0KCQjwnKHlBRDLARIsAMtMHDFC6E65QBD9bycE3Slw0D0tBNxFKR-Vn5mH1KITMRHCil_hmbI2bzYaAmgOEALw_wcB","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenken64%2Fiot-door-sensor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkenken64%2Fiot-door-sensor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenken64%2Fiot-door-sensor/lists"}