th0mcumm1ngs / ARWIN

Home Page:https://thomcummings.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HomeSystem

CodeQL

This repository includes the code for the RPi Server that holds all of the HomeSystem data.

How It Works

In a nutshell, the system works by sending requests as JSON data across the DataInterchange folder.

Example Scenario 1 - Telegram Bot for user interaction

A user sends a command to the Telegram Bot. The bot then recognises the command, initiates the send_request() function and passes the parameters command and chatID. This function then adds one to the reqID_counter system-wide variable — This is used to ensure that every request ID is unique. Then, a dictionary is created with the request ID, command type and chatID from earlier. After that, the dictionary is turned into JSON1 and packaged into a .json file. This is then sent to the DataInterchange folder. The main.py file constantly looks through the DataInterchange and parses the JSON data in the files. It then acts upon the command specified in the request and sends the output to the chatID obtained earlier.

Example Scenario 2 - Flask Request Receiver for computer generated requests

The reciever.py file contains a Flask Server. This can recieve JSON data from other systems and devices - i.e. a Smart Screen, Smart Camera, Siri Shortcuts, etc. It then packages this JSON data and sends it to the DataInterchange in the same way as in Scenario 1.

This has multiple applications including:

  • Using the Server as a private cloud to store data from other devices.
  • Handling requests from non-users2

How To Install

This project was designed to be run on a Raspberry Pi. It may work on other systems but there is no guarantee.

There are 2 ways to go about this:

  1. Install directly to your Raspberry Pi.

  2. Download to an external computer and send the files over to the Raspberry Pi.

I prefer Option 2 as I've found Raspberry Pi's can be hard to work with.

Option 1

  1. Open Chromium on your Raspberry Pi and navigate to the GitHub Repository.

  2. Under the Releases menu on the right-hand side, click on the latest release. 3

  3. Scroll to the assets section and download either Source Code.zip or Source Code.tar.gz.

  4. Unzip the file and move the HomeSystem folder to your Home Directory. 4

  5. Open a new terminal and install all dependencies with the command:

     pip3 install -r requirements.txt
    
  6. Open 4 terminals all in the HomeSystem Directory. In terminal 1 type python3 main.py, in terminal 2 type python3 HS_Bot.py, in terminal 3 type python3 receiver.py and in terminal 4 type ./ngrok http 5000.

Option 2

  1. On your external computer, open the GitHub Repository in your browser.

  2. Under the Releases menu on the right-hand side, click on the latest release. 3

  3. Scroll to the assets section and download either Source Code.zip or Source Code.tar.gz.

  4. Unzip the file and put it anywhere. Leave it in the downloads folder if it is there automatically.

  5. Install Croc on both your external computer and your Raspberry Pi:

    1. Open a new terminal.
    2. Type curl https://getcroc.schollz.com | bash
  6. On your external computer, open a new terminal in the parent to the HomeSystem Directory and type:

     croc send HomeSystem-X.X.X
    

    You will be given a code phrase. Note it down.

  7. On your Raspberry Pi, open a new terminal in your Home Directory4 and type:

     croc [Your code phrase]
    
  8. Still on your Raspberry Pi, open a new terminal in the HomeSystem-X.X.X Directory and install all dependencies with the command:

     pip3 install -r requirements.txt
    

    DO NOT close this terminal

  9. Go to the ngrok website and create an account. Copy your auth token. On your external computer open a new terminal and type:

     croc send --text [YOUR AUTH TOKEN]
    
  10. In the terminal from Step 9 on the Raspberry Pi type:

    croc [Your code phrase]
    

    Your auth token should appear. Copy it

  11. In the same terminal type:

    chmod +x ngrok
    

    then

    ./ngrok authtoken [YOUR AUTH TOKEN]
    
  12. Open 4 terminals all in the HomeSystem-X.X.X Directory. In terminal 1 type python3 main.py, in terminal 2 type python3 HS_Bot.py, in terminal 3 type python3 receiver.py and in terminal 4 type ./ngrok http 5000.

Footnotes

1 An exapmle of this:

data = {
    "reqID":reqID,
    "command":command,
    "chatID":chatID
}

2 Examples of this could be:

  • A Motion Sensor has detected motion and wants to alert the system.
  • A smart screen wishes to retrieve information from the FileSystem.

3 Ensure to use the latest release and not just clone the repository. This is crucial since the repository may be unstable.

4 Usually called Pi unless you have changed it.

About

https://thomcummings.dev


Languages

Language:Python 89.8%Language:HTML 10.2%