Code Monkey home page Code Monkey logo

piswitch's Introduction

PiSwitch

Simple web-based remote control for custom actions, like switching on or off radio controlled sockets or external APIs.

Preview

Requirements

Preparing

Clone this repository on your Pi:

git clone https://github.com/DerAtrox/PiSwitch.git

Make run.sh executable:

chmod +x ./run.sh

Configuring

Application configuration

The application configuration file is used for interal configuration.

Copy /config/default-config.js to /config/config.js.

Properties

Property Default Description
port 3010 Port used by the web server
get false Enables or disables the API GET endpoints
gpio.transmitter 2 GPIO pin used for 433MHz transmitter
gpio.receiver 3 GPIO pin used for 433MHz receiver (unused)

Controls configuration

In the controls configuration file, you specify which controls with which buttons and actions should be displayed.

Create a new file in the /public/ named controls.js or move the existing examples file (/public/controls-example.js) to /public/controls.js.

Definition

In the context of this application a control is a set of buttons, which each can perform different actions, together with a title and some other information. In the preview above, we have three different controls. One named "Speaker", one named "Lights" and so on. Each of the buttons of each control can be configured to perform different actions. One control combines multiple buttons to one "object". For example a radio controlled outlet would be one control with two buttons: "Turn on" and "Turn off".

For better understanding of this configuration, I also added a graphic describing, what is what.

Properties

Property Optional Description
controls[] no Array containing all different controls to display
controls[].title no Title of the control
controls[].sub yes Subtitle of the control
controls[].description yes Description of the control
controls[].icon yes Font Awesome 5 icon of the control. Example: fas fa-lightbulb
controls[].buttons[] yes Array containing all buttons of the control. Each control should have at least one button
controls[].buttons[].lable yes Label (text) of the button
controls[].buttons[].bt-icon yes Icon of the button (see controls.icon)
controls[].buttons[].actions[] yes Array containing all actions the button should perform on click
controls[].buttons[].actions[].action no Name of the action to perform
controls[].buttons[].actions[].data no Data to pass to the action

Running and updating

Run run.sh to compile all the binaries and to start and daemonize PiSwitch with PM2.

./run.sh

After that you can use PM2 to start, stop, restart or monitor PiFrame.

Now you can just open your browser and navigate to your Pi with the port you chose, for example http://raspberry:3010/.

To update PiSwitch, just run the start script (run.sh) again.

Note: Running the start script will reset everything in the directory, except Node.js modules, configurations in /config/, custom sources in /src/custom/ and custom actions in /actions/ to the last commit in this repository#master.

Actions

Actions are scripts which are executed when a button is pressed. By default there are only two actions, though more actions are planned in the future.

  • rcswitch - sends a code via an 433 MHz transmitter
  • webrequest - sends a simple web request to for example another API

Adding your own Actions

Detailed documentation coming soon..

Libraries, Frameworks, Fonts and APIs

This project is made possible by these awesome libraries, frameworks, fonts and APIs, go check them out!

  • Node.js - Node.js JavaScript runtime
  • PM2 - Node.js Production Process Manager with a built-in Load
  • Express - Fast, unopinionated, minimalist web framework for node
  • Wiring Pi - PIN based GPIO access library for all versions of the Raspberry Pi
  • Bootstrap - The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web
  • jQuery - jQuery JavaScript Library
  • Font Awesome - The iconic SVG, font, and CSS toolkit
  • Google Fonts - Making the web more beautiful, fast, and open through great typography

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.