Skip to content

Commit

Permalink
Merge pull request #16 from CDRV/dev
Browse files Browse the repository at this point in the history
Main merge for 1.2.0 release
  • Loading branch information
SBriere authored Apr 18, 2024
2 parents 505246b + d759b53 commit bd70504
Show file tree
Hide file tree
Showing 14 changed files with 876 additions and 411 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.idea
/.gitignore
venv
logs
Test
data
/__pycache__/*.pyc
*.pyc
/config/PiHub.json
/config/secure_opentera
8 changes: 1 addition & 7 deletions Globals.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
##################################################
# PiHub global variables
##################################################
# Author: Simon Brière, Eng. MASc.
##################################################

from libs.config.ConfigManager import ConfigManager

config_man = ConfigManager()

version_string = '1.1.0'
version_string = '1.2.0'
58 changes: 33 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Multi-network (cellular, wi-fi & ethernet) sensor and data hub with local re
This project was designed to run on a Raspberry Pi board with a cellular hat (Waveshare SIM7600CE 4G HAT - https://www.waveshare.com/product/raspberry-pi/hats/iot/sim7600ce-4g-hat.htm).

Main features of the project includes:
* Local wifi hub on which devices can connect and provides direct internet access
* Local Wi-Fi hub on which devices can connect and provides direct internet access
* Over cellular network
* Over connected ethernet cable
* Data transfer hub:
Expand All @@ -15,28 +15,40 @@ Main features of the project includes:
* OpenTera (https://github.com/introlab/opentera) server

## Requirements
Tested on Python 3.10
* Miniconda

## Pi setup
### Miniconda installation

1. Open a terminal
2. `wget http://repo.continuum.io/miniconda/Miniconda3-py39_4.9.2-Linux-aarch64.sh -O ~/miniconda3/miniconda.sh`
3. `conda init bash`
4. Close the terminal and start it again (or reload bash)

This suppose that a working git environment is setup, and that a Personal Access Token (PAT) was generated to use as password.
Initialize credential manager (to remember PAT) `git config --global credential.helper store`
## Pi setup

1. Clone the repository directly into `/home/pi/Desktop` folder (a PiHub folder will be created): `git clone https://github.com/CDRV/PiHub.git`
### Installation
1. Clone the repository directly into `/home/pi/Desktop` folder (a PiHub folder will be created - you can also choose any other place you want):
`git clone https://github.com/CDRV/PiHub.git`
2. Create Python virtual environment:
1. `cd /home/pi/Desktop/PiHub`
2. `python3 -m venv venv`
3. `source venv/bin/activate`
4. `pip install -r requirements.txt`
5. `deactivate`
* **If miniconda is installed, the script "create_conda_venv" can also be used**
4. Edit the config file `/home/pi/Desktop/PiHub/config/PiHub.json` with the appropriate values
5. Setup the cron tasks using `sudo crontab -e` and the crontab job listed in the `/home/pi/Desktop/PiHub/setup/crontab.txt` file
6. Setup and enable the main pihub service using<br>
`sudo cp /home/pi/Desktop/PiHub/setup/pihub.service /etc/systemd/system/pihub.service`<br>
`sudo systemctl enable pihub.service`
`sudo systemctl start pihub.service`
2. `chmod +x create_conda_venv.sh`
3. `./create_conda_venv.sh`
4. Make a copy of the default config file `cp /home/pi/Desktop/PiHub/config/PiHub_Defaults.json /home/pi/Desktop/PiHub/config/PiHub.json`
5. Edit the config file `/home/pi/Desktop/PiHub/config/PiHub.json` with the appropriate values
6. Setup the cron tasks using `sudo crontab -e` and the crontab job listed in the `/home/pi/Desktop/PiHub/setup/crontab.txt` file
7. Setup and enable the main pihub service using<br>
`sudo cp /home/pi/Desktop/PiHub/setup/pihub.service /etc/systemd/system/pihub.service`<br>
`sudo systemctl enable pihub.service`
`sudo systemctl start pihub.service`

### OpenTera configuration
Edit the `PiHub.json` configuration file:
* `WatchServer`
* `"transfer_type": "opentera"`
* `OpenTera`
* `"device_register_key": "(insert key)"` -> Device register key can be obtained by logging in on the target server and going in the "About" screen. Only super admins can see that key.
* `"default_session_type_id": (id)` -> Session type ID to use to create session.

### Service usage
To check if the service is running: `systemctl status pihub.service`
To query service output (log): `journalctl -u pihub.service`
Expand All @@ -46,12 +58,8 @@ If not developping directly on a Raspberry Pi, a virtual Python environment (ven

1. Install Python (see requirement version above)
2. Create a virtual environment:
1. Open a command line interface
2. Go to the PiHub folder
3. Create the virtual environment: `python -m venv venv`
4. Enable the virtual environment: <br>
On Mac/Linux: `source venv/bin/activate`<br>
On Windows: `venv\Scripts\activate.bat`<br>
**If miniconda is installed, the script "create_conda_venv" can also be used**
5. Install requirements: `pip install -r requirements.txt`
1. Install and setup miniconda for your OS
2. Open a command line interface
3. Go to the PiHub folder
4. Create the virtual environment: `create_conda_venv`

17 changes: 9 additions & 8 deletions config/PiHub.json → config/PiHub_Defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"hostname": "0.0.0.0",
"port": 8118,
"data_path": "data/watch",
"sftp_transfer": true,
"opentera_transfer": false,
"transfer_type": "opentera",
"server_base_folder": "Watch",
"send_logs_only": false,
"minimal_dataset_duration": 10
Expand All @@ -30,13 +29,15 @@
"sensor_ID": "Sensor_0"
},
"SFTP": {
"hostname": "telesante.cdrv.ca",
"port": 40091,
"username": "sftp_dev",
"password": "LS9PwJx7$829so"
"hostname": "127.0.0.1",
"port": 22,
"username": "sftp",
"password": "sftp"
},
"OpenTera": {
"hostname": "localhost",
"port": 40075
"hostname": "127.0.0.1",
"port": 40075,
"device_register_key": "1234567890",
"default_session_type_id": 1
}
}
8 changes: 5 additions & 3 deletions libs/config/ConfigManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ def load_config(self, filename) -> bool:
if self.validate_config("SFTP", config_json['SFTP'], ['hostname', 'port', 'username', 'password']):
self.sftp_config = config_json["SFTP"]

if self.validate_config("OpenTera", config_json['OpenTera'], ['hostname', 'port']):
if self.validate_config("OpenTera", config_json['OpenTera'],
['hostname', 'port', 'device_register_key', 'default_session_type_id']):
self.opentera_config = config_json["OpenTera"]

if self.validate_config("WatchServer", config_json['WatchServer'], ['hostname', 'port', 'data_path',
'sftp_transfer', 'opentera_transfer',
'server_base_folder', 'send_logs_only']):
'transfer_type', 'server_base_folder',
'send_logs_only', 'minimal_dataset_duration'
]):
self.watch_server_config = config_json["WatchServer"]

if self.validate_config("BedServer", config_json['BedServer'], ['hostname', 'port', 'data_path',
Expand Down
Loading

0 comments on commit bd70504

Please sign in to comment.