Skip to content

Commit

Permalink
Refs #14. Fixed sync files error when "ToProcess" folder doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Apr 16, 2024
1 parent e6c67f9 commit ff7e053
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
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`

5 changes: 3 additions & 2 deletions libs/servers/WatchServerOpenTera.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ def sync_files(self):
logging.info("WatchServerOpenTera: Checking if any pending transfers...")
# Get base folder path
base_folder = os.path.join(self.data_path, 'ToProcess')
for device_name in os.listdir(base_folder):
self.initiate_opentera_transfer(device_name)
if os.path.isdir(base_folder):
for device_name in os.listdir(base_folder):
self.initiate_opentera_transfer(device_name)

logging.info("All done!")

Expand Down

0 comments on commit ff7e053

Please sign in to comment.