Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Install packages using a virtual environment (#88)
Browse files Browse the repository at this point in the history
* Added script for activating a virtual environment where available

* Updated Readme

* Added .venv to .gitignore

* Added "sudo" back to commands in Readme
  • Loading branch information
merll authored and zewelor committed Aug 14, 2019
1 parent d1aebad commit d722002
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
config.yaml
__pycache__/
.idea/
.venv
.vscode/
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ On a modern Linux system, just a few steps are needed to get the gateway working
The following example shows the installation under Debian/Raspbian:

```shell
sudo apt-get install git python3 python3-pip python3-wheel bluetooth bluez libglib2.0-dev
sudo apt-get install git python3 python3-virtualenv python3-pip python3-wheel bluetooth bluez libglib2.0-dev
git clone https://github.com/zewelor/bt-mqtt-gateway.git
cd bt-mqtt-gateway
sudo pip3 install -r requirements.txt
virtualenv -p python3 .venv
source .venv/bin/activate
pip3 install -r requirements.txt
```

## Configuration
Expand All @@ -55,7 +57,8 @@ This file needs to be created first:
```shell
cp config.yaml.example config.yaml
vim config.yaml
./gateway.py
source .venv/bin/activate
sudo ./gateway.py
```

**Attention:**
Expand All @@ -71,6 +74,7 @@ sudo hcitool lescan
A test run is as easy as:

```shell
source .venv/bin/activate
sudo ./gateway.py
```

Expand All @@ -94,7 +98,7 @@ sudo systemctl enable bt-mqtt-gateway
```

**Attention:**
You need to define the absolute path of `gateway.py` in `bt-mqtt-gateway.service`.
You need to define the absolute path of `service.sh` in `bt-mqtt-gateway.service`.

**Testing mqtt:**
Use mosquitto_sub to print all messages
Expand Down
2 changes: 1 addition & 1 deletion bt-mqtt-gateway.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ After=network.target
[Service]
Type=simple
WorkingDirectory=/home/user/bt-mqtt-gateway
ExecStart=/home/user/bt-mqtt-gateway/gateway.py
ExecStart=/home/user/bt-mqtt-gateway/service.sh
Restart=always

[Install]
Expand Down
11 changes: 11 additions & 0 deletions service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
set -e
SCRIPT_DIR=$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )
VIRTUAL_ENV=$SCRIPT_DIR/.venv
if [ -d "$VIRTUAL_ENV" ]; then
export VIRTUAL_ENV
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH
fi
cd "$SCRIPT_DIR"
python3 ./gateway.py "$@"

0 comments on commit d722002

Please sign in to comment.