SmartHaus is a home automation system for building real-time dashboards for monitoring and controlling IoT devices. It works with microcontrollers like the Arduino Uno/Mega/Duo and the ESP8266 or ESP32. Built with Angular on the client-side and Node.js on the server-side and communicates via a RESTful API.
- β‘ Robust: Full JavaScript stack with Angular and Node.js with MongoDB database (MEAN Stack)
- π Convenient: Operates from your local network where your IoT devices live
- π Secure: It's centralized in your network and does not require an external "cloud" server
- π Simple: No need for external MQTT broker configurations. It's fully RESTful!
- On your device, upload one of the required Arduino example sketches that are available in the sketches directory of this project. Please refer to the Embeded API in the docs section.
- Set up the system on a Raspberry Pi. Please refer to this tutorial.
- backend/api/index.js - remove
userCtrl.verifyJWT
- src/app/app-routing.module.ts - remove
canActivate: [AuthGuard]
The API is similar to the official Arduino with Analog & Digital I/O functions except for the js callFunction()
and the getVariable()
functions.
pinMode(id, pin, mode)
Configures the specified pin to behave either as an input or an output
id: device ID. pin: the pin number. mode: 'i' for INPUT, 'o' for OUTPUT and 'I' for INPUT_PULLUP.
// Sets pin 6 mode to OUTPUT.
pinMode('468792', 6, 'o')
digitalWrite(id, pin, value)
Writes a HIGH or a LOW value to a digital pin
id: device ID. pin: the pin number to write to. value: 1 for 'HIGH' and 0 for 'LOW'.
// Sets pin 5 state to HIGH.
digitalWrite('468792', 5, 1)
digitalRead(id, pin)
Reads the state value from a specified digital pin
id: device ID. pin: the pin number to read from.
// Reads pin 4 state value and prints it to the console
digitalRead('468792', 4)
.subscribe((data) => {
console.log(data);
});
analogWrite(id, pin, value)
Writes an analog value (PWM wave) to a pin
id: device ID. pin: the pin to write to. value: the duty cycle: between 0 (always off) and 255 (always on).
// Writes an analog value to pin 3
analogWrite('468792', 3)
analogRead(id, pin)
Reads the value from the specified analog pin
id: device ID. pin: the pin to read from.
// Reads the voltage from pin 2 and prints it to the console
analogRead('468792', 2)
.subscribe((data) => {
console.log(data);
});
getVariable(id, variable)
Reads a variable from the device. This is useful for reading sensor data
id: device ID. variable: variable name to read from.
// Gets the value of variable 'temperatre' and prints it to the console
getVariable('468792', 'temperature')
.subscribe((data) => {
console.log(data);
});
callFunction(id, called_function, parameters)
Executes a pre-defined function on the device
id: device ID. called_function: function name to call parameters: parameters to pass to the function
// Calls the function 'turn_on_led' and passes the value 1
callFunction('468792', 'turn_on_led', '1')
The corresponding Arduino library "Restfulino" was forked from the aREST library. The changes made in this version were necessary in order to disconnect the library from the centralized private aREST MQTT broker since this system doesn't rely on MQTT. Other minor tweaks were also applied. The library is published under the same licence of aREST.
int temperature;
rest.variable("variable name", &temperature);
rest.set_name("Weather Station");
rest.set_id("841239");
The ID should be 6 characters long (will be automatically generated if not set)
rest.handle(client);
After uploading the sketch using the Arduino IDE, get the IP address from the serial monitor, enter it in your browser, and you should receive something like this:
{"variables": {}, "id": "468792", "name": "Weather Station", "hardware": "esp8266", "connected": true}
It should return a JSON body with all the device data.
- Add Raspberry Pi control support
- Add SSL Certificate on Node.js server
- Enable TLS on MongoDB server
- Add MongoDB database
- Add JWT authentication for client and server HTTP requests
- Add dynamic dashboard
SmartHaus is licensesd under the GPL-3.0 license.