Coder Social home page Coder Social logo

mplee / smarthaus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cath90mph/smarthaus

0.0 2.0 0.0 117 KB

🏠 A RESTful home automation system for monitoring and controlling IoT devices.

Home Page: https://smarthaus.herokuapp.com/

License: GNU General Public License v3.0

JavaScript 12.01% TypeScript 20.49% C++ 47.89% HTML 10.77% CSS 8.84%

smarthaus's Introduction

🏠 Smart Haus

Build Status GPLv3 license

Smart Haus 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.

Superpowers:

  1. ⚑ Robust: Full JavaScript stack with Angular and Node.js
  2. πŸ‘Œ Convenient: Operates from your local network where your IoT devices live
  3. πŸ” Secure: It's centralized in your network and does not require an external "cloud" server
  4. πŸ‘ Simple: No need for external MQTT broker configurations. It's fully RESTful!

Setup

  • 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.

πŸ“„ Client API:

The API is similar to the official Arduino with Analog & Digital I/O functions except for the callFunction() and the getVariable() functions.

pinMode()

pinMode(id, pin, mode)  

Configures the specified pin to behave either as an input or an output

Parameters:

id: device ID.
pin: the pin number.
mode: 'i' for INPUT, 'o' for OUTPUT and 'I' for INPUT_PULLUP.

Example:

// Sets pin 6 mode to OUTPUT.  
pinMode('468792', 6, 'o')  

⚠️ https://www.baldengineer.com/when-to-use-arduinos-pinmode-and-why.html


digitalWrite()

digitalWrite(id, pin, value)  

Writes a HIGH or a LOW value to a digital pin

Parameters:

id: device ID.
pin: the pin number to write to.
value: 1 for 'HIGH' and 0 for 'LOW'.

Example:

// Sets pin 5 state to HIGH.  
digitalWrite('468792', 5, 1)  

digitalRead()

digitalRead(id, pin)  

Reads the state value from a specified digital pin

Parameters:

id: device ID.
pin: the pin number to read from.

Example:

// Reads pin 4 state value and prints it to the console  
digitalRead('468792', 4)  
    .subscribe((data) => {  
        console.log(data);  
    });  

analogWrite()

analogWrite(id, pin, value)  

Writes an analog value (PWM wave) to a pin

Parameters:

id: device ID.
pin: the pin to write to.
value: the duty cycle: between 0 (always off) and 255 (always on).

Example:

// Writes an analog value to pin 3  
analogWrite('468792', 3)  

analogRead()

analogRead(id, pin)  

Reads the value from the specified analog pin

Parameters:

id: device ID.
pin: the pin to read from.

Example:

// Reads the voltage from pin 2 and prints it to the console  
analogRead('468792', 2)  
    .subscribe((data) => {  
        console.log(data);  
    });  

getVariable()

getVariable(id, variable)  

Reads a variable from the device. This is useful for reading sensor data

Parameters:

id: device ID.
variable: variable name to read from.

Example:

// Gets the value of variable 'temperatre' and prints it to the console  
getVariable('468792', 'temperature')  
    .subscribe((data) => {  
        console.log(data);  
    });  

callFunction()

callFunction(id, called_function, parameters)  

Executes a pre-defined function on the device

Parameters:

id: device ID.
called_function: function name to call
parameters: parameters to pass to the function

Example:

// Calls the function 'turn_on_led' and passes the value 1  
callFunction('468792', 'turn_on_led', '1')  

πŸ“„ Embedded API:

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.

Initializes a variable and exposes it to RESTful API
int temperature;  
rest.variable("variable name", &temperature);  
Sets a name for the device
rest.set_name("Weather Station");  
Sets an ID for the device
rest.set_name("Weather Station");  

The ID should be 6 characters long (will be automatically generated if not set)

Handle the client in the loop() function.
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.


πŸ“‘To-Do List

  • Add Raspberry Pi control support
  • Add SSL on Node.js server
  • Add CI/CD deployment to the Raspberry Pi from a remote repository
  • Add dynamic dashboard

smarthaus's People

Contributors

amir0ff avatar

Watchers

James Cloos avatar Lee Mun Poh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.