Control your home using only Javascript
--
How to use React, Node.js and Espruino on ESP8266 to build some smart home components
In the last 2 months I spent some nights creating a smart home architecture, based exclusively on Javascript.
Why? There are already plenty of solutions on the internet.
Two main reasons:
- Price: I didn’t want to spend >40$ for a single smart switch. I should be able to make my home intelligent with less than 10$ for every component.
- Know your code: after some IoT scandals I wanted to know exactly what every component is doing in every moment. That’s also the reason why I published everything on my Github account.
The project (that I called Aurora) is based on:
- React + Redux for the Front-End
- Node.JS for the Back-End
- Espruino for the components (based on ESP8266)
As you can see, there are three main components in this architecture:
Progressive Web App
Here I can switch on/off the lights, share nodes with other people and schedule some events for the future.
It’s using React and Redux to handle all the state, and this is also saved on LocalStorage. A service worker is caching all the GET requests, so after the first load the app is really fast to open and to interact. And with the last Chrome for Android, you can also install it as a normal app :)
Node.js server
The server it’s where all the information about the nodes, the users and all the interaction between them resides. It’s composed by:
- an API to create nodes, set node state (switch on/off, change brightness…), add a user to a node and get info about a user. The authentication is based on a Token strategy.
- A MQTT broker (i’m using Mosca) to connect to the nodes and send/receive state changes.
- A Socket.io server, to send to the Web app all the state changes caused…