149 lines
2.5 KiB
Markdown
149 lines
2.5 KiB
Markdown
# PiSwitch
|
|
|
|
A Raspberry Pi Relay controller based on the Astral Library
|
|
|
|
## Physical setup
|
|
|
|
Use physical pin numbering
|
|
|
|
![Pi pinout](https://www.jameco.com/Jameco/workshop/circuitnotes/raspberry_pi_circuit_note_fig2.jpg)
|
|
|
|
### Switch Toggle Button:
|
|
|
|
3.3v: either pin 1 or pin 17
|
|
|
|
signal: pin 11
|
|
|
|
### Astral Toggle Button / Switch:
|
|
|
|
3.3v: either pin 1 or pin 17
|
|
|
|
signal: pin 15
|
|
|
|
### LED's
|
|
5v: eiter pin 2 or pin 4
|
|
|
|
signal: pin 12
|
|
|
|
ground : any ground pin
|
|
|
|
### Relay
|
|
|
|
5v: eiter pin 2 or pin 4
|
|
|
|
signal: pin 38
|
|
|
|
ground : any ground pin
|
|
|
|
## Installation Process
|
|
|
|
Clone the repository
|
|
````shell
|
|
git clone https://git.dennisvandermeulen.nl/dennis/PiSwitch.git
|
|
cd PiSwitch/
|
|
````
|
|
Setup virtual environment & install requirements (skip if you use Docker)
|
|
````shell
|
|
python3 -m venv venv
|
|
source venv/bin/activate
|
|
pip3 install -r requirements.txt
|
|
````
|
|
|
|
Setup config.ini
|
|
````shell
|
|
nano src/config.ini
|
|
````
|
|
## Config.ini
|
|
Set up the base url for your api
|
|
````ini
|
|
[setup]
|
|
baseurl = http(s)://www.example.com:port/
|
|
````
|
|
setup switch id
|
|
````ini
|
|
switchid = integer
|
|
````
|
|
Setup whether information must be pushed to the database
|
|
````ini
|
|
storedb = 0/1
|
|
````
|
|
|
|
Set the apikey for this PiSwitch
|
|
````ini
|
|
apikey = string
|
|
````
|
|
Set the key of the [PiSwitch reporting server](https://git.dennisvandermeulen.nl/dennis/PiSwitch_reporting) (Do not use if storedb=0)
|
|
````ini
|
|
srvapikey = string
|
|
````
|
|
|
|
Setup your location info
|
|
````ini
|
|
[location]
|
|
name = name
|
|
region = region
|
|
lat = float
|
|
lon = float
|
|
timezone = Europe/Amsterdam
|
|
````
|
|
|
|
##Docker
|
|
Use the included Docker-Compose files to build the scheduler and server container
|
|
````shell
|
|
docker-compose . -up -d
|
|
````
|
|
|
|
|
|
## Systemd
|
|
Use the following scripts to automatically start the scripts at boot for a true headless experience
|
|
|
|
### server.py
|
|
````ini
|
|
[Unit]
|
|
Description=Relay Switch Server
|
|
After=multi-user.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=root
|
|
Group=root
|
|
WorkingDirectory=/path/to/PiSwitch/src
|
|
ExecStart=/path/to/venv/bin/python3 path/to/PiSwitch/src/server.py
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
````
|
|
save as relayserver.service
|
|
|
|
### scheduler.py
|
|
````ini
|
|
[Unit]
|
|
Description=Relay Switch listener
|
|
After=multi-user.target
|
|
Requires=relayserver.service
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=root
|
|
Group=root
|
|
WorkingDirectory=/path/to/PiSwitch/src
|
|
ExecStart=/path/to/venv/bin/python3 path/to/PiSwitch/src/scheduler.py
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
````
|
|
save as scheduler.service
|
|
|
|
## Troubleshooting
|
|
Check LED color for basic status indications
|
|
|
|
White Solid = No Wi-Fi
|
|
|
|
Red Solid = Lights off
|
|
|
|
Green Solid = Lights on
|
|
|
|
Blue Flashing = Astral enabled
|
|
|
|
Off = No power / Led dead :)
|