{"id":43,"date":"2016-02-06T11:11:51","date_gmt":"2016-02-06T11:11:51","guid":{"rendered":"http:\/\/www.albertosarullo.com\/blog\/?p=43"},"modified":"2016-02-21T10:11:28","modified_gmt":"2016-02-21T10:11:28","slug":"door-smartphone-esp8266-nodejs-azure-relay","status":"publish","type":"post","link":"http:\/\/www.albertosarullo.com\/blog\/door-smartphone-esp8266-nodejs-azure-relay","title":{"rendered":"ESP8266: Smartphone door opener for less then 10$"},"content":{"rendered":"<p>Sometimes you have your hands full of bags, umbrellas, etc.\u00c2\u00a0In these cases it would be useful to open the door without keys,\u00c2\u00a0simply finishing ahead.<\/p>\n<p>My idea is to use a smartphone to trigger the opening of the door, using a microcontroller inside my\u00c2\u00a0house and an application on the cloud to manage the communications of the system.<\/p>\n<p>For my jobs experience, I know very well that with a RaspberryPI + wifi (45$) or an\u00c2\u00a0Arduino Y\u00c3\u00b9n (60$) the project is feasible, but:<\/p>\n<ul>\n<li>my challenge is implement the whole system with a cost lower than 10$<\/li>\n<li>It is a waste to use an entire operating system to push a button<\/li>\n<\/ul>\n<p>So, I choose the\u00c2\u00a0well known\u00c2\u00a0ESP8266 module.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-56\" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/esp8266_relay_intercom_IMG_20160207_112909-1024x768.jpg\" alt=\"esp8266_relay_intercom_IMG_20160207_112909\" width=\"640\" height=\"480\" srcset=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/esp8266_relay_intercom_IMG_20160207_112909-1024x768.jpg 1024w, http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/esp8266_relay_intercom_IMG_20160207_112909-300x225.jpg 300w, http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/esp8266_relay_intercom_IMG_20160207_112909-768x576.jpg 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<h2>Recipe<\/h2>\n<ul>\n<li>1 ESP8266 dev board like NodeMCU (~8$)<\/li>\n<li>1 Relay\u00c2\u00a0(~1$)<\/li>\n<li>NodeJS application on Azure websites\u00c2\u00a0 (0$)<\/li>\n<\/ul>\n<p>I bought all the hardware on my favourite <a href=\"https:\/\/www.banggood.com\/?p=0L080312177382015027\" target=\"_blank\">chinese mall Bangood<\/a>.<\/p>\n<h2><\/h2>\n<h2>System<\/h2>\n<p><a href=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/Intercom-Esp8266-2.png\" rel=\"attachment wp-att-48\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-48\" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/Intercom-Esp8266-2.png\" alt=\"Intercom Esp8266 (2)\" width=\"798\" height=\"509\" srcset=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/Intercom-Esp8266-2.png 798w, http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/Intercom-Esp8266-2-300x191.png 300w, http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/Intercom-Esp8266-2-768x490.png 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/p>\n<h2>How it works<\/h2>\n<ol>\n<li>On the cloud there is a NodeJS app (websocket server + http server)<\/li>\n<li>The ESP8266 board is connected to NodeJS app via websocket, using my home wifi network<\/li>\n<li>When certain <em>conditions<\/em> are met, the smartphone makes a HTTP request\u00c2\u00a0to\u00c2\u00a0NodeJS app<\/li>\n<li>When NodeJS app receive specific http request, send a command to the websocket<\/li>\n<li>The\u00c2\u00a0ESP8266 board receive the command instantly (&lt; 0.2s) and activate the relay digital pin<\/li>\n<li>The Relay receive current and trigger the switch on the intercom<\/li>\n<li>The door is unlocked<\/li>\n<\/ol>\n<h2>Code<\/h2>\n<p>Soon publish the code on <a href=\"http:\/\/github.com\/albertosarullo\/\" target=\"_blank\">Github<\/a> for both ESP8266 and NodeJS apps<\/p>\n<h2>TLTR<\/h2>\n<p>At the beginning I wanted\u00c2\u00a0bypass entirely the intercom, but after\u00c2\u00a0few attempt I realize that the intercom protocol is not well documented. Audio, video and signal all on 2 wire at 26-28V. Definitely easier\u00c2\u00a0to simulate the press on the intercom button using a relay.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-51\" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/IMG_20160204_193929-copy-674x1024.jpg\" alt=\"IMG_20160204_193929 copy\" width=\"640\" height=\"972\" srcset=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/IMG_20160204_193929-copy-674x1024.jpg 674w, http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/IMG_20160204_193929-copy-198x300.jpg 198w, http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/IMG_20160204_193929-copy-768x1166.jpg 768w, http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/IMG_20160204_193929-copy.jpg 1942w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p><a href=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/IMG_20160205_210522.jpg\" rel=\"attachment wp-att-50\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-50\" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/IMG_20160205_210522-821x1024.jpg\" alt=\"IMG_20160205_210522\" width=\"640\" height=\"798\" srcset=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/IMG_20160205_210522-821x1024.jpg 821w, http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/IMG_20160205_210522-241x300.jpg 241w, http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2016\/02\/IMG_20160205_210522-768x957.jpg 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>After write the Esp8266 code with Arduino, I wrote the server parte with NodeJS and a webpage.<\/p>\n<p>From an architectural perspective the initial system is composed by a single server and two client (Esp8266 and Smartphone) that communicating with a persistent connection (websocket).<\/p>\n<p>Due to the websocket connection limit of free azure websites (max 5 connection) an other economic considerations, I upgrade the system to limit the websocket connection only to the indispensable Esp8266 side, letting the smartphone using classic\u00c2\u00a0HTTP\u00c2\u00a0requests to send commands to the server.<\/p>\n<p>I build\u00c2\u00a0a webpage with a on\/off butto to test the system, and it works! After 2 weeks of continuous running without any problem, I am fully satisfied: I can open my door with a touch on my smartphone.<\/p>\n<p>But\u00c2\u00a0it would be great if I could open the door without touching the smartphone. So I started to investigate the conditions and technologies to upgrade the system the next level.<\/p>\n<p>As often happens, any simplification for the user adds layers of complexity to the system, and the\u00c2\u00a0variables become many:<\/p>\n<ul>\n<li>location (gps and wifi based)<\/li>\n<li>walk paths<\/li>\n<li>hours of the day<\/li>\n<li>days of the week<\/li>\n<li>wifi ssid available<\/li>\n<li>network to which my mobile phone is connected<\/li>\n<\/ul>\n<p>The approach based on a web page was no longer sufficient: i switch to native app.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you have your hands full of bags, umbrellas, etc.\u00c2\u00a0In these cases it would be useful to open the door without keys,\u00c2\u00a0simply finishing ahead. My idea is to use a smartphone to trigger the opening of the door, using a microcontroller inside my\u00c2\u00a0house and an application on the cloud to manage the communications of the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.albertosarullo.com\/blog\/door-smartphone-esp8266-nodejs-azure-relay\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;ESP8266: Smartphone door opener for less then 10$&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,66,54],"tags":[63,58,64,67,57,62,65,36,59,60,61],"class_list":["post-43","post","type-post","status-publish","format-standard","hentry","category-arduino","category-diy","category-maker","tag-arduino","tag-azure","tag-cloud","tag-diy","tag-esp8266","tag-express","tag-intercom","tag-nodejs","tag-nodemcu","tag-relay","tag-websocket"],"_links":{"self":[{"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":0,"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}